Skip to content

Commit

Permalink
Lift upper bounds on Grimp
Browse files Browse the repository at this point in the history
  • Loading branch information
seddonym committed Sep 28, 2022
1 parent 7d0955a commit 77b79ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ latest
------

* Include py.typed file in package data to support type checking
* Remove upper bounds on dependencies. This allows usage of Grimp 2.0, which should significantly speed up checking of
layers contracts.

1.3.0 (2022-08-22)
------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def read(*names, **kwargs):
"Topic :: Utilities",
],
python_requires=">=3.7",
install_requires=["click>=6,<9", "grimp>=1.3,<2", "typing-extensions>=3.10.0.0"],
install_requires=["click>=6", "grimp>=1.3", "typing-extensions>=3.10.0.0"],
extras_require={"toml": ["toml"]},
entry_points={
"console_scripts": ["lint-imports = importlinter.cli:lint_imports_command"]
Expand Down
13 changes: 9 additions & 4 deletions src/importlinter/contracts/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,21 @@ def _get_indirect_collapsed_chains(
temp_graph.squash_module(imported_package.name)

segments = cls._find_segments(
temp_graph, importer=importer_package, imported=imported_package
temp_graph, reference_graph=graph, importer=importer_package, imported=imported_package
)
return cls._segments_to_collapsed_chains(
graph, segments, importer=importer_package, imported=imported_package
)

@classmethod
def _find_segments(cls, graph: ImportGraph, importer: Module, imported: Module):
def _find_segments(
cls, graph: ImportGraph, reference_graph: ImportGraph, importer: Module, imported: Module
):
"""
Return list of headless and tailless detailed chains.
Two graphs are passed in: the first is mutated, the second is used purely as a reference to
look up import details which are otherwise removed during mutation.
"""
segments = []
for chain in cls._pop_shortest_chains(
Expand All @@ -350,7 +355,7 @@ def _find_segments(cls, graph: ImportGraph, importer: Module, imported: Module):
for importer_in_chain, imported_in_chain in [
(chain[i], chain[i + 1]) for i in range(len(chain) - 1)
]:
import_details = graph.get_import_details(
import_details = reference_graph.get_import_details(
importer=importer_in_chain, imported=imported_in_chain
)
line_numbers = tuple(set(j["line_number"] for j in import_details))
Expand Down Expand Up @@ -441,7 +446,7 @@ def _pop_direct_imports(cls, higher_layer_package, lower_layer_package, graph: I
lower_layer_package.name
)
for lower_layer_module in lower_layer_modules:
imported_modules = graph.find_modules_directly_imported_by(lower_layer_module)
imported_modules = graph.find_modules_directly_imported_by(lower_layer_module).copy()
for imported_module in imported_modules:
if Module(imported_module) == higher_layer_package or Module(
imported_module
Expand Down

0 comments on commit 77b79ad

Please sign in to comment.