Skip to content

Commit 7ccd355

Browse files
committed
Make the signature for get_git_url return an empty string rather than None if there is no remote for ease of type checking
1 parent cfdaabf commit 7ccd355

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/tap/tap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def add_subparser(self, flag: str, subparser_type: type, **kwargs) -> None:
331331
self._subparser_buffer.append((flag, subparser_type, kwargs))
332332

333333
def _add_subparsers(self) -> None:
334-
"""Add each of the subparsers to the Tap object. """
334+
"""Add each of the subparsers to the Tap object."""
335335
# Initialize the _subparsers object if not already created
336336
if self._subparsers is None and len(self._subparser_buffer) > 0:
337337
self._subparsers = super(Tap, self).add_subparsers()
@@ -345,7 +345,7 @@ def add_subparsers(self, **kwargs) -> None:
345345
self._subparsers = super().add_subparsers(**kwargs)
346346

347347
def _configure(self) -> None:
348-
"""Executes the user-defined configuration. """
348+
"""Executes the user-defined configuration."""
349349
# Call the user-defined configuration
350350
self.configure()
351351

@@ -370,7 +370,7 @@ def configure(self) -> None:
370370
pass
371371

372372
@staticmethod
373-
def get_reproducibility_info(repo_path: Optional[PathLike] = None) -> Dict[str, Optional[str]]:
373+
def get_reproducibility_info(repo_path: Optional[PathLike] = None) -> Dict[str, str]:
374374
"""Gets a dictionary of reproducibility information.
375375
376376
Reproducibility information always includes:
@@ -402,7 +402,7 @@ def get_reproducibility_info(repo_path: Optional[PathLike] = None) -> Dict[str,
402402
if git_info.has_git():
403403
reproducibility["git_root"] = git_info.get_git_root()
404404
reproducibility["git_url"] = git_info.get_git_url(commit_hash=True)
405-
reproducibility["git_has_uncommitted_changes"] = git_info.has_uncommitted_changes()
405+
reproducibility["git_has_uncommitted_changes"] = str(git_info.has_uncommitted_changes())
406406

407407
return reproducibility
408408

@@ -727,7 +727,7 @@ def __deepcopy__(self, memo: Dict[int, Any] = None) -> TapType:
727727

728728
memo[id(self)] = copied
729729

730-
for (k, v) in self.__dict__.items():
730+
for k, v in self.__dict__.items():
731731
copied.__dict__[k] = deepcopy(v, memo)
732732

733733
return copied

src/tap/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ def get_git_version(self) -> tuple:
8383
number_start_index = next(i for i, c in enumerate(raw) if c.isdigit())
8484
return tuple(int(num) for num in raw[number_start_index:].split("."))
8585

86-
def get_git_url(self, commit_hash: bool = True) -> Optional[str]:
86+
def get_git_url(self, commit_hash: bool = True) -> str:
8787
"""Gets the https url of the git repo where the command is run.
8888
8989
:param commit_hash: If True, the url links to the latest local git commit hash.
9090
If False, the url links to the general git url.
91-
:return: The https url of the current git repo.
91+
:return: The https url of the current git repo or an empty string for a local repo.
9292
"""
9393
# Get git url (either https or ssh)
9494
input_remote = (
@@ -102,7 +102,7 @@ def get_git_url(self, commit_hash: bool = True) -> Optional[str]:
102102
if e.returncode == 2:
103103
# https://git-scm.com/docs/git-remote#_exit_status
104104
# 2: The remote does not exist.
105-
return None
105+
return ""
106106
raise e
107107

108108
# Remove .git at end
@@ -417,7 +417,7 @@ def default(self, obj: Any) -> Any:
417417

418418

419419
class UnpicklableObject:
420-
"""A class that serves as a placeholder for an object that could not be pickled. """
420+
"""A class that serves as a placeholder for an object that could not be pickled."""
421421

422422
def __eq__(self, other):
423423
return isinstance(other, UnpicklableObject)

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_get_git_url_ssh_hash_enterprise(self) -> None:
110110

111111
def test_get_git_url_no_remote(self) -> None:
112112
subprocess.run(["git", "remote", "remove", "origin"])
113-
self.assertIsNone(self.git_info.get_git_url())
113+
self.assertEqual(self.git_info.get_git_url(), "")
114114

115115
def test_get_git_version(self) -> None:
116116
git_version = self.git_info.get_git_version()

0 commit comments

Comments
 (0)