Skip to content

check_reqs only checks transitive dependencies if they're a part of an extra #109

@smheidrich

Description

@smheidrich

The problem

The documentation of check_reqs says:

Check if the given requirements are all satisfied.
[...]
[Returns:] All the requirements in reqs satisfied or not.

But in reality, it only checks transitive ("nested") dependencies if they're part of a top-level extra or its extras, recursively.

To reproduce

To convince yourself that this is the case, you can:

  1. Install typer-slim[standard]==0.12.5.
    • This depends on rich for the standard extra, while rich in turn depends on Pygments unconditionally.
  2. Uninstall Pygments manually with Pip, leaving rich itself installed but with broken dependencies.
  3. Notice that check_reqs("typer-slim[standard]") still returns True.
  4. Optional sanity check: Uninstall rich, which will cause check_reqs("typer-slim[standard]") to correctly return False (because its direct dependent is the standard extra of typer-slim).

Comparison to "reference" library

This is different from the behavior of e.g. pkg_resources.require, which checks all dependencies recursively whether they're part of an extra or not.

Cause in the code

The code section that causes this to happen:

need_check, ext = False, None
for extra in req.extras:
if child_req_obj.marker and child_req_obj.marker.evaluate({'extra': extra}):
need_check = True
ext = extra
break
if need_check: # check for extra reqs
yield from _yield_reqs_to_install(child_req_obj, ext)

Only extras are iterated over to determine whether a child dependency should be processed.

What I think should happen

So IMO either a) the documentation of check_reqs should be updated to reflect the fact it only looks at packages that are dependencies of a top-level extra (or extras below that, recursively) or b) this should be fixed to behave the same as pkg_resources.require.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions