Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requirement: Remove incorrect assertion around URL requirements without egg fragment #359

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ All versions prior to 0.0.9 are untracked.
* Fixed an issue where packages on PyPI with no published versions trigger a
dependency resolution failure instead of being skipped
([#357](https://github.com/trailofbits/pip-audit/pull/357))

* Fixed an incorrect assertion triggering for non-editable URL requirements that
don't have an egg fragment
([#359](https://github.com/trailofbits/pip-audit/pull/359))

## [2.4.3]

Expand Down
12 changes: 3 additions & 9 deletions pip_audit/_dependency_source/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from pip_requirements_parser import (
EditableRequirement,
InstallRequirement,
InvalidRequirementLine,
RequirementsFile,
)
from pip_requirements_parser import InstallRequirement, InvalidRequirementLine, RequirementsFile

from pip_audit._dependency_source import (
DependencyFixError,
Expand Down Expand Up @@ -95,13 +90,12 @@ def collect(self) -> Iterator[Dependency]:
req_names: Set[str] = set()
for req in rf.requirements:
if req.req is None:
# For editable requirements that don't have an egg fragment that lists the
# the package name and version, `pip-requirements-parser` won't attach a
# For URL requirements that don't have an egg fragment that lists the
# package name and version, `pip-requirements-parser` won't attach a
# `Requirement` object to the `InstallRequirement`.
#
# In this case, we can't audit the dependency so we should signal to the
# caller that we're skipping it.
assert isinstance(req, EditableRequirement)
yield SkippedDependency(
name=req.requirement_line.line,
skip_reason="could not deduce package/specifier pair from requirement, "
Expand Down
20 changes: 20 additions & 0 deletions test/dependency_source/test_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ def test_requirement_source_editable_without_egg_fragment(monkeypatch):
)


def test_requirement_source_non_editable_without_egg_fragment(monkeypatch):
source = requirement.RequirementSource([Path("requirements1.txt")], ResolveLibResolver())

monkeypatch.setattr(
pip_requirements_parser,
"get_file_content",
lambda _: "git+https://github.com/unbit/uwsgi.git@1bb9ad77c6d2d310c2d6d1d9ad62de61f725b824",
)

specs = list(source.collect())
assert (
SkippedDependency(
name="git+https://github.com/unbit/uwsgi.git@1bb9ad77c6d2d310c2d6d1d9ad62de61f725b824",
skip_reason="could not deduce package/specifier pair from requirement, please specify "
"them with #egg=your_package_name==your_package_version",
)
in specs
)


def _check_fixes(
input_reqs: List[str],
expected_reqs: List[str],
Expand Down