pygitops
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: pygitops | ||
| Version: 0.16.0 | ||
| Version: 0.16.1 | ||
| Summary: Wrapper for low-level git logic. Useful for systems automating git operations. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/wayfair-incubator/pygitops |
| Metadata-Version: 2.1 | ||
| Name: pygitops | ||
| Version: 0.16.0 | ||
| Version: 0.16.1 | ||
| Summary: Wrapper for low-level git logic. Useful for systems automating git operations. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/wayfair-incubator/pygitops |
+26
-3
| import logging | ||
| import os | ||
| from contextlib import contextmanager | ||
| from os import PathLike | ||
| from pathlib import Path | ||
| from typing import Iterator | ||
| from typing import Iterator, Union | ||
@@ -11,3 +12,3 @@ from filelock import FileLock, Timeout | ||
| from pygitops.exceptions import PyGitOpsError | ||
| from pygitops.exceptions import PyGitOpsError, PyGitOpsWorkingDirError | ||
@@ -28,3 +29,3 @@ _logger = logging.getLogger(__name__) | ||
| repo_name = os.path.basename(os.path.normpath(repo.working_dir)) | ||
| repo_name = os.path.basename(os.path.normpath(repo_working_dir(repo))) | ||
| lockfile_name = str(get_lockfile_path(repo_name)) | ||
@@ -128,1 +129,23 @@ | ||
| return False | ||
| def repo_working_dir(repo: Repo) -> Union[str, PathLike]: | ||
| """ | ||
| Between gitpython 3.1.18 and 3.1.29, `git.Repo.working_dir` is now typed as Optional. | ||
| The `os.path` and `pathlib.Path` operations are not typed to support `Optional`. | ||
| Calling this function to access this property will handle cases where `repo.working_dir` is None, although it should never happen in practice. | ||
| :param repo: The repo whose `working_dir` we are interested in. | ||
| :raises PyGitOpsWorkingDirError: Raise error if `working_dir` is unexpectedly None. | ||
| :return str: `working_dir` of the repo | ||
| """ | ||
| working_dir = repo.working_dir | ||
| # Can replace with assignment operator when python 3.7 support is dropped | ||
| if working_dir is None: | ||
| raise PyGitOpsWorkingDirError( | ||
| f"The working_dir for repo {repo} is unexpectedly None" | ||
| ) | ||
| return working_dir |
@@ -11,1 +11,5 @@ class PyGitOpsError(Exception): | ||
| """There were no items to stage for commit.""" | ||
| class PyGitOpsWorkingDirError(PyGitOpsError): | ||
| """There was an error with the filesystem, namely `git.Repo.working_dir` is unexpectedly None.""" |
@@ -15,2 +15,3 @@ import logging | ||
| from pygitops._util import push_error_present as _push_error_present | ||
| from pygitops._util import repo_working_dir as _repo_working_dir | ||
| from pygitops.exceptions import PyGitOpsError, PyGitOpsStagedItemsError | ||
@@ -47,3 +48,3 @@ from pygitops.remote_git_utils import _scrub_github_auth | ||
| index = repo.index | ||
| workdir_path = Path(repo.working_dir) | ||
| workdir_path = Path(_repo_working_dir(repo)) | ||
@@ -50,0 +51,0 @@ # We will determine items_to_stage if the parameter was not provided. |
+1
-1
@@ -6,3 +6,3 @@ [metadata] | ||
| author_email = josh.woodward2693@gmail.com | ||
| version = 0.16.0 | ||
| version = 0.16.1 | ||
| description = Wrapper for low-level git logic. Useful for systems automating git operations. | ||
@@ -9,0 +9,0 @@ long_description = file: README.md |
+16
-16
@@ -10,3 +10,3 @@ import re | ||
| from pygitops._constants import GIT_BRANCH_MAIN, GIT_BRANCH_MASTER | ||
| from pygitops._util import checkout_pull_branch | ||
| from pygitops._util import checkout_pull_branch, repo_working_dir | ||
| from pygitops.exceptions import PyGitOpsError, PyGitOpsStagedItemsError | ||
@@ -72,3 +72,3 @@ from pygitops.operations import ( | ||
| # Write to remote from the clone, then pull from local | ||
| test_file_path = Path(cloned_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| test_file_path = Path(repo_working_dir(cloned_repo)) / SOME_CONTENT_FILENAME | ||
| test_file_path.write_text(SOME_INITIAL_CONTENT) | ||
@@ -83,3 +83,3 @@ | ||
| def _delete_existing_file(local_repo: Repo, filename: str) -> None: | ||
| test_second_file_path = Path(local_repo.working_dir) / filename | ||
| test_second_file_path = Path(repo_working_dir(local_repo)) / filename | ||
| test_second_file_path.unlink() | ||
@@ -89,3 +89,3 @@ | ||
| def _modify_existing_file(local_repo: Repo, filename: str, content: str) -> None: | ||
| test_file_path = Path(local_repo.working_dir) / filename | ||
| test_file_path = Path(repo_working_dir(local_repo)) / filename | ||
| test_file_path.write_text(content) | ||
@@ -95,3 +95,3 @@ | ||
| def _add_new_file(local_repo: Repo, filename: str) -> None: | ||
| test_other_file_path = Path(local_repo.working_dir) / filename | ||
| test_other_file_path = Path(repo_working_dir(local_repo)) / filename | ||
| test_other_file_path.touch() | ||
@@ -196,3 +196,3 @@ | ||
| test_file_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| test_file_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
| test_file_path.write_text(SOME_INITIAL_CONTENT) | ||
@@ -226,3 +226,3 @@ | ||
| with feature_branch(cloned_repo, SOME_FEATURE_BRANCH): | ||
| test_file_path = Path(cloned_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| test_file_path = Path(repo_working_dir(cloned_repo)) / SOME_CONTENT_FILENAME | ||
| test_file_path.write_text(SOME_INITIAL_CONTENT) | ||
@@ -241,3 +241,3 @@ | ||
| ): | ||
| removal_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| removal_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
| removal_path.unlink() | ||
@@ -271,5 +271,5 @@ | ||
| test_file_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| test_file_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
| test_file_path.write_text(SOME_INITIAL_CONTENT) | ||
| other_file_path = Path(local_repo.working_dir) / other_file | ||
| other_file_path = Path(repo_working_dir(local_repo)) / other_file | ||
| other_file_path.write_text("other test content") | ||
@@ -312,3 +312,3 @@ | ||
| with feature_branch(local_repo, SOME_FEATURE_BRANCH): | ||
| test_file_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| test_file_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
| test_file_path.write_text("content one") | ||
@@ -820,3 +820,3 @@ stage_commit_push_changes( | ||
| local_content_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| local_content_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
@@ -840,3 +840,3 @@ # The file should exist only on local before pushing | ||
| """Run assertions before and after staging, committing, and pushing for a given repo pair.""" | ||
| local_content_path = Path(local_repo.working_dir) / SOME_CONTENT_FILENAME | ||
| local_content_path = Path(repo_working_dir(local_repo)) / SOME_CONTENT_FILENAME | ||
@@ -887,4 +887,4 @@ # The file should exist only on local before pushing | ||
| # Because they are clones, they will have 'origin' correctly configured | ||
| local_repo = Repo.clone_from(remote_repo.working_dir, local_path) | ||
| cloned_repo = Repo.clone_from(remote_repo.working_dir, clone_path) | ||
| local_repo = Repo.clone_from(repo_working_dir(remote_repo), local_path) | ||
| cloned_repo = Repo.clone_from(repo_working_dir(remote_repo), clone_path) | ||
@@ -905,3 +905,3 @@ return MultipleTestingRepos( | ||
| index = repo.index | ||
| workdir_path = Path(repo.working_dir) | ||
| workdir_path = Path(repo_working_dir(repo)) | ||
@@ -908,0 +908,0 @@ untracked_file_paths = [Path(f) for f in repo.untracked_files] |
+18
-1
@@ -16,4 +16,5 @@ import shutil | ||
| push_error_present, | ||
| repo_working_dir, | ||
| ) | ||
| from pygitops.exceptions import PyGitOpsError | ||
| from pygitops.exceptions import PyGitOpsError, PyGitOpsWorkingDirError | ||
@@ -197,1 +198,17 @@ SOME_REPO_NAME = "some-repo-name" | ||
| assert is_git_repo(tmp_path) | ||
| def test_repo_working_dir__working_dir_none__raises_pygitops_working_dir_error(mocker): | ||
| repo = mocker.Mock(working_dir=None) | ||
| with pytest.raises(PyGitOpsWorkingDirError): | ||
| repo_working_dir(repo) | ||
| def test_repo_working_dir__working_dir_present__expected_working_dir_returned(tmp_path): | ||
| repo_path = tmp_path / SOME_REPO_NAME | ||
| repo_path.mkdir() | ||
| repo = Repo.init(repo_path) | ||
| assert repo_working_dir(repo) == str(repo_path) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
68891
2.64%1223
2.51%