gitbolt 0.0.0.dev3__py3-none-any.whl → 0.0.0.dev5__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.
@@ -11,4 +11,5 @@ from gitbolt.git_subprocess.base import GitSubcmdCommand as GitSubcmdCommand
11
11
  from gitbolt.git_subprocess.base import AddCommand as AddCommand
12
12
  from gitbolt.git_subprocess.base import LsTreeCommand as LsTreeCommand
13
13
  from gitbolt.git_subprocess.base import VersionCommand as VersionCommand
14
+ from gitbolt.git_subprocess.base import UncheckedSubcmd as UncheckedSubcmd
14
15
  # endregion
@@ -9,9 +9,11 @@ from __future__ import annotations
9
9
 
10
10
  from abc import abstractmethod, ABC
11
11
  from pathlib import Path
12
- from typing import override, Protocol, Unpack, Self, overload, Literal
12
+ from subprocess import CompletedProcess
13
+ from typing import override, Protocol, Unpack, Self, overload, Literal, Any
13
14
 
14
15
  from vt.utils.commons.commons.core_py import is_unset, not_none_not_unset
16
+ from vt.utils.commons.commons.op import RootDirOp
15
17
 
16
18
  from gitbolt import Git, Version, LsTree, GitSubCommand, HasGitUnderneath, Add
17
19
  from gitbolt.git_subprocess.add import AddCLIArgsBuilder, IndividuallyOverridableACAB
@@ -283,6 +285,14 @@ class GitCommand(Git, ABC):
283
285
  @abstractmethod
284
286
  def add_subcmd(self) -> AddCommand: ...
285
287
 
288
+ @property
289
+ @abstractmethod
290
+ def subcmd_unchecked(self) -> UncheckedSubcmd:
291
+ """
292
+ Run an unchecked git subcommand using subprocess.
293
+ """
294
+ ...
295
+
286
296
 
287
297
  class GitSubcmdCommand(GitSubCommand, HasGitUnderneath["GitCommand"], Protocol):
288
298
  """
@@ -434,3 +444,93 @@ class AddCommand(Add, GitSubcmdCommand, Protocol):
434
444
  :return: Builder the complete list of subcommand CLI arguments to be passed to ``git add`` subprocess.
435
445
  """
436
446
  return IndividuallyOverridableACAB()
447
+
448
+
449
+ class UncheckedSubcmd(GitSubcmdCommand, RootDirOp, Protocol):
450
+ """
451
+ Unchecked git subcommand. Runs subcommands directly in subprocess.
452
+ """
453
+
454
+ @override
455
+ def _subcmd_from_git(self, git: "Git") -> Self:
456
+ return self
457
+
458
+ @overload
459
+ def run(
460
+ self,
461
+ subcommand_args: list[str],
462
+ *subprocess_run_args: Any,
463
+ _input: str,
464
+ text: Literal[True],
465
+ **subprocess_run_kwargs: Any,
466
+ ) -> CompletedProcess[str]: ...
467
+
468
+ @overload
469
+ def run(
470
+ self,
471
+ subcommand_args: list[str],
472
+ *subprocess_run_args: Any,
473
+ _input: bytes,
474
+ text: Literal[False],
475
+ **subprocess_run_kwargs: Any,
476
+ ) -> CompletedProcess[bytes]: ...
477
+
478
+ @overload
479
+ def run(
480
+ self,
481
+ subcommand_args: list[str],
482
+ *subprocess_run_args: Any,
483
+ text: Literal[True],
484
+ **subprocess_run_kwargs: Any,
485
+ ) -> CompletedProcess[str]: ...
486
+
487
+ @overload
488
+ def run(
489
+ self,
490
+ subcommand_args: list[str],
491
+ *subprocess_run_args: Any,
492
+ text: Literal[False] = ...,
493
+ **subprocess_run_kwargs: Any,
494
+ ) -> CompletedProcess[bytes]: ...
495
+
496
+ def run(
497
+ self,
498
+ subcommand_args: list[str],
499
+ *subprocess_run_args: Any,
500
+ _input: str | bytes | None = None,
501
+ text: Literal[True, False] = False,
502
+ **subprocess_run_kwargs,
503
+ ) -> CompletedProcess[str] | CompletedProcess[bytes]:
504
+ """
505
+ Run unchecked git subcommand using subprocess
506
+
507
+ :param subcommand_args: the full subcommand argument list.
508
+ :param subprocess_run_args: additional subprocess positionals.
509
+ :param _input: any stdin to be passed to the subprocess.
510
+ :param text: ``_input`` and returns both are str if this value is ``True``. Else, bytes are considered.
511
+ :param subprocess_run_kwargs: additional subprocess keyword arguments.
512
+
513
+ :return: ``CompletedProcess`` capturing all the required stdout, stderr, return-code etc.
514
+ """
515
+ main_cmd_args = self.underlying_git.build_main_cmd_args()
516
+ envs_vars = self.underlying_git.build_git_envs()
517
+ another_supplied_env = subprocess_run_kwargs.pop('env', None)
518
+ if another_supplied_env:
519
+ envs_vars.update(another_supplied_env)
520
+ cwd = subprocess_run_kwargs.pop('cwd', None) or self.root_dir
521
+ capture_output = subprocess_run_kwargs.pop('capture_output', None) or True
522
+ check = subprocess_run_kwargs.pop('check', None) or True
523
+ # Run the git command
524
+ result = self.underlying_git.runner.run_git_command(
525
+ main_cmd_args,
526
+ subcommand_args,
527
+ *subprocess_run_args,
528
+ _input=_input,
529
+ text=text,
530
+ env=envs_vars,
531
+ cwd=cwd,
532
+ capture_output=capture_output,
533
+ check=check,
534
+ **subprocess_run_kwargs
535
+ )
536
+ return result
@@ -20,6 +20,7 @@ from gitbolt.git_subprocess import (
20
20
  LsTreeCommand,
21
21
  GitSubcmdCommand,
22
22
  AddCommand,
23
+ UncheckedSubcmd
23
24
  )
24
25
  from gitbolt.git_subprocess.add import AddCLIArgsBuilder
25
26
  from gitbolt.git_subprocess.constants import VERSION_CMD
@@ -131,7 +132,26 @@ class AddCommandImpl(AddCommand, GitSubcmdCommandImpl):
131
132
  return AddCommandImpl(self.root_dir, self.underlying_git)
132
133
 
133
134
 
135
+ class UncheckedSubcmdImpl(UncheckedSubcmd, GitSubcmdCommandImpl):
136
+ def __init__(
137
+ self,
138
+ root_dir: Path,
139
+ git: GitCommand
140
+ ):
141
+ super().__init__(git)
142
+ self._root_dir = root_dir
143
+
144
+ @override
145
+ @property
146
+ def root_dir(self) -> Path:
147
+ return self._root_dir
148
+
149
+ def clone(self) -> "UncheckedSubcmdImpl":
150
+ return UncheckedSubcmdImpl(self.root_dir, self.underlying_git)
151
+
152
+
134
153
  class SimpleGitCommand(GitCommand, RootDirOp):
154
+
135
155
  def __init__(
136
156
  self,
137
157
  git_root_dir: Path = Path.cwd(),
@@ -140,12 +160,14 @@ class SimpleGitCommand(GitCommand, RootDirOp):
140
160
  version_subcmd: VersionCommand | None = None,
141
161
  ls_tree_subcmd: LsTreeCommand | None = None,
142
162
  add_subcmd: AddCommand | None = None,
163
+ subcmd_unchecked: UncheckedSubcmd | None = None
143
164
  ):
144
165
  super().__init__(runner)
145
166
  self.git_root_dir = git_root_dir
146
167
  self._version_subcmd = version_subcmd or VersionCommandImpl(self)
147
168
  self._ls_tree = ls_tree_subcmd or LsTreeCommandImpl(self.root_dir, self)
148
169
  self._add_subcmd = add_subcmd or AddCommandImpl(self.root_dir, self)
170
+ self._subcmd_unchecked = subcmd_unchecked or UncheckedSubcmdImpl(self.root_dir, self)
149
171
 
150
172
  @override
151
173
  @property
@@ -171,6 +193,7 @@ class SimpleGitCommand(GitCommand, RootDirOp):
171
193
  version_subcmd=self.version_subcmd,
172
194
  ls_tree_subcmd=self.ls_tree_subcmd,
173
195
  add_subcmd=self.add_subcmd,
196
+ subcmd_unchecked=self.subcmd_unchecked
174
197
  )
175
198
  # endregion
176
199
  # region clone protected members
@@ -183,3 +206,7 @@ class SimpleGitCommand(GitCommand, RootDirOp):
183
206
  @property
184
207
  def root_dir(self) -> Path:
185
208
  return self.git_root_dir
