From 49cc215538b9193d37448e83f28d03888489908c Mon Sep 17 00:00:00 2001 From: DavHau Date: Mon, 10 Jul 2023 13:49:28 +0200 Subject: [PATCH] refactor(fetchPipMetadata): minor refactoring after code review --- .../src/fetch_pip_metadata/lock_file_from_report.py | 10 +++++----- v1/nix/pkgs/fetchPipMetadata/src/tests/conftest.py | 4 ++-- .../fetchPipMetadata/src/tests/test_evaluate_extras.py | 2 +- .../src/tests/test_lock_info_from_path.py | 4 ++-- .../tests/{test_git_repo_root.py => test_repo_root.py} | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename v1/nix/pkgs/fetchPipMetadata/src/tests/{test_git_repo_root.py => test_repo_root.py} (66%) diff --git a/v1/nix/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py b/v1/nix/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py index 8bf18e57..73839ad0 100644 --- a/v1/nix/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py +++ b/v1/nix/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py @@ -10,7 +10,7 @@ from packaging.utils import ( ) -def git_repo_root(directory): +def repo_root(directory): proc = subprocess.run( ["git", "rev-parse", "--show-toplevel"], text=True, @@ -60,9 +60,9 @@ def path_from_file_url(url): def lock_info_from_path(full_path): # See whether the path is relative to our local repo - repo_root = Path(git_repo_root(".")) - if repo_root in full_path.parents or repo_root == full_path: - return str(full_path.relative_to(repo_root)), None + repo = Path(repo_root(".")) + if repo in full_path.parents or repo == full_path: + return str(full_path.relative_to(repo)), None # Otherwise, we assume its in /nix/store and just the "top-level" # store path /nix/store/$hash-name/ @@ -70,7 +70,7 @@ def lock_info_from_path(full_path): if not Path("/nix/store") == store_path.parent: raise Exception( f"fatal: requirement '{full_path}' refers to something outside " - f"/nix/store and our local repo '{repo_root}'" + f"/nix/store and our local repo '{repo}'" ) # Check if its a FOD, if so use nix to print the derivation of our diff --git a/v1/nix/pkgs/fetchPipMetadata/src/tests/conftest.py b/v1/nix/pkgs/fetchPipMetadata/src/tests/conftest.py index e4c41e68..37de1dfb 100644 --- a/v1/nix/pkgs/fetchPipMetadata/src/tests/conftest.py +++ b/v1/nix/pkgs/fetchPipMetadata/src/tests/conftest.py @@ -1,11 +1,11 @@ from os import environ import pytest -import subprocess as sp +import subprocess from pathlib import Path from tempfile import TemporaryDirectory @pytest.fixture() def git_repo_path(tmp_path): - sp.run(["git", "init"], cwd=tmp_path) + subprocess.run(["git", "init"], cwd=tmp_path) return tmp_path diff --git a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_evaluate_extras.py b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_evaluate_extras.py index a2852fcd..c3ca4eeb 100644 --- a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_evaluate_extras.py +++ b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_evaluate_extras.py @@ -17,7 +17,7 @@ def test_marker_match(env): def test_marker_mismatch(env): env = dict(python_version="3.10") - requirement = Requirement("requests; python_version >= '3.11'") + requirement = Requirement("requests; python_version == '3.11'") assert l.evaluate_extras(requirement, None, env) == False diff --git a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_lock_info_from_path.py b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_lock_info_from_path.py index 0fc1cd19..2d88baac 100644 --- a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_lock_info_from_path.py +++ b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_lock_info_from_path.py @@ -5,10 +5,10 @@ import lock_file_from_report as l def test_path_in_repo_root(monkeypatch, git_repo_path): - def git_repo_root(path): + def repo_root(path): return git_repo_path - monkeypatch.setattr(l, "git_repo_root", git_repo_root) + monkeypatch.setattr(l, "repo_root", repo_root) assert l.lock_info_from_path(git_repo_path / "foo") == ("foo", None) diff --git a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_git_repo_root.py b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_repo_root.py similarity index 66% rename from v1/nix/pkgs/fetchPipMetadata/src/tests/test_git_repo_root.py rename to v1/nix/pkgs/fetchPipMetadata/src/tests/test_repo_root.py index 410f9182..dd28689a 100644 --- a/v1/nix/pkgs/fetchPipMetadata/src/tests/test_git_repo_root.py +++ b/v1/nix/pkgs/fetchPipMetadata/src/tests/test_repo_root.py @@ -9,8 +9,8 @@ import lock_file_from_report as l def test_not_in_repo(): with TemporaryDirectory() as tmpdir: - assert l.git_repo_root(str(tmpdir)) == str(Path(".").absolute()) + assert l.repo_root(str(tmpdir)) == str(Path(".").absolute()) def test_in_repo_root(git_repo_path): - assert l.git_repo_root(git_repo_path) == str(git_repo_path) + assert l.repo_root(git_repo_path) == str(git_repo_path)