Skip to content

Commit

Permalink
Increase cov
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Nov 30, 2023
1 parent 45deb3d commit abb1e1a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
29 changes: 26 additions & 3 deletions tests/test_unidep.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""unidep tests."""
from __future__ import annotations

import shutil
import subprocess
import textwrap
from pathlib import Path
Expand Down Expand Up @@ -1416,10 +1417,32 @@ def test_mixed_real_and_placeholder_dependencies(tmp_path: Path) -> None:
assert requirements == {}


def test_parse_project_dependencies_pip_installable() -> None:
example_folder = REPO_ROOT / "example"
def test_parse_project_dependencies_pip_installable(tmp_path: Path) -> None:
example_folder = tmp_path / "example"
shutil.copytree(REPO_ROOT / "example", example_folder)

# Add an extra project
extra_project = example_folder / "project69"
extra_project.mkdir(exist_ok=True, parents=True)
(extra_project / "requirements.yaml").write_text("includes: [../project1]")

# Add a line to project1 includes
project1_req = example_folder / "project1" / "requirements.yaml"
yaml = YAML(typ="safe")
with project1_req.open("r") as f:
requirements = yaml.load(f)
requirements["includes"].append("../project69")
with project1_req.open("w") as f:
yaml.dump(requirements, f)

found_files = find_requirements_files(example_folder)
assert found_files
assert len(found_files) == 4

# Add a common requirements file
common_requirements = example_folder / "common-requirements.yaml"
common_requirements.write_text("includes: [project1]")
found_files.append(common_requirements)

requirements = parse_project_dependencies(
*found_files,
check_pip_installable=True,
Expand Down
16 changes: 10 additions & 6 deletions unidep.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,18 @@ def parse_yaml_requirements( # noqa: PLR0912

def _extract_project_dependencies( # noqa: PLR0913
path: Path,
base_path: str,
base_path: Path,
processed: set,
dependencies: dict[str, set[str]],
*,
check_pip_installable: bool = True,
verbose: bool = False,
) -> None:
print(processed)
if check_pip_installable and not _is_pip_installable(base_path):
if verbose:
msg = f"⚠️ `{base_path}` is not pip installable, skipping."
print(msg)
return
if path in processed:
return
processed.add(path)
Expand All @@ -373,14 +377,14 @@ def _extract_project_dependencies( # noqa: PLR0913
msg = f"Include file `{include_path}` does not exist."
raise FileNotFoundError(msg)
if check_pip_installable and not _is_pip_installable(include_path.parent):
if verbose: # pragma: no cover
if verbose:
msg = f"⚠️ `{include_path.parent}` is not pip installable, skipping."
print(msg)
continue
include_base_path = str(include_path.parent)
if include_base_path == base_path:
if include_base_path == str(base_path):
continue
dependencies[base_path].add(include_base_path)
dependencies[str(base_path)].add(include_base_path)
if verbose:
print(f"🔗 Adding include `{include_path}`")
_extract_project_dependencies(
Expand All @@ -406,7 +410,7 @@ def parse_project_dependencies(
for p in paths:
if verbose:
print(f"🔗 Analyzing dependencies in `{p}`")
base_path = str(p.resolve().parent)
base_path = p.resolve().parent
_extract_project_dependencies(
path=p,
base_path=base_path,
Expand Down

0 comments on commit abb1e1a

Please sign in to comment.