Skip to content

Conversation

@nathanjmcdougall
Copy link
Contributor

@nathanjmcdougall nathanjmcdougall commented Dec 17, 2025

Another testing the waters sort of thing, I'm wanting to make sure:

  • this is the right size PR in terms of reviewability (e.g. too many rules in one PR)?
  • you're happy with the tweaks & rules themselves

I've included rulesets which are relatively uncontroversial (thus mostly already complied with) and have autofixes enabled. I've ignored specific rules which are too controversial.

To access autofixes with ruff check . --fix, I wonder whether it would be helpful to configure Just to run Ruff with --fix, if not by default then at least with opt-in for specific use cases, e.g. for within pre-commit.

"DirectImport",
"Import",
"ImportGraph",
"Layer",
Copy link
Contributor Author

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

tails=frozenset(
{
"mypackage.application.7537183614.6928774480.5676105139.3275676604"
# noqa:E501
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

components = [package_name] + internal_filename_and_path_without_extension.split(
self.file_system.sep
)
components = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

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.")):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match= arguments are regex (which is easy to forget), so characters like . have special meaning. This can lead to subtle bugs. Better to explicitly escape the string.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistic (similar comment to before regarding unpackaging syntax)

for layer in layers:
assert len(layer.module_tails) == 1
module = list(layer.module_tails)[0]
module = next(iter(layer.module_tails))
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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


# 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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

("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"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parametrizations are duplicated.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 17, 2025

CodSpeed Performance Report

Merging #284 will not alter performance

Comparing nathanjmcdougall:refactor/enable-various-ruff-rulesets (a0c0912) with main (90e6ccb)

Summary

✅ 26 untouched
⏩ 23 skipped1

Footnotes

  1. 23 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@seddonym seddonym self-requested a review December 17, 2025 12:30
Copy link
Collaborator

@seddonym seddonym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

For auto-generated changes it's fine to bundle them all up together into a commit, as you have done. I am likely to side with ruff on pretty much everything. If you want to turn on an even stricter mode I can review all in one go if you like.

To access autofixes with ruff check . --fix, I wonder whether it would be helpful to configure Just to run Ruff with --fix, if not by default then at least with opt-in for specific use cases, e.g. for within pre-commit

Maybe - feel free to put together a demo PR. At the moment you can do just autofix-python.

@seddonym seddonym merged commit 5899ee0 into python-grimp:main Dec 17, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants