gitbolt 0.0.0.dev4__py3-none-any.whl → 0.0.0.dev6__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 CHANGED
@@ -4,6 +4,7 @@
4
4
  """
5
5
  Git command interfaces with default implementation using subprocess calls.
6
6
  """
7
+
7
8
  from pathlib import Path
8
9
 
9
10
  # region imports
@@ -38,4 +39,5 @@ def get_git(git_root_dir: Path = Path.cwd()) -> Git:
38
39
  :param git_root_dir: Path to the git repo root directory. Defaults to current working directory.
39
40
  """
40
41
  from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
42
+
41
43
  return SimpleGitCommand(git_root_dir)
gitbolt/base.py CHANGED
@@ -243,6 +243,18 @@ class Version(GitSubCommand, Protocol):
243
243
  """
244
244
  Require that arguments sent to the version command is valid.
245
245
 
246
+ Examples:
247
+
248
+ Correct:
249
+
250
+ >>> Version._require_valid_args()
251
+
252
+ Error:
253
+
254
+ >>> Version._require_valid_args(1) # type: ignore[arg-type] # required bool, supplied int
255
+ Traceback (most recent call last):
256
+ gitbolt.exceptions.GitExitingException: TypeError: build_options should be bool.
257
+
246
258
  :param build_options: argument to be validated.
247
259
  :raise GitExitingException: if supplied ``build_options`` is invalid.
248
260
  """
gitbolt/constants.py CHANGED
@@ -4,7 +4,8 @@
4
4
  """
5
5
  Constants related to gitbolt.
6
6
  """
7
+
7
8
  from pathlib import Path
8
9
 
9
- GIT_DIR_STR = '.git'
10
+ GIT_DIR_STR = ".git"
10
11
  GIT_DIR = Path(GIT_DIR_STR)
@@ -340,6 +340,7 @@ class LsTreeCommand(LsTree, GitSubcmdCommand, Protocol):
340
340
  self.args_validator.validate(tree_ish, **ls_tree_opts)
341
341
  sub_cmd_args = self.cli_args_builder.build(tree_ish, **ls_tree_opts)
342
342
  main_cmd_args = self.underlying_git.build_main_cmd_args()
343
+ env_vars = self.underlying_git.build_git_envs()
343
344
 
344
345
  # Run the git command
345
346
  result = self.underlying_git.runner.run_git_command(
@@ -349,6 +350,7 @@ class LsTreeCommand(LsTree, GitSubcmdCommand, Protocol):
349
350
  text=True,
350
351
  capture_output=True,
351
352
  cwd=self.root_dir,
353
+ env=env_vars,
352
354
  )
353
355
 
354
356
  return result.stdout.strip()
@@ -420,6 +422,7 @@ class AddCommand(Add, GitSubcmdCommand, Protocol):
420
422
  **add_opts,
421
423
  )
422
424
  main_cmd_args = self.underlying_git.build_main_cmd_args()
425
+ env_vars = self.underlying_git.build_git_envs()
423
426
 
424
427
  # Run the git command
425
428
  result = self.underlying_git.runner.run_git_command(
@@ -430,6 +433,7 @@ class AddCommand(Add, GitSubcmdCommand, Protocol):
430
433
  text=True,
431
434
  capture_output=True,
432
435
  cwd=self.root_dir,
436
+ env=env_vars,
433
437
  )
434
438
 
435
439
  return result.stdout.strip()
@@ -514,12 +518,12 @@ class UncheckedSubcmd(GitSubcmdCommand, RootDirOp, Protocol):
514
518
  """
515
519
  main_cmd_args = self.underlying_git.build_main_cmd_args()
516
520
  envs_vars = self.underlying_git.build_git_envs()
517
- another_supplied_env = subprocess_run_kwargs.pop('env', None)
521
+ another_supplied_env = subprocess_run_kwargs.pop("env", None)
518
522
  if another_supplied_env:
519
523
  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
524
+ cwd = subprocess_run_kwargs.pop("cwd", None) or self.root_dir
525
+ capture_output = subprocess_run_kwargs.pop("capture_output", None) or True
526
+ check = subprocess_run_kwargs.pop("check", None) or True
523
527
  # Run the git command
524
528
  result = self.underlying_git.runner.run_git_command(
525
529
  main_cmd_args,
@@ -531,6 +535,6 @@ class UncheckedSubcmd(GitSubcmdCommand, RootDirOp, Protocol):
531
535
  cwd=cwd,
532
536
  capture_output=capture_output,
533
537
  check=check,
534
- **subprocess_run_kwargs
538
+ **subprocess_run_kwargs,
535
539
  )
536
540
  return result
@@ -20,7 +20,7 @@ from gitbolt.git_subprocess import (
20
20
  LsTreeCommand,
21
21
  GitSubcmdCommand,
22
22
  AddCommand,
23
- UncheckedSubcmd
23
+ UncheckedSubcmd,
24
24
  )
25
25
  from gitbolt.git_subprocess.add import AddCLIArgsBuilder
26
26
  from gitbolt.git_subprocess.constants import VERSION_CMD
@@ -48,10 +48,16 @@ class VersionCommandImpl(VersionCommand, GitSubcmdCommandImpl):
48
48
  self._require_valid_args(build_options)
49
49
  main_cmd_args = self.underlying_git.build_main_cmd_args()
50
50
  sub_cmd_args = [VERSION_CMD]
51
+ env_vars = self.underlying_git.build_git_envs()
51
52
  if build_options:
52
53
  sub_cmd_args.append("--build-options")
53
54
  return self.underlying_git.runner.run_git_command(
54
- main_cmd_args, sub_cmd_args, check=True, text=True, capture_output=True
55
+ main_cmd_args,
56
+ sub_cmd_args,
57
+ check=True,
58
+ text=True,
59
+ capture_output=True,
60
+ env=env_vars,
55
61
  ).stdout.strip()
56
62
 
57
63
  def clone(self) -> "VersionCommandImpl":
@@ -133,11 +139,7 @@ class AddCommandImpl(AddCommand, GitSubcmdCommandImpl):
133
139
 
134
140
 
135
141
  class UncheckedSubcmdImpl(UncheckedSubcmd, GitSubcmdCommandImpl):
136
- def __init__(
137
- self,
138
- root_dir: Path,
139
- git: GitCommand
140
- ):
142
+ def __init__(self, root_dir: Path, git: GitCommand):
141
143
  super().__init__(git)
142
144
  self._root_dir = root_dir
143
145
 
@@ -151,7 +153,6 @@ class UncheckedSubcmdImpl(UncheckedSubcmd, GitSubcmdCommandImpl):
151
153
 
152
154
 
153
155
  class SimpleGitCommand(GitCommand, RootDirOp):
154
-
155
156
  def __init__(
156
157
  self,
157
158
  git_root_dir: Path = Path.cwd(),
@@ -160,7 +161,7 @@ class SimpleGitCommand(GitCommand, RootDirOp):
160
161
  version_subcmd: VersionCommand | None = None,
161
162
  ls_tree_subcmd: LsTreeCommand | None = None,
162
163
  add_subcmd: AddCommand | None = None,
163
- subcmd_unchecked: UncheckedSubcmd | None = None
164
+ subcmd_unchecked: UncheckedSubcmd | None = None,
164
165
  ):
165
166
  super().__init__(runner)
166
167
  self.git_root_dir = git_root_dir
@@ -172,17 +173,25 @@ class SimpleGitCommand(GitCommand, RootDirOp):
172
173
  @override
173
174
  @property
174
175
  def version_subcmd(self) -> VersionCommand:
175
- return self._version_subcmd
176
+ # TODO: in all subcommand methods, find a better way to retain envs and opts rather than cloning each time
177
+ # and setting the underlying git.
178
+ version_subcmd = self._version_subcmd.clone()
179
+ version_subcmd._set_underlying_git(self)
180
+ return version_subcmd
176
181
 
177
182
  @override
178
183
  @property
179
184
  def ls_tree_subcmd(self) -> LsTreeCommand:
180
- return self._ls_tree
185
+ ls_tree_subcmd = self._ls_tree.clone()
186
+ ls_tree_subcmd._set_underlying_git(self)
187
+ return ls_tree_subcmd
181
188
 
182
189
  @override
183
190
  @property
184
191
  def add_subcmd(self) -> AddCommand:
185
- return self._add_subcmd
192
+ add_subcmd = self._add_subcmd.clone()
193
+ add_subcmd._set_underlying_git(self)
194
+ return add_subcmd
186
195
 
187
196
  @override
188
197
  def clone(self) -> "SimpleGitCommand":
@@ -193,7 +202,7 @@ class SimpleGitCommand(GitCommand, RootDirOp):
193
202
  version_subcmd=self.version_subcmd,
194
203
  ls_tree_subcmd=self.ls_tree_subcmd,
195
204
  add_subcmd=self.add_subcmd,
196
- subcmd_unchecked=self.subcmd_unchecked
205
+ subcmd_unchecked=self.subcmd_unchecked,
197
206
  )
198
207
  # endregion
199
208
  # region clone protected members
@@ -209,4 +218,6 @@ class SimpleGitCommand(GitCommand, RootDirOp):
209
218
 
210
219
  @property
211
220
  def subcmd_unchecked(self) -> UncheckedSubcmd:
212
- return self._subcmd_unchecked
221
+ subcmd_unchecked = self._subcmd_unchecked.clone()
222
+ subcmd_unchecked._set_underlying_git(self)
223
+ return subcmd_unchecked
@@ -86,4 +86,6 @@ class SimpleGitCR(GitCommandRunner):
86
86
  **subprocess_run_kwargs,
87
87
  )
88
88
  except subprocess.CalledProcessError as e:
89
- raise GitCmdException(e.stderr, called_process_error=e, exit_code=e.returncode) from e
89
+ raise GitCmdException(
90
+ e.stderr, called_process_error=e, exit_code=e.returncode
91
+ ) from e
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env python3
2
+ # coding=utf-8
3
+
4
+ """
5
+ Third-party importable pytest plugins for ``gitbolt``.
6
+ """
7
+
8
+ import subprocess
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ REMOTE_DIR_NAME = "remote"
14
+ LOCAL_DIR_NAME = "local"
15
+
16
+
17
+ @pytest.fixture
18
+ def repo_root(tmpdir):
19
+ """
20
+ Create a test repo root to perform tests in.
21
+
22
+ :param tmpdir: temporary directory for test.
23
+ :return: temporary directory
24
+ """
25
+ return tmpdir
26
+
27
+
28
+ @pytest.fixture
29
+ def repo_remote(repo_root) -> Path:
30
+ subprocess.run(
31
+ ["git", "init", "--bare", REMOTE_DIR_NAME], cwd=repo_root, check=True
32
+ )
33
+ return repo_root / REMOTE_DIR_NAME
34
+
35
+
36
+ @pytest.fixture
37
+ def repo_local(repo_root, repo_remote) -> Path:
38
+ subprocess.run(
39
+ ["git", "clone", REMOTE_DIR_NAME, LOCAL_DIR_NAME], cwd=repo_root, check=True
40
+ )
41
+ 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.dev4
3
+ Version: 0.0.0.dev6
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
@@ -1,28 +1,30 @@
1
- gitbolt/__init__.py,sha256=fYw-eNfs7kpowyQOqx0K8rmoMCCg4pZnxrBFrmHvIfM,1174
1
+ gitbolt/__init__.py,sha256=SyV-PMv4Ul_k8sh7Y76Y4hUku1N5s-4ViyDpVbfRDOI,1176
2
2
  gitbolt/_internal_init.py,sha256=alSsIMgBWHmOdUo7P1ewftR12xPv8vb3ZgECuVsRMwk,485
