Skip to content

Commit

Permalink
LogicOverhaul: Default to full_depth in parse_requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Gabe Goodhart <[email protected]>
  • Loading branch information
gabe-l-hart committed Jul 26, 2022
1 parent 31877bf commit 3d53ff5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions import_tracker/setup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def parse_requirements(
requirements: Union[List[str], str],
library_name: str,
extras_modules: Optional[List[str]] = None,
full_depth: bool = True,
**kwargs,
) -> Tuple[List[str], Dict[str, List[str]]]:
"""This helper uses the lists of required modules and parameters for the
Expand All @@ -36,6 +37,10 @@ def parse_requirements(
extras_modules: Optional[List[str]]
List of module names that should be used to generate extras_require
sets
full_depth: bool
Passthrough to track_module. The default here is switched to True so
that modules which are both direct and transitive dependencies of
the library are correctly allocated.
**kwargs:
Additional keyword arguments to pass through to track_module
Expand Down Expand Up @@ -68,6 +73,7 @@ def parse_requirements(
library_name,
submodules=True,
detect_transitive=True,
full_depth=full_depth,
**kwargs,
)
log.debug4("Library Import Mapping:\n%s", library_import_mapping)
Expand Down
2 changes: 2 additions & 0 deletions test/sample_libs/full_depth_direct_and_transitive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Local
from . import bar, foo
3 changes: 3 additions & 0 deletions test/sample_libs/full_depth_direct_and_transitive/bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Import single_extra to get alog transitively
# Third Party
import single_extra
3 changes: 3 additions & 0 deletions test/sample_libs/full_depth_direct_and_transitive/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Depend on alog directly
# First Party
import alog
43 changes: 43 additions & 0 deletions test/test_setup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,46 @@ def test_nested_deps():
"direct_dep_nested.nested": sorted(["PyYaml"]),
"direct_dep_nested.nested2": sorted(["alchemy-logging"]),
}


def test_full_depth_direct_and_transitive():
"""Make sure that a library which holds a dependency as both a direct import
dependency and also requires it transitively through another third party
library correclty allocates the dependency to places where the intermediate
third party library is required.
"""
# Run without full_depth and ensure that alog is only allocated to foo and
# is not in the base requirements
requirements, extras_require = parse_requirements(
["single_extra", "alchemy-logging"],
"full_depth_direct_and_transitive",
[
"full_depth_direct_and_transitive.foo",
"full_depth_direct_and_transitive.bar",
],
full_depth=False,
)
assert requirements == []
assert extras_require == {
"all": sorted(["single_extra", "alchemy-logging"]),
"full_depth_direct_and_transitive.foo": ["alchemy-logging"],
"full_depth_direct_and_transitive.bar": ["single_extra"],
}

# Run without overriding full_depth (defaults to True) and ensure that alog
# is found transitively via single_extra so it ends up in the base
# requirements
requirements, extras_require = parse_requirements(
["single_extra", "alchemy-logging"],
"full_depth_direct_and_transitive",
[
"full_depth_direct_and_transitive.foo",
"full_depth_direct_and_transitive.bar",
],
)
assert requirements == ["alchemy-logging"]
assert extras_require == {
"all": sorted(["single_extra", "alchemy-logging"]),
"full_depth_direct_and_transitive.foo": [],
"full_depth_direct_and_transitive.bar": ["single_extra"],
}

0 comments on commit 3d53ff5

Please sign in to comment.