Skip to content
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

feat: check for both path/foo.py and path/foo/__init__.py being present #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GabDug
Copy link

@GabDug GabDug commented Mar 27, 2024

Hey 👋

Quick MR to close #19

As it's my first contribution here, I'm happy to take any feedback, especially around the wording of the rule.

I've included a wheel for E2E testing, but will try to add more tests if needed.

Thanks,
Gabriel

Copy link
Owner

@jwodder jwodder left a comment

Choose a reason for hiding this comment

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

You also need to add a section to the README describing the new check, when it fails, why it's a problem, and/or how to fix it.

Copy link
Owner

Choose a reason for hiding this comment

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

Testing with actual wheels is only for special cases, and there generally isn't a need to add more test wheels at this time. Instead, the new check should be tested with a test function in test/test_checking.py that just operates on lists of filepaths; cf. the tests already in that file and the "Adding a New Check" section of CONTRIBUTING.md.

Please remove this wheel from your PR's history before requesting a re-review.

@@ -23,6 +23,7 @@ class Check(Enum):
W008 = "Wheel is empty"
W009 = "Wheel contains multiple toplevel library entries"
W010 = "Toplevel library directory contains no Python modules"
W011 = "Wheel contains module and submodule with the same name"
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
W011 = "Wheel contains module and submodule with the same name"
W011 = "Wheel contains module and package with the same basename"

for name, entry in tree.entries.items():
if isinstance(entry, Directory):
if tree.files.get(name + ".py") is not None:
conflicts.append(entry.path or name)
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of returning a single failed check that just contains the conflicting directory paths, I feel you should instead return one FailedCheck for each foo.py + foo/__init__.py pair, and the FailedCheck should contains both of those paths.

Cf. the following paragraph from "Adding a New Check" in CONTRIBUTING.md:

Generally, a check method should return at most one FailedCheck containing all of the failing filepaths; only return multiple FailedChecks if the check applies to groups of files. For example, W002 ("Wheel contains duplicate files") returns a separate FailedCheck for each group of equal files.

Comment on lines +311 to +312
for name, entry in tree.entries.items():
if isinstance(entry, Directory):
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
for name, entry in tree.entries.items():
if isinstance(entry, Directory):
for name, entry in tree.subdirectories.items():

for name, entry in tree.entries.items():
if isinstance(entry, Directory):
if tree.files.get(name + ".py") is not None:
conflicts.append(entry.path or name)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
conflicts.append(entry.path or name)
# `entry` exists within a directory and thus is not the root directory, and so it has a path.
assert entry.path is not None
conflicts.append(entry.path)

check_dir(entry)

for tree in (contents.purelib_tree, contents.platlib_tree):
if isinstance(tree, Directory):
Copy link
Owner

Choose a reason for hiding this comment

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

This line is redundant; contents.purelib_tree and contents.platlib_tree are always Directorys.

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.

Add a check for both path/foo.py and path/foo/__init__.py being present
2 participants