Skip to content

Commit 820fa4f

Browse files
committed
Generate location-based hash also for system pip and npm packages
1 parent 6ccf6b1 commit 820fa4f

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

dependency_resolver/detectors/npm_detector.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def get_dependencies(
5050

5151
# Build result with desired field order: scope, location, hash, dependencies
5252
result: dict[str, Any] = {"scope": scope}
53-
if scope == "project":
54-
result["location"] = location
53+
result["location"] = location
5554

5655
if exit_code != 0:
5756
result["dependencies"] = dependencies

dependency_resolver/detectors/pip_detector.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ def get_dependencies(
4444
if exit_code != 0:
4545
location = self._get_pip_location(executor, working_dir)
4646
scope = "system" if self._is_system_location(location) else "project"
47-
result: dict[str, Any] = {"scope": scope}
48-
if scope == "project":
49-
result["location"] = location
50-
result["dependencies"] = {}
51-
return result
47+
return {"scope": scope, "location": location, "dependencies": {}}
5248

5349
dependencies = {}
5450
for line in stdout.strip().split("\n"):
@@ -65,17 +61,14 @@ def get_dependencies(
6561
scope = "system" if self._is_system_location(location) else "project"
6662

6763
# Build result with desired field order: scope, location, hash, dependencies
68-
final_result: dict[str, Any] = {"scope": scope}
64+
result: dict[str, Any] = {"scope": scope, "location": location}
6965

70-
if scope == "project":
71-
final_result["location"] = location
72-
# Generate location-based hash if appropriate
73-
if dependencies and not skip_hash_collection:
74-
final_result["hash"] = self._generate_location_hash(executor, location)
66+
# Generate location-based hash if appropriate
67+
if dependencies and not skip_hash_collection:
68+
result["hash"] = self._generate_location_hash(executor, location)
7569

76-
final_result["dependencies"] = dependencies
77-
78-
return final_result
70+
result["dependencies"] = dependencies
71+
return result
7972

8073
def _is_system_location(self, location: str) -> bool:
8174
"""Check if a location path represents a system-wide installation."""

tests/detectors/pip/test_pip_venv_detection.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,8 @@ def _validate_venv_detection(self, result: Dict[str, Any], expected_scope: str)
404404

405405
assert len(found_packages) >= 1, f"Should find at least 1 test package, found: {found_packages}"
406406

407-
# Should have a hash for project scope
408-
if expected_scope == "project":
409-
assert "hash" in result, "Project scope should include hash"
410-
assert isinstance(result["hash"], str), f"Hash should be string, got {type(result['hash'])}"
407+
assert "hash" in result, "Hash should be included"
408+
assert isinstance(result["hash"], str), f"Hash should be string, got {type(result['hash'])}"
411409

412410

413411
if __name__ == "__main__":

0 commit comments

Comments
 (0)