209
+
210
+ @property
211
+ def subcmd_unchecked(self) -> UncheckedSubcmd:
212
+ return self._subcmd_unchecked
@@ -86,4 +86,4 @@ class SimpleGitCR(GitCommandRunner):
86
86
  **subprocess_run_kwargs,
87
87
  )
88
88
  except subprocess.CalledProcessError as e:
89
- raise GitCmdException(called_process_error=e, exit_code=e.returncode) from e
89
+ raise GitCmdException(e.stderr, called_process_error=e, exit_code=e.returncode) from e
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python3
2
+ # coding=utf-8
3
+
4
+ """
5
+ Third-party importable pytest plugins for ``gitbolt``.
6
+ """
7
+ import subprocess
8
+ from pathlib import Path
9
+
10
+ import pytest
11
+
12
+ REMOTE_DIR_NAME = "remote"
13
+ LOCAL_DIR_NAME = "local"
14
+
15
+
16
+ @pytest.fixture
17
+ def repo_root(tmpdir):
18
+ """
19
+ Create a test repo root to perform tests in.
20
+
21
+ :param tmpdir: temporary directory for test.
22
+ :return: temporary directory
23
+ """
24
+ return tmpdir
25
+
26
+
27
+ @pytest.fixture
28
+ def repo_remote(repo_root) -> Path:
29
+ subprocess.run(
30
+ ["git", "init", "--bare", REMOTE_DIR_NAME], cwd=repo_root, check=True
31
+ )
32
+ return repo_root / REMOTE_DIR_NAME
33
+
34
+
35
+ @pytest.fixture
36
+ def repo_local(repo_root, repo_remote) -> Path:
37
+ subprocess.run(
38
+ ["git", "clone", REMOTE_DIR_NAME, LOCAL_DIR_NAME], cwd=repo_root, check=True
39
+ )
40
+ return repo_root / LOCAL_DIR_NAME
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitbolt
3
- Version: 0.0.0.dev3
3
+ Version: 0.0.0.dev5
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>
@@ -27,6 +27,7 @@ Requires-Python: >=3.12
27
27
  Description-Content-Type: text/markdown
28
28
  License-File: LICENSE
29
29
  Requires-Dist: vt-err-hndlr==0.0.0dev1
30
+ Requires-Dist: pytest
30
31
  Provides-Extra: pygit2
31
32
  Requires-Dist: pygit2; extra == "pygit2"
32
33
  Dynamic: license-file
@@ -272,6 +273,23 @@ no_advice_reset_git = overridden_git.git_opts_override(no_advice=False)
272
273
 
273
274
  </details>
274
275
 
276
+ ### 🔄 Run unchecked commands
277
+
278
+ At last, run unchecked commands in git.
279
+
280
+ Introduced in `0.0.0dev4` to
281
+ - experiment.
282
+ - have consistent interfaced commands run until all subcommands are provided by the library.
283
+
284
+ ```python
285
+ from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
286
+
287
+ git = SimpleGitCommand()
288
+ git = git.git_opts_override(no_advice=True)
289
+ git.subcmd_unchecked.run(['--version']) # run the version option for git.
290
+ git.subcmd_unchecked.run(['version']) # run the version subcommand.
291
+ ```
292
+
275
293
 
276
294
  ---
277
295
 
@@ -7,22 +7,24 @@ gitbolt/exceptions.py,sha256=7YvR7whZYM1hlWZk4GxHbeNgJ0KJXElg5VFA1Vi-fiA,989
7
7
  gitbolt/ls_tree.py,sha256=PrDSoh4Pnqh6g4AfX8kwgez_zHYaH4yqknULbFbisUY,6269
8
8
  gitbolt/models.py,sha256=iwIO-ugHYiKS57I_LPo3uDFEQlAtu2mnn5AjZHHQg04,18828
9
9
  gitbolt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ gitbolt/pytest_plugin.py,sha256=YPYqZN0Mi2kcZIXGl5bGXe-Y-NvgymnT58FpnFPiYPU,832
10
11
  gitbolt/utils.py,sha256=XftX3LIKtfzjQaUZUF3QYaFJFM-QdFjc05ZrZSMSdeM,6315
11
- gitbolt/git_subprocess/__init__.py,sha256=ynnsY2IDCsjzd2LU2GbXtIamNyBcME58q1yDsCBXCX8,515
12
+ gitbolt/git_subprocess/__init__.py,sha256=yEyJKH_iXFBkdgQMwE8vnHnhVTrjs2RkQUjUCF25SzU,590
12
13
  gitbolt/git_subprocess/_internal_init.py,sha256=C6jfsbjXhIFHaDH9GE-wLPAN9WMlUU57rRLWvfpZuAs,255
13
14
  gitbolt/git_subprocess/add.py,sha256=1PA9XonqFi2O941eBwIPMobSNgEJ0tgFYxlkVXSe1K4,17277
14
- gitbolt/git_subprocess/base.py,sha256=3DIydF-yQ7cVmT0di5cJtBVz-w68tawxk2xpq0yfcz8,14399
15
+ gitbolt/git_subprocess/base.py,sha256=ywm_bGVt0R9ILyj5rtwYS3e-gQGIkaGSGkaPvm1JK9k,17591
15
16
  gitbolt/git_subprocess/constants.py,sha256=3qHXbNjPf_DOhTPNHi3_bcvIpvtqvgFtpGoTJLYmTWk,250
16
17
  gitbolt/git_subprocess/exceptions.py,sha256=cx4YKzxeBRSRKoF-oakZLpFUGrAHiGj1FtMIsiK5oHc,4063
17
18
  gitbolt/git_subprocess/ls_tree.py,sha256=MmM3qh-kvkD_tGQG9yliLx-reY_5TIVEArvAXJN6rP4,13200
18
19
  gitbolt/git_subprocess/utils.py,sha256=n9_kXPvDf0ACrzAm6SVVLBOFM1JyjHmXJl_99vBoPS8,4941
19
20
  gitbolt/git_subprocess/impl/__init__.py,sha256=bxYluO0B3My-10H5Z0JuEGvZe_g8i71QTpt6iM0WXoU,97
20
- gitbolt/git_subprocess/impl/simple.py,sha256=nMxZYp1ayX6kyigLzIfrT5kNLvTd3KjYPDUNV4iB04U,5653
21
+ gitbolt/git_subprocess/impl/simple.py,sha256=yY7tMI4B093ssooZB4UvffVQaCrFVD1bAIrieYPajLQ,6407
21
22
  gitbolt/git_subprocess/runner/__init__.py,sha256=LPxbj3AwKLXyDxxCLwAVtl5b5SKjaNDj99lkKz6VSOU,177
22
23
  gitbolt/git_subprocess/runner/base.py,sha256=Sof2WaNyYULiObRF7WjaGs7-yGrdyeHUXchE2tg1820,1562
23
- gitbolt/git_subprocess/runner/simple_impl.py,sha256=ov8lXamu489twQanej0lCkkjBmEXvXxqGrWI_aK3JzQ,2484
24
- gitbolt-0.0.0.dev3.dist-info/licenses/LICENSE,sha256=pOzr5bMWS6mHi3vro8d5vw0qW1i14rVq2XFrDuystVY,11372
25
- gitbolt-0.0.0.dev3.dist-info/METADATA,sha256=dY1-qsrZ06buyBvm1sk42mA6HyPE4rCeRY4W3l4LmaI,10724
26
- gitbolt-0.0.0.dev3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- gitbolt-0.0.0.dev3.dist-info/top_level.txt,sha256=QCXclkzSPZjgamcwB6XuKJexaJ1as_TLUUSGdIDA7VY,8
28
- gitbolt-0.0.0.dev3.dist-info/RECORD,,
24
+ gitbolt/git_subprocess/runner/simple_impl.py,sha256=V-6efvcQLP6gpUKSwRfnNI-Zd9nBxaN0EuAnpn-5LwU,2494
25
+ gitbolt-0.0.0.dev5.dist-info/licenses/LICENSE,sha256=pOzr5bMWS6mHi3vro8d5vw0qW1i14rVq2XFrDuystVY,11372
26
+ gitbolt-0.0.0.dev5.dist-info/METADATA,sha256=ddzCTnVG2oGLM46wDDrRg-kanPhsJNODJsroolpf5jM,11249
27
+ gitbolt-0.0.0.dev5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ gitbolt-0.0.0.dev5.dist-info/entry_points.txt,sha256=Q078Wjss4skreUs8hzAEJ8sUcH4Rhjc9emZ4jRXCiBM,52
29
+ gitbolt-0.0.0.dev5.dist-info/top_level.txt,sha256=QCXclkzSPZjgamcwB6XuKJexaJ1as_TLUUSGdIDA7VY,8
30
+ gitbolt-0.0.0.dev5.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ gitbolt_fixtures = gitbolt.pytest_plugin