3
3
  gitbolt/add.py,sha256=F16d0SQfLrjbpUzJIjKFwGU4KLSjqtYLOA9oZ5gdNS0,31731
4
- gitbolt/base.py,sha256=eUjzfu0OilCrOpxpwRyCSs7HD83OaXk6BCzxT8LKKhU,9322
5
- gitbolt/constants.py,sha256=5obkhMs8Og9P_xxQKEPvDx0io9mIYhZLc8Uv2WVrOHI,152
4
+ gitbolt/base.py,sha256=Vhd4GkTu3OscngXRJVfUMxVDY5Ilu6WVZvuhNw4dgFA,9649
5
+ gitbolt/constants.py,sha256=PyGZ8XG-OhSM7K0iHmZrTaF0-WwU5sCe8t8p7JcPu-c,153
6
6
  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=Gto30Ofmfz8kJ_AuBrEhqENmWoDlpMnsrpQWzHDmUi4,833
10
11
  gitbolt/utils.py,sha256=XftX3LIKtfzjQaUZUF3QYaFJFM-QdFjc05ZrZSMSdeM,6315
11
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=ywm_bGVt0R9ILyj5rtwYS3e-gQGIkaGSGkaPvm1JK9k,17591
15
+ gitbolt/git_subprocess/base.py,sha256=iAL_aFiywqbZGuPHTqY03ve5O0bYkdyLzmdzc30mM4E,17756
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=yY7tMI4B093ssooZB4UvffVQaCrFVD1bAIrieYPajLQ,6407
21
+ gitbolt/git_subprocess/impl/simple.py,sha256=sjdby07SlLfdKpGlLedN9nYEAWxkGqy-rlJ1x32rbtE,7051
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=V-6efvcQLP6gpUKSwRfnNI-Zd9nBxaN0EuAnpn-5LwU,2494
24
- gitbolt-0.0.0.dev4.dist-info/licenses/LICENSE,sha256=pOzr5bMWS6mHi3vro8d5vw0qW1i14rVq2XFrDuystVY,11372
25
- gitbolt-0.0.0.dev4.dist-info/METADATA,sha256=JsZQi3otwuW43nJQ-Szj-lo99zBjmjYDAD7jaIYBP7M,11227
26
- gitbolt-0.0.0.dev4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- gitbolt-0.0.0.dev4.dist-info/top_level.txt,sha256=QCXclkzSPZjgamcwB6XuKJexaJ1as_TLUUSGdIDA7VY,8
28
- gitbolt-0.0.0.dev4.dist-info/RECORD,,
24
+ gitbolt/git_subprocess/runner/simple_impl.py,sha256=JvKCQ_MITguuMn3f3hVQwfAukymkIqFdli5f2fxin54,2524
25
+ gitbolt-0.0.0.dev6.dist-info/licenses/LICENSE,sha256=pOzr5bMWS6mHi3vro8d5vw0qW1i14rVq2XFrDuystVY,11372
26
+ gitbolt-0.0.0.dev6.dist-info/METADATA,sha256=xBJyJKj2N0cyqasfrejKd1JocGRs6KA4ObWdpAvBDDQ,11249
27
+ gitbolt-0.0.0.dev6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ gitbolt-0.0.0.dev6.dist-info/entry_points.txt,sha256=Q078Wjss4skreUs8hzAEJ8sUcH4Rhjc9emZ4jRXCiBM,52
29
+ gitbolt-0.0.0.dev6.dist-info/top_level.txt,sha256=QCXclkzSPZjgamcwB6XuKJexaJ1as_TLUUSGdIDA7VY,8
30
+ gitbolt-0.0.0.dev6.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ gitbolt_fixtures = gitbolt.pytest_plugin