gitbolt 0.0.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,97 @@
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
+ from gitbolt.subprocess.base import GitSession as GitSession
21
+ # endregion
22
+
23
+
24
+ from gitbolt.constants import GIT_DIR as GIT_DIR
25
+ from gitbolt.subprocess.constants import GIT_CMD
26
+ from gitbolt.subprocess.impl.simple import SimpleGitCommand as _SimpleGitCommand
27
+ from gitbolt.subprocess.impl.simple import CLISimpleGitCommand as _CLISimpleGitCommand
28
+ from gitbolt.subprocess.runner.simple import SimpleGitCR as _SimpleGitCR
29
+ # endregion
30
+
31
+
32
+ def get_git(git_root_dir: Path = Path.cwd()) -> Git:
33
+ """
34
+ Get operational and programmatic ``Git``.
35
+
36
+ Examples:
37
+
38
+ * Get git version:
39
+
40
+ >>> import subprocess
41
+ >>> import gitbolt
42
+ >>> git = gitbolt.get_git()
43
+ >>> assert git.version().version() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
44
+
45
+ :param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
46
+ :returns: The ``Git`` instance with all subcommands.
47
+ """
48
+
49
+ return _SimpleGitCommand(git_root_dir)
50
+
51
+
52
+ def get_git_command(
53
+ git_root_dir: Path = Path.cwd(),
54
+ *,
55
+ git_prog: str | Path = GIT_CMD,
56
+ opts: list[str] | None = None,
57
+ envs: dict[str, str] | None = None,
58
+ prefer_cli: bool = False,
59
+ ) -> GitCommand:
60
+ """
61
+ Get operational and programmatic ``Git`` which runs as a subprocess.
62
+
63
+ Examples:
64
+
65
+ * Get git version, as base git:
66
+
67
+ >>> import subprocess
68
+ >>> import gitbolt
69
+ >>> git = gitbolt.get_git_command()
70
+ >>> assert git.version().version() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
71
+
72
+ * Get git version, as a git subcommand. Runs git in subprocess:
73
+
74
+ >>> assert git.subcmd_unchecked().run(["version"], text=True).stdout.strip() == subprocess.run(['git', 'version'], capture_output=True, text=True).stdout.strip()
75
+
76
+ :param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
77
+ :param git_prog: git program name/location. Useful when user wants to run a separate git version/git emulator.
78
+ :param opts: main git cli options. The main git command options like ``--no-replace-objects``, ``--no-pager``, ``-C`` etc are git main command args.
79
+ :param envs: main git cli environment variables (env vars). Not supplying any env vars (default behavior: ``None``)
80
+ simply supplies all the env vars to the underlying runner.
81
+ :param prefer_cli: cli opts and envs will be given priority over programmatically set opts and envs. Setting
82
+ this param to ``True`` will make cli opts and envs appear later in the opts and envs strings which will
83
+ make them override previously programmatically set opts and envs.
84
+ :returns: ``GitCommand`` instance with all the subcommands as well as ``unchecked_subcmd``. Runs git commands in a
85
+ separate runner in subprocess.
86
+ """
87
+ runner = _SimpleGitCR(git_prog)
88
+ if opts is None:
89
+ return _SimpleGitCommand(git_root_dir, runner)
90
+ else:
91
+ return _CLISimpleGitCommand(
92
+ git_root_dir,
93
+ runner,
94
+ opts=opts,
95
+ envs=envs,
96
+ prefer_cli=prefer_cli,
97
+ )
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env python3
2
+ # coding=utf-8
3
+
4
+ """
5
+ Git command interfaces with default implementation using subprocess calls.
6
+
7
+ This file is created to behave as an __init__ but only for internal stuff as we do not want to export everything
8
+ in the package's __init__.
9
+ """
10
+
11
+ from vt.utils.errors.error_specs import ErrorMsgFormer
12
+
13
+ errmsg_creator = ErrorMsgFormer
14
+ """
15
+ Create formatted error messages using this global instance.
16
+
17
+ To get a local instance use ``errmsg_creator.clone_with(...)``.
18
+ """