-
Notifications
You must be signed in to change notification settings - Fork 19
Enable various Ruff rulesets #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,9 +147,10 @@ def _module_name_from_filename( | |
| """ | ||
| internal_filename_and_path = filename_and_path[len(package_directory) :] | ||
| internal_filename_and_path_without_extension = internal_filename_and_path[1:-3] | ||
| components = [package_name] + internal_filename_and_path_without_extension.split( | ||
| self.file_system.sep | ||
| ) | ||
| components = [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unpacking syntax is a stylistic choice. Personally I like it but feel free to disagree - I'll revert and ignore the rule. |
||
| package_name, | ||
| *internal_filename_and_path_without_extension.split(self.file_system.sep), | ||
| ] | ||
| if components[-1] == "__init__": | ||
| components.pop() | ||
| return ".".join(components) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,18 +54,12 @@ def large_graph(): | |
| heads=frozenset({"mypackage.domain.7960519247.6215972208"}), | ||
| middle=(), | ||
| tails=frozenset( | ||
| { | ||
| "mypackage.application.7537183614.6928774480.5676105139.3275676604" | ||
| # noqa:E501 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latest version of ruff doesn't consider these to be "line-too-long" violations so these rule codes can be removed. |
||
| } | ||
| {"mypackage.application.7537183614.6928774480.5676105139.3275676604"} | ||
| ), | ||
| ), | ||
| Route( | ||
| heads=frozenset( | ||
| { | ||
| "mypackage.domain.6928774480.5676105139.1330171288.7588443317.4661445087" | ||
| # noqa:E501 | ||
| } | ||
| {"mypackage.domain.6928774480.5676105139.1330171288.7588443317.4661445087"} | ||
| ), | ||
| middle=(), | ||
| tails=frozenset({"mypackage.application.7537183614.3430454356.1518604543"}), | ||
|
|
@@ -84,10 +78,7 @@ def large_graph(): | |
| ), | ||
| Route( | ||
| heads=frozenset( | ||
| { | ||
| "mypackage.domain.6928774480.1028759677.7960519247.2888779155.7486857426" | ||
| # noqa:E501 | ||
| } | ||
| {"mypackage.domain.6928774480.1028759677.7960519247.2888779155.7486857426"} | ||
| ), | ||
| middle=(), | ||
| tails=frozenset({"mypackage.application.7537183614.3430454356.1518604543"}), | ||
|
|
@@ -139,18 +130,14 @@ def large_graph(): | |
| heads=frozenset( | ||
| { | ||
| "mypackage.application.7537183614.2538372545.1153384736.6297289996", | ||
| # noqa:E501 | ||
| "mypackage.application.7537183614.2538372545.1153384736.6404547812.6297289996", | ||
| # noqa:E501 | ||
| } | ||
| ), | ||
| middle=("mypackage.6398020133.9075581450.6529869526.6297289996",), | ||
| tails=frozenset( | ||
| { | ||
| "mypackage.plugins.5634303718.6180716911.7582995238.1039461003.2943193489", | ||
| # noqa:E501 | ||
| "mypackage.plugins.5634303718.6180716911.7582995238.1039461003.6322703811", | ||
| # noqa:E501 | ||
| } | ||
| ), | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import re | ||
| import pytest # type: ignore | ||
|
|
||
| from grimp.application.graph import ImportGraph | ||
|
|
@@ -112,14 +113,14 @@ def test_find_shortest_chain_returns_none_if_not_exists(self): | |
| def test_raises_value_error_if_importer_not_present(self): | ||
| graph = ImportGraph() | ||
|
|
||
| with pytest.raises(ValueError, match="Module foo is not present in the graph."): | ||
| with pytest.raises(ValueError, match=re.escape("Module foo is not present in the graph.")): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| graph.find_shortest_chain(importer="foo", imported="bar") | ||
|
|
||
| def test_raises_value_error_if_imported_not_present(self): | ||
| graph = ImportGraph() | ||
| graph.add_module("foo") | ||
|
|
||
| with pytest.raises(ValueError, match="Module bar is not present in the graph."): | ||
| with pytest.raises(ValueError, match=re.escape("Module bar is not present in the graph.")): | ||
| graph.find_shortest_chain(importer="foo", imported="bar") | ||
|
|
||
| def test_find_shortest_chain_copes_with_cycle(self): | ||
|
|
@@ -164,7 +165,7 @@ def test_demonstrate_nondeterminism_of_equal_chains(self): | |
|
|
||
| one_chain = (source, a, b, c, destination) | ||
| other_chain = (source, d, e, f, destination) | ||
| assert (result == one_chain) or (result == other_chain) | ||
| assert result in (one_chain, other_chain) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stylistic (similar comment to before regarding unpackaging syntax) |
||
|
|
||
| @pytest.mark.parametrize( | ||
| "as_packages, expected_result", | ||
|
|
@@ -201,7 +202,7 @@ def test_modules_with_shared_descendants_raises_value_error_when_as_packages_tru | |
| graph.add_module(importer) | ||
| graph.add_module(imported) | ||
|
|
||
| with pytest.raises(ValueError, match="Modules have shared descendants."): | ||
| with pytest.raises(ValueError, match=re.escape("Modules have shared descendants.")): | ||
| graph.find_shortest_chains(importer=importer, imported=imported, as_packages=True) | ||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,7 +83,7 @@ def test_indirect_illegal_within_one_package( | |
| self, specify_container: bool, start: str, end: str, route_middle: list[str] | ||
| ): | ||
| graph = self._build_legal_graph() | ||
| import_pairs = _pairwise([start] + route_middle + [end]) | ||
| import_pairs = _pairwise([start, *route_middle, end]) | ||
| for importer, imported in import_pairs: | ||
| graph.add_import(importer=importer, imported=imported) | ||
|
|
||
|
|
@@ -342,7 +342,7 @@ def test_demonstrate_nondeterminism_with_equal_length_forked_routes(self): | |
| ), | ||
| } | ||
|
|
||
| assert (result == first_option) or (result == second_option) | ||
| assert result in (first_option, second_option) | ||
|
|
||
| def _build_legal_graph(self): | ||
| graph = ImportGraph() | ||
|
|
@@ -479,7 +479,7 @@ def test_indirect_illegal_within_one_package( | |
| self, specify_container: bool, start: str, end: str, route_middle: list[str] | ||
| ): | ||
| graph = self._build_legal_graph() | ||
| import_pairs = _pairwise([start] + route_middle + [end]) | ||
| import_pairs = _pairwise([start, *route_middle, end]) | ||
| for importer, imported in import_pairs: | ||
| graph.add_import(importer=importer, imported=imported) | ||
|
|
||
|
|
@@ -668,7 +668,7 @@ def test_indirect_illegal_across_two_packages( | |
| self, start: str, end: str, route_middle: list[str] | ||
| ): | ||
| graph = self._build_legal_graph() | ||
| import_pairs = _pairwise([start] + route_middle + [end]) | ||
| import_pairs = _pairwise([start, *route_middle, end]) | ||
| for importer, imported in import_pairs: | ||
| graph.add_import(importer=importer, imported=imported) | ||
|
|
||
|
|
@@ -1104,12 +1104,12 @@ def _build_layers(self, layers: Iterable[Layer]): | |
| modules = [] | ||
| for layer in layers: | ||
| assert len(layer.module_tails) == 1 | ||
| module = list(layer.module_tails)[0] | ||
| module = next(iter(layer.module_tails)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stylistic (similar comment to before regarding unpackaging syntax) It's a slight performance hit to instantiate the list in full, so that's the motivation for this slightly less readable syntax. Perhaps should be disabled for the test suite |
||
| graph.add_module(module) | ||
| modules.append(module) | ||
|
|
||
| # Legal imports, from higher layer to immediate lower layer | ||
| for higher_module, lower_module in zip(modules[:-1], modules[1:]): | ||
| for higher_module, lower_module in itertools.pairwise(modules): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stylistic (similar comment to before regarding unpackaging syntax) I think this one is more readable |
||
| graph.add_import(importer=higher_module, imported=lower_module) | ||
|
|
||
| return graph | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -730,13 +730,6 @@ def my_function(): | |
| ("import namespace.foo.green.alpha.one", "namespace.foo.green"), | ||
| ("from namespace.foo.green.alpha import one", "namespace.foo.green"), | ||
| ("from ..green.alpha import one", "namespace.foo.green"), | ||
| ("from .. import green", "namespace.foo.green"), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These parametrizations are duplicated. |
||
| ("import namespace.foo.green.alpha", "namespace.foo.green"), | ||
| ("from namespace.foo.green import alpha", "namespace.foo.green"), | ||
| ("from ..green import alpha", "namespace.foo.green"), | ||
| ("import namespace.foo.green.alpha.one", "namespace.foo.green"), | ||
| ("from namespace.foo.green.alpha import one", "namespace.foo.green"), | ||
| ("from ..green.alpha import one", "namespace.foo.green"), | ||
| ), | ||
| ) | ||
| def test_external_package_imports_for_namespace_packages(statement, expected_module_name): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sorting
__all__alphabetically