🐛 Differentiate transitive dependencies from direct third-party deps versus local deps

Open
#54 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

Start at parse_requirements and use the provided test_nested_deps example to trace how direct, transitive, third-party, and local-module dependencies are classified. The work is done when the expected requirements and extras_require assertions pass, with PyYaml remaining in common requirements rather than the nested module's extras.

Written by the indexing model from the issue text.

Description

stage/010-actionable stage/stalled

Describe the bug

A clear and concise description of what the bug is.
😆

Ok, this one is gross: With the fix in #49, a direct dependency held on a parent module that was also held on a child module would be correctly placed into the common dependency set because it is needed directly by the parent. This is, unfortunately, only a first-order fix since this same situation can occur when the dependency is needed by a Third Party dependency held directly by the parent rather than a local child sub-module.

This is only a problem if the requirements list given to parse_requirements includes the transitive dependency that is only used by the Third Party dependency and is NOT used anywhere inside of the local library. This is a very unlikely circumstance, but it could conceivably arise if the Third party dependency has an open version range for the transitive dependency, but the local library needs to pin that version for some valid reason (like a security patch)..

Platform

Please provide details about the environment you are using, including the following:

  • Interpreter version:
  • Library version:

Sample Code

def test_nested_deps():
    """Make sure that direct depencencies show up in requirements
    for nested modules
    """
    requirements, extras_require = parse_requirements(
        ["sample_lib", "PyYaml", "alchemy-logging"],
        "direct_dep_nested",
        ["direct_dep_nested.nested", "direct_dep_nested.nested2"]
    )

Expected behavior

The PyYaml dependency should be in the common requirements because it's needed transitively by sample_lib which is needed directly by the top-level direct_dep_nested module.

assert requirements == sorted(["alchemy-logging", "sample_lib"])
assert extras_require == {
    "all": sorted(["sample_lib", "PyYaml", "alchemy-logging", "PyYaml"]),
    "direct_dep_nested.nested": [],
    "direct_dep_nested.nested2": [],
}

Observed behavior

The PyYaml dependency is placed into the extras for direct_dep_nested.nested because it's held as an extra set and PyYaml is not allocated as a direct dependency of the top-level direct_dep_nested module.

assert requirements == sorted(["alchemy-logging", "sample_lib"])
assert extras_require == {
    "all": sorted(["sample_lib", "PyYaml", "alchemy-logging"]),
    "direct_dep_nested.nested": ["PyYaml"],
    "direct_dep_nested.nested2": [],
}

Additional context

Discovered when trying to write a test case for https://github.com/IBM/import-tracker/pull/53 with @prashantgupta24

Dominant language
Python
Stars
460
Forks
17
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from IBM/import-tracker

All issues in IBM/import-tracker

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.