gitbolt 0.0.0.dev12__tar.gz → 0.0.0.dev14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/PKG-INFO +2 -2
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/pyproject.toml +2 -2
- gitbolt-0.0.0.dev14/src/gitbolt/__init__.py +96 -0
- gitbolt-0.0.0.dev14/src/gitbolt/subprocess/__init__.py +15 -0
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/add.py +1 -1
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/base.py +19 -12
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/exceptions.py +5 -5
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/impl/simple.py +15 -14
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/ls_tree.py +1 -1
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/runner/__init__.py +1 -1
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/runner/base.py +9 -0
- gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess/runner/simple_impl.py → gitbolt-0.0.0.dev14/src/gitbolt/subprocess/runner/simple.py +16 -4
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt.egg-info/PKG-INFO +2 -2
- gitbolt-0.0.0.dev14/src/gitbolt.egg-info/SOURCES.txt +33 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt.egg-info/requires.txt +1 -1
- gitbolt-0.0.0.dev12/src/gitbolt/__init__.py +0 -44
- gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess/__init__.py +0 -15
- gitbolt-0.0.0.dev12/src/gitbolt.egg-info/SOURCES.txt +0 -33
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/LICENSE +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/README.md +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/setup.cfg +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/_internal_init.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/add.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/base.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/constants.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/exceptions.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/ls_tree.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/models.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/py.typed +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/pytest_plugin.py +0 -0
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/_internal_init.py +0 -0
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/constants.py +0 -0
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/impl/__init__.py +0 -0
- {gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/utils.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt/utils.py +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt.egg-info/dependency_links.txt +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt.egg-info/entry_points.txt +0 -0
- {gitbolt-0.0.0.dev12 → gitbolt-0.0.0.dev14}/src/gitbolt.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitbolt
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev14
|
|
4
4
|
Summary: Fast, flexible and type-safe Git commands in Python.
|
|
5
5
|
Author-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
6
6
|
Maintainer-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
@@ -26,7 +26,7 @@ Classifier: Typing :: Typed
|
|
|
26
26
|
Requires-Python: >=3.12
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
28
28
|
License-File: LICENSE
|
|
29
|
-
Requires-Dist: vt-err-hndlr>=0.0.
|
|
29
|
+
Requires-Dist: vt-err-hndlr>=0.0.0dev6
|
|
30
30
|
Requires-Dist: vt-commons>=0.0.1.dev9
|
|
31
31
|
Provides-Extra: pygit2
|
|
32
32
|
Requires-Dist: pygit2; extra == "pygit2"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "gitbolt"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.0dev14"
|
|
4
4
|
description = "Fast, flexible and type-safe Git commands in Python."
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
readme = "README.md"
|
|
@@ -36,7 +36,7 @@ classifiers = [
|
|
|
36
36
|
"Typing :: Typed"
|
|
37
37
|
]
|
|
38
38
|
dependencies = [
|
|
39
|
-
"vt-err-hndlr >= 0.0.
|
|
39
|
+
"vt-err-hndlr >= 0.0.0dev6",
|
|
40
40
|
"vt-commons >= 0.0.1.dev9",
|
|
41
41
|
]
|
|
42
42
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Git command interfaces with default implementation using subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
# region imports
|
|
11
|
+
# region base related imports
|
|
12
|
+
from gitbolt.base import Git as Git
|
|
13
|
+
from gitbolt.base import CanOverrideGitOpts as CanOverrideGitOpts
|
|
14
|
+
from gitbolt.base import HasGitUnderneath as HasGitUnderneath
|
|
15
|
+
from gitbolt.base import GitSubCommand as GitSubCommand
|
|
16
|
+
from gitbolt.base import LsTree as LsTree
|
|
17
|
+
from gitbolt.base import Version as Version
|
|
18
|
+
from gitbolt.base import Add as Add
|
|
19
|
+
from gitbolt.subprocess.base import GitCommand
|
|
20
|
+
# endregion
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from gitbolt.constants import GIT_DIR as GIT_DIR
|
|
24
|
+
from gitbolt.subprocess.constants import GIT_CMD
|
|
25
|
+
from gitbolt.subprocess.impl.simple import SimpleGitCommand as _SimpleGitCommand
|
|
26
|
+
from gitbolt.subprocess.impl.simple import CLISimpleGitCommand as _CLISimpleGitCommand
|
|
27
|
+
from gitbolt.subprocess.runner.simple import SimpleGitCR as _SimpleGitCR
|
|
28
|
+
# endregion
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_git(git_root_dir: Path = Path.cwd()) -> Git:
|
|
32
|
+
"""
|
|
33
|
+
Get operational and programmatic ``Git``.
|
|
34
|
+
|
|
35
|
+
Examples:
|
|
36
|
+
|
|
37
|
+
* Get git version:
|
|
38
|
+
|
|
39
|
+
>>> import subprocess
|
|
40
|
+
>>> import gitbolt
|
|
41
|
+
>>> git = gitbolt.get_git()
|
|
42
|
+
>>> assert git.version().version() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
|
|
43
|
+
|
|
44
|
+
:param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
|
|
45
|
+
:returns: The ``Git`` instance with all subcommands.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
return _SimpleGitCommand(git_root_dir)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_git_command(
|
|
52
|
+
git_root_dir: Path = Path.cwd(),
|
|
53
|
+
*,
|
|
54
|
+
git_prog: str | Path = GIT_CMD,
|
|
55
|
+
main_cmd_opts: list[str] | None = None,
|
|
56
|
+
main_cmd_envs: dict[str, str] | None = None,
|
|
57
|
+
prefer_cli: bool = False,
|
|
58
|
+
) -> GitCommand:
|
|
59
|
+
"""
|
|
60
|
+
Get operational and programmatic ``Git`` which runs as a subprocess.
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
|
|
64
|
+
* Get git version, as base git:
|
|
65
|
+
|
|
66
|
+
>>> import subprocess
|
|
67
|
+
>>> import gitbolt
|
|
68
|
+
>>> git = gitbolt.get_git_command()
|
|
69
|
+
>>> assert git.version().version() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
|
|
70
|
+
|
|
71
|
+
* Get git version, as a git subcommand. Runs git in subprocess:
|
|
72
|
+
|
|
73
|
+
>>> assert git.subcmd_unchecked.run(["version"], text=True).stdout.strip() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
|
|
74
|
+
|
|
75
|
+
:param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
|
|
76
|
+
:param git_prog: git program name/location. Useful when user wants to run a separate git version/git emulator.
|
|
77
|
+
:param opts: main git cli options. The main git command options like ``--no-replace-objects``, ``--no-pager``, ``-C`` etc are git main command args.
|
|
78
|
+
:param envs: main git cli env vars. Not supplying any env vars (default behavior: ``None``) simply supplies all
|
|
79
|
+
the env vars to the underlying runner.
|
|
80
|
+
:param prefer_cli: cli opts and envs will be given priority over programmatically set opts and envs. Setting
|
|
81
|
+
this param to ``True`` will make cli opts and envs appear later in the opts and envs strings which will
|
|
82
|
+
make them override previously programmatically set opts and envs.
|
|
83
|
+
:returns: ``GitCommand`` instance with all the subcommands as well as ``unchecked_subcmd``. Runs git commands in a
|
|
84
|
+
separate runner in subprocess.
|
|
85
|
+
"""
|
|
86
|
+
runner = _SimpleGitCR(git_prog)
|
|
87
|
+
if main_cmd_opts is None:
|
|
88
|
+
return _SimpleGitCommand(git_root_dir, runner)
|
|
89
|
+
else:
|
|
90
|
+
return _CLISimpleGitCommand(
|
|
91
|
+
git_root_dir,
|
|
92
|
+
runner,
|
|
93
|
+
opts=main_cmd_opts,
|
|
94
|
+
envs=main_cmd_envs,
|
|
95
|
+
prefer_cli=prefer_cli,
|
|
96
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Git command interfaces with implementation using subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# region gitbolt.subprocess.base
|
|
9
|
+
from gitbolt.subprocess.base import GitCommand as GitCommand
|
|
10
|
+
from gitbolt.subprocess.base import GitSubcmdCommand as GitSubcmdCommand
|
|
11
|
+
from gitbolt.subprocess.base import AddCommand as AddCommand
|
|
12
|
+
from gitbolt.subprocess.base import LsTreeCommand as LsTreeCommand
|
|
13
|
+
from gitbolt.subprocess.base import VersionCommand as VersionCommand
|
|
14
|
+
from gitbolt.subprocess.base import UncheckedSubcmd as UncheckedSubcmd
|
|
15
|
+
# endregion
|
{gitbolt-0.0.0.dev12/src/gitbolt/git_subprocess → gitbolt-0.0.0.dev14/src/gitbolt/subprocess}/add.py
RENAMED
|
@@ -9,7 +9,7 @@ from abc import abstractmethod
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import Protocol, Unpack, override, Literal
|
|
11
11
|
|
|
12
|
-
from gitbolt.
|
|
12
|
+
from gitbolt.subprocess.constants import ADD_CMD
|
|
13
13
|
from gitbolt.models import GitAddOpts
|
|
14
14
|
|
|
15
15
|
|
|
@@ -19,12 +19,12 @@ from vt.utils.errors.error_specs import ERR_INVALID_USAGE
|
|
|
19
19
|
|
|
20
20
|
from gitbolt import Git, Version, LsTree, GitSubCommand, HasGitUnderneath, Add
|
|
21
21
|
from gitbolt.exceptions import GitExitingException
|
|
22
|
-
from gitbolt.
|
|
23
|
-
from gitbolt.
|
|
22
|
+
from gitbolt.subprocess.add import AddCLIArgsBuilder, IndividuallyOverridableACAB
|
|
23
|
+
from gitbolt.subprocess.ls_tree import (
|
|
24
24
|
LsTreeCLIArgsBuilder,
|
|
25
25
|
IndividuallyOverridableLTCAB,
|
|
26
26
|
)
|
|
27
|
-
from gitbolt.
|
|
27
|
+
from gitbolt.subprocess.runner import GitCommandRunner
|
|
28
28
|
from gitbolt.models import GitOpts, GitLsTreeOpts, GitAddOpts, GitEnvVars
|
|
29
29
|
from gitbolt.utils import merge_git_opts, merge_git_envs
|
|
30
30
|
|
|
@@ -40,7 +40,7 @@ class GitCommand(Git, ABC):
|
|
|
40
40
|
"""
|
|
41
41
|
self.runner: GitCommandRunner = runner
|
|
42
42
|
self._main_cmd_opts: GitOpts = {}
|
|
43
|
-
self._env_vars: GitEnvVars =
|
|
43
|
+
self._env_vars: GitEnvVars | None = None
|
|
44
44
|
|
|
45
45
|
# region build_main_cmd_args
|
|
46
46
|
def build_main_cmd_args(self) -> list[str]:
|
|
@@ -216,7 +216,7 @@ class GitCommand(Git, ABC):
|
|
|
216
216
|
# endregion
|
|
217
217
|
|
|
218
218
|
# region build_git_envs
|
|
219
|
-
def build_git_envs(self) -> dict[str, str]:
|
|
219
|
+
def build_git_envs(self) -> dict[str, str] | None:
|
|
220
220
|
"""
|
|
221
221
|
Terminal operation to build and return effective Git environment variables
|
|
222
222
|
from the merged ``GitEnvVars`` object.
|
|
@@ -226,16 +226,22 @@ class GitCommand(Git, ABC):
|
|
|
226
226
|
|
|
227
227
|
:return: A cleaned and normalized GitEnvVars dict suitable for use in subprocesses.
|
|
228
228
|
"""
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
if self._env_vars is None:
|
|
230
|
+
return None
|
|
231
|
+
else:
|
|
232
|
+
env: dict[str, str] = {}
|
|
233
|
+
for key, val in self._env_vars.items():
|
|
234
|
+
if not_none_not_unset(val):
|
|
235
|
+
env[key] = str(val)
|
|
236
|
+
return env
|
|
234
237
|
|
|
235
238
|
@override
|
|
236
239
|
def git_envs_override(self, **overrides: Unpack[GitEnvVars]) -> Self:
|
|
237
240
|
_git_cmd = self.clone()
|
|
238
|
-
|
|
241
|
+
if self._env_vars:
|
|
242
|
+
_env_vars = merge_git_envs(overrides, self._env_vars)
|
|
243
|
+
else:
|
|
244
|
+
_env_vars = overrides
|
|
239
245
|
_git_cmd._env_vars = _env_vars
|
|
240
246
|
return _git_cmd
|
|
241
247
|
|
|
@@ -582,7 +588,8 @@ class UncheckedSubcmd(GitSubcmdCommand, RootDirOp, Protocol):
|
|
|
582
588
|
envs_vars = self.underlying_git.build_git_envs()
|
|
583
589
|
another_supplied_env = subprocess_run_kwargs.pop("env", None)
|
|
584
590
|
if another_supplied_env:
|
|
585
|
-
envs_vars
|
|
591
|
+
if envs_vars is not None:
|
|
592
|
+
envs_vars.update(another_supplied_env)
|
|
586
593
|
cwd = subprocess_run_kwargs.pop("cwd", self.root_dir)
|
|
587
594
|
capture_output = subprocess_run_kwargs.pop("capture_output", True)
|
|
588
595
|
check = subprocess_run_kwargs.pop("check", True)
|
|
@@ -22,26 +22,26 @@ class GitCmdException(GitException, VTCmdException):
|
|
|
22
22
|
|
|
23
23
|
>>> raise GitCmdException(called_process_error=CalledProcessError(1, ['git', 'status'])) # always use `from` clause.
|
|
24
24
|
Traceback (most recent call last):
|
|
25
|
-
gitbolt.
|
|
25
|
+
gitbolt.subprocess.exceptions.GitCmdException: CalledProcessError: Command '['git', 'status']' returned non-zero exit status 1.
|
|
26
26
|
|
|
27
27
|
* raise with a message:
|
|
28
28
|
|
|
29
29
|
>>> raise GitCmdException('Git failed', called_process_error=CalledProcessError(1, ['git', 'push'])) # always use `from` clause.
|
|
30
30
|
Traceback (most recent call last):
|
|
31
|
-
gitbolt.
|
|
31
|
+
gitbolt.subprocess.exceptions.GitCmdException: CalledProcessError: Git failed
|
|
32
32
|
|
|
33
33
|
* raise with overridden exit code:
|
|
34
34
|
|
|
35
35
|
>>> raise GitCmdException('Git push failed', called_process_error=CalledProcessError(1, ['git', 'push']), exit_code=42) # always use `from` clause.
|
|
36
36
|
Traceback (most recent call last):
|
|
37
|
-
gitbolt.
|
|
37
|
+
gitbolt.subprocess.exceptions.GitCmdException: CalledProcessError: Git push failed
|
|
38
38
|
|
|
39
39
|
* raise without message, override with stderr inside CalledProcessError:
|
|
40
40
|
|
|
41
41
|
>>> err = CalledProcessError(128, ['git', 'fetch'], stderr='fatal: not a git repository')
|
|
42
42
|
>>> raise GitCmdException(called_process_error=err) # always use `from` clause.
|
|
43
43
|
Traceback (most recent call last):
|
|
44
|
-
gitbolt.
|
|
44
|
+
gitbolt.subprocess.exceptions.GitCmdException: CalledProcessError: Command '['git', 'fetch']' returned non-zero exit status 128.
|
|
45
45
|
|
|
46
46
|
* raise exception using `from` clause (chaining):
|
|
47
47
|
|
|
@@ -50,7 +50,7 @@ class GitCmdException(GitException, VTCmdException):
|
|
|
50
50
|
... except CalledProcessError as e:
|
|
51
51
|
... raise GitCmdException('Clone failed', called_process_error=e) from e
|
|
52
52
|
Traceback (most recent call last):
|
|
53
|
-
gitbolt.
|
|
53
|
+
gitbolt.subprocess.exceptions.GitCmdException: CalledProcessError: Clone failed
|
|
54
54
|
|
|
55
55
|
* cause reflects original CalledProcessError when chained:
|
|
56
56
|
|
|
@@ -15,7 +15,7 @@ from vt.utils.commons.commons.op import RootDirOp
|
|
|
15
15
|
|
|
16
16
|
from gitbolt.base import Version
|
|
17
17
|
from gitbolt.add import AddArgsValidator
|
|
18
|
-
from gitbolt.
|
|
18
|
+
from gitbolt.subprocess import (
|
|
19
19
|
GitCommand,
|
|
20
20
|
VersionCommand,
|
|
21
21
|
LsTreeCommand,
|
|
@@ -23,11 +23,11 @@ from gitbolt.git_subprocess import (
|
|
|
23
23
|
AddCommand,
|
|
24
24
|
UncheckedSubcmd,
|
|
25
25
|
)
|
|
26
|
-
from gitbolt.
|
|
27
|
-
from gitbolt.
|
|
28
|
-
from gitbolt.
|
|
29
|
-
from gitbolt.
|
|
30
|
-
from gitbolt.
|
|
26
|
+
from gitbolt.subprocess.add import AddCLIArgsBuilder
|
|
27
|
+
from gitbolt.subprocess.constants import VERSION_CMD
|
|
28
|
+
from gitbolt.subprocess.ls_tree import LsTreeCLIArgsBuilder
|
|
29
|
+
from gitbolt.subprocess.runner import GitCommandRunner
|
|
30
|
+
from gitbolt.subprocess.runner.simple import SimpleGitCR
|
|
31
31
|
from gitbolt.ls_tree import LsTreeArgsValidator
|
|
32
32
|
|
|
33
33
|
|
|
@@ -266,7 +266,8 @@ class CLISimpleGitCommand(SimpleGitCommand):
|
|
|
266
266
|
):
|
|
267
267
|
"""
|
|
268
268
|
:param opts: main git cli options.
|
|
269
|
-
:param envs: main git cli env vars.
|
|
269
|
+
:param envs: main git cli env vars. Not supplying any env vars (default behavior: ``None``) simply supplies all
|
|
270
|
+
the env vars to the underlying runner.
|
|
270
271
|
:param prefer_cli: cli opts and envs will be given priority over programmatically set opts and envs. Setting
|
|
271
272
|
this param to ``True`` will make cli opts and envs appear later in the opts and envs strings which will
|
|
272
273
|
make them override previously programmatically set opts and envs.
|
|
@@ -293,13 +294,13 @@ class CLISimpleGitCommand(SimpleGitCommand):
|
|
|
293
294
|
return super().build_main_cmd_args()
|
|
294
295
|
|
|
295
296
|
@override
|
|
296
|
-
def build_git_envs(self) -> dict[str, str]:
|
|
297
|
-
if self._cmd_cli_envs:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
def build_git_envs(self) -> dict[str, str] | None:
|
|
298
|
+
if self._cmd_cli_envs is None:
|
|
299
|
+
return super().build_git_envs()
|
|
300
|
+
if self.prefer_cli:
|
|
301
|
+
return (super().build_git_envs() or {}) | self._cmd_cli_envs
|
|
302
|
+
else:
|
|
303
|
+
return self._cmd_cli_envs | (super().build_git_envs() or {})
|
|
303
304
|
|
|
304
305
|
@override
|
|
305
306
|
def _subclass_clone(self) -> CLISimpleGitCommand:
|
|
@@ -8,7 +8,7 @@ Helper interfaces for ``git ls-tree`` subcommand with default implementation for
|
|
|
8
8
|
from abc import abstractmethod
|
|
9
9
|
from typing import Protocol, Unpack, override
|
|
10
10
|
|
|
11
|
-
from gitbolt.
|
|
11
|
+
from gitbolt.subprocess.constants import LS_TREE_CMD
|
|
12
12
|
from gitbolt.models import GitLsTreeOpts
|
|
13
13
|
|
|
14
14
|
|
|
@@ -7,6 +7,7 @@ Git command runner interfaces to run subprocess calls.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import pathlib
|
|
10
11
|
from abc import abstractmethod
|
|
11
12
|
from subprocess import CompletedProcess
|
|
12
13
|
from typing import Protocol, overload, Any, Literal
|
|
@@ -62,3 +63,11 @@ class GitCommandRunner(Protocol):
|
|
|
62
63
|
text: Literal[False] = ...,
|
|
63
64
|
**subprocess_run_kwargs: Any,
|
|
64
65
|
) -> CompletedProcess[bytes]: ...
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def git_prog(self) -> str | pathlib.Path:
|
|
70
|
+
"""
|
|
71
|
+
:returns: git path location or git program name.
|
|
72
|
+
"""
|
|
73
|
+
...
|
|
@@ -7,13 +7,14 @@ A simple and straight-forward git command subprocess runner implementation.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import pathlib
|
|
10
11
|
import subprocess
|
|
11
12
|
from subprocess import CompletedProcess
|
|
12
13
|
from typing import overload, override, Any, Literal
|
|
13
14
|
|
|
14
|
-
from gitbolt.
|
|
15
|
-
from gitbolt.
|
|
16
|
-
from gitbolt.
|
|
15
|
+
from gitbolt.subprocess.constants import GIT_CMD
|
|
16
|
+
from gitbolt.subprocess.exceptions import GitCmdException
|
|
17
|
+
from gitbolt.subprocess.runner import GitCommandRunner
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class SimpleGitCR(GitCommandRunner):
|
|
@@ -21,6 +22,12 @@ class SimpleGitCR(GitCommandRunner):
|
|
|
21
22
|
Simple git command runner that simply runs everything `as-is` in a subprocess.
|
|
22
23
|
"""
|
|
23
24
|
|
|
25
|
+
def __init__(self, git_prog: str | pathlib.Path = GIT_CMD):
|
|
26
|
+
"""
|
|
27
|
+
:param git_prog: git program name/location. Useful when user wants to run a separate git version/git emulator.
|
|
28
|
+
"""
|
|
29
|
+
self._git_prog = git_prog
|
|
30
|
+
|
|
24
31
|
@overload
|
|
25
32
|
@override
|
|
26
33
|
def run_git_command(
|
|
@@ -79,7 +86,7 @@ class SimpleGitCR(GitCommandRunner):
|
|
|
79
86
|
) -> CompletedProcess[str] | CompletedProcess[bytes]:
|
|
80
87
|
try:
|
|
81
88
|
return subprocess.run(
|
|
82
|
-
[
|
|
89
|
+
[str(self.git_prog), *main_cmd_args, *subcommand_args],
|
|
83
90
|
*subprocess_run_args,
|
|
84
91
|
input=_input,
|
|
85
92
|
text=text,
|
|
@@ -89,3 +96,8 @@ class SimpleGitCR(GitCommandRunner):
|
|
|
89
96
|
raise GitCmdException(
|
|
90
97
|
e.stderr, called_process_error=e, exit_code=e.returncode
|
|
91
98
|
) from e
|
|
99
|
+
|
|
100
|
+
@override
|
|
101
|
+
@property
|
|
102
|
+
def git_prog(self) -> str | pathlib.Path:
|
|
103
|
+
return self._git_prog
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitbolt
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev14
|
|
4
4
|
Summary: Fast, flexible and type-safe Git commands in Python.
|
|
5
5
|
Author-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
6
6
|
Maintainer-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
@@ -26,7 +26,7 @@ Classifier: Typing :: Typed
|
|
|
26
26
|
Requires-Python: >=3.12
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
28
28
|
License-File: LICENSE
|
|
29
|
-
Requires-Dist: vt-err-hndlr>=0.0.
|
|
29
|
+
Requires-Dist: vt-err-hndlr>=0.0.0dev6
|
|
30
30
|
Requires-Dist: vt-commons>=0.0.1.dev9
|
|
31
31
|
Provides-Extra: pygit2
|
|
32
32
|
Requires-Dist: pygit2; extra == "pygit2"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/gitbolt/__init__.py
|
|
5
|
+
src/gitbolt/_internal_init.py
|
|
6
|
+
src/gitbolt/add.py
|
|
7
|
+
src/gitbolt/base.py
|
|
8
|
+
src/gitbolt/constants.py
|
|
9
|
+
src/gitbolt/exceptions.py
|
|
10
|
+
src/gitbolt/ls_tree.py
|
|
11
|
+
src/gitbolt/models.py
|
|
12
|
+
src/gitbolt/py.typed
|
|
13
|
+
src/gitbolt/pytest_plugin.py
|
|
14
|
+
src/gitbolt/utils.py
|
|
15
|
+
src/gitbolt.egg-info/PKG-INFO
|
|
16
|
+
src/gitbolt.egg-info/SOURCES.txt
|
|
17
|
+
src/gitbolt.egg-info/dependency_links.txt
|
|
18
|
+
src/gitbolt.egg-info/entry_points.txt
|
|
19
|
+
src/gitbolt.egg-info/requires.txt
|
|
20
|
+
src/gitbolt.egg-info/top_level.txt
|
|
21
|
+
src/gitbolt/subprocess/__init__.py
|
|
22
|
+
src/gitbolt/subprocess/_internal_init.py
|
|
23
|
+
src/gitbolt/subprocess/add.py
|
|
24
|
+
src/gitbolt/subprocess/base.py
|
|
25
|
+
src/gitbolt/subprocess/constants.py
|
|
26
|
+
src/gitbolt/subprocess/exceptions.py
|
|
27
|
+
src/gitbolt/subprocess/ls_tree.py
|
|
28
|
+
src/gitbolt/subprocess/utils.py
|
|
29
|
+
src/gitbolt/subprocess/impl/__init__.py
|
|
30
|
+
src/gitbolt/subprocess/impl/simple.py
|
|
31
|
+
src/gitbolt/subprocess/runner/__init__.py
|
|
32
|
+
src/gitbolt/subprocess/runner/base.py
|
|
33
|
+
src/gitbolt/subprocess/runner/simple.py
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# coding=utf-8
|
|
3
|
-
|
|
4
|
-
"""
|
|
5
|
-
Git command interfaces with default implementation using subprocess calls.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
# region imports
|
|
11
|
-
# region base related imports
|
|
12
|
-
from gitbolt.base import Git as Git
|
|
13
|
-
from gitbolt.base import CanOverrideGitOpts as CanOverrideGitOpts
|
|
14
|
-
from gitbolt.base import HasGitUnderneath as HasGitUnderneath
|
|
15
|
-
from gitbolt.base import GitSubCommand as GitSubCommand
|
|
16
|
-
from gitbolt.base import LsTree as LsTree
|
|
17
|
-
from gitbolt.base import Version as Version
|
|
18
|
-
from gitbolt.base import Add as Add
|
|
19
|
-
# endregion
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
from gitbolt.constants import GIT_DIR as GIT_DIR
|
|
23
|
-
# endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# TODO: check failing test on macos
|
|
27
|
-
def get_git(git_root_dir: Path = Path.cwd()) -> Git:
|
|
28
|
-
"""
|
|
29
|
-
Get operational and programmatic ``Git``.
|
|
30
|
-
|
|
31
|
-
Examples:
|
|
32
|
-
|
|
33
|
-
* Get git version:
|
|
34
|
-
|
|
35
|
-
>>> import subprocess
|
|
36
|
-
>>> import gitbolt
|
|
37
|
-
>>> git = gitbolt.get_git()
|
|
38
|
-
>>> assert git.version().version() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
|
|
39
|
-
|
|
40
|
-
:param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
|
|
41
|
-
"""
|
|
42
|
-
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
43
|
-
|
|
44
|
-
return SimpleGitCommand(git_root_dir)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# coding=utf-8
|
|
3
|
-
|
|
4
|
-
"""
|
|
5
|
-
Git command interfaces with implementation using subprocess calls.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
# region gitbolt.git_subprocess.base
|
|
9
|
-
from gitbolt.git_subprocess.base import GitCommand as GitCommand
|
|
10
|
-
from gitbolt.git_subprocess.base import GitSubcmdCommand as GitSubcmdCommand
|
|
11
|
-
from gitbolt.git_subprocess.base import AddCommand as AddCommand
|
|
12
|
-
from gitbolt.git_subprocess.base import LsTreeCommand as LsTreeCommand
|
|
13
|
-
from gitbolt.git_subprocess.base import VersionCommand as VersionCommand
|
|
14
|
-
from gitbolt.git_subprocess.base import UncheckedSubcmd as UncheckedSubcmd
|
|
15
|
-
# endregion
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
pyproject.toml
|
|
4
|
-
src/gitbolt/__init__.py
|
|
5
|
-
src/gitbolt/_internal_init.py
|
|
6
|
-
src/gitbolt/add.py
|
|
7
|
-
src/gitbolt/base.py
|
|
8
|
-
src/gitbolt/constants.py
|
|
9
|
-
src/gitbolt/exceptions.py
|
|
10
|
-
src/gitbolt/ls_tree.py
|
|
11
|
-
src/gitbolt/models.py
|
|
12
|
-
src/gitbolt/py.typed
|
|
13
|
-
src/gitbolt/pytest_plugin.py
|
|
14
|
-
src/gitbolt/utils.py
|
|
15
|
-
src/gitbolt.egg-info/PKG-INFO
|
|
16
|
-
src/gitbolt.egg-info/SOURCES.txt
|
|
17
|
-
src/gitbolt.egg-info/dependency_links.txt
|
|
18
|
-
src/gitbolt.egg-info/entry_points.txt
|
|
19
|
-
src/gitbolt.egg-info/requires.txt
|
|
20
|
-
src/gitbolt.egg-info/top_level.txt
|
|
21
|
-
src/gitbolt/git_subprocess/__init__.py
|
|
22
|
-
src/gitbolt/git_subprocess/_internal_init.py
|
|
23
|
-
src/gitbolt/git_subprocess/add.py
|
|
24
|
-
src/gitbolt/git_subprocess/base.py
|
|
25
|
-
src/gitbolt/git_subprocess/constants.py
|
|
26
|
-
src/gitbolt/git_subprocess/exceptions.py
|
|
27
|
-
src/gitbolt/git_subprocess/ls_tree.py
|
|
28
|
-
src/gitbolt/git_subprocess/utils.py
|
|
29
|
-
src/gitbolt/git_subprocess/impl/__init__.py
|
|
30
|
-
src/gitbolt/git_subprocess/impl/simple.py
|
|
31
|
-
src/gitbolt/git_subprocess/runner/__init__.py
|
|
32
|
-
src/gitbolt/git_subprocess/runner/base.py
|
|
33
|
-
src/gitbolt/git_subprocess/runner/simple_impl.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|