Skip to content

Commit

Permalink
fix: Correct check if a requirement is a direct requirement
Browse files Browse the repository at this point in the history
"r.comes_from" can be "None" if a requirement is directly specified and not
listed in a requirements file.
  • Loading branch information
johbo committed Nov 5, 2023
1 parent 2ad8bd4 commit baee876
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pip2nix/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def process_requirements(self, options, requirement_set, finder, resolver):
if self.config.get_config('pip2nix', 'only_direct'):
packages_base = [
r for r in requirement_set.requirements.values()
if r.is_direct and not r.comes_from.startswith('-c ')]
if _is_direct_requirement(r)]
else:
try:
packages_base = requirement_set.all_requirements
Expand Down Expand Up @@ -390,3 +390,11 @@ def generate(config):
cmd = NixFreezeCommand(config)

return cmd.main([])


def _is_direct_requirement(r):
return r.is_direct and not _comes_from_constraint(r)


def _comes_from_constraint(r):
return r.comes_from and r.comes_from.startswith('-c ')

0 comments on commit baee876

Please sign in to comment.