refactor(fetchPipMetadata): minor refactoring after code review

This commit is contained in:
DavHau 2023-07-10 13:49:28 +02:00
parent 8da26fae21
commit 49cc215538
5 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)