Skip to content

Conversation

felixfontein
Copy link
Collaborator

@felixfontein felixfontein commented Mar 16, 2025

This is currently blocked by pylint-dev/pylint#10278.

@gotmax23
Copy link
Collaborator

Does the error happen in a clean venv or only when the ansible package that provides ansible_collections in site packages is also installed?

@felixfontein
Copy link
Collaborator Author

The error happens in the venv created by nox. There's ansible-core in there, but not ansible. What's worse, sometimes it happens, sometimes it does not.

I do need to use the rsync way to reproduce it though: https://github.com/ansible-community/antsibull-nox/pull/1/files#diff-998a45901c6eeed5c113b8b118eecc0a55676298af65200193c383975fd33fadR372 (or a copy). With the symlinks (that's commented in right now) there are other errors (No name 'dns' in module 'ansible_collections.community').

@felixfontein
Copy link
Collaborator Author

After some trial and error I found out that I don't really need the __init__.py in the collection's root, so everything's fine. (It took me some time to notice that the reason that mypy didn't find most of the intentional typing errors I introduced is because they happen in functions without a type signature - and these are ignored 🤦.)

I'm currently polishing the PR and will push something soon.

@felixfontein
Copy link
Collaborator Author

Meh, for whatever reason this seems to be hitting pylint-dev/pylint#5832...

@felixfontein
Copy link
Collaborator Author

I also created wntrblm/nox#943 since for some reason nox runs the linting with Python 3.11 instead of 3.13.

@gotmax23
Copy link
Collaborator

I also created wntrblm/nox#943 since for some reason nox runs the linting with Python 3.11 instead of 3.13.

The way the nox actions selects Python versions is kind of wonky. Might be better to just use setup-python to install Python and then pipx or uv to run nox.

@felixfontein
Copy link
Collaborator Author

Yep, with Python 3.13 the pylint bug is gone...

@felixfontein felixfontein marked this pull request as ready for review March 18, 2025 20:41
@gotmax23 gotmax23 self-requested a review March 18, 2025 20:52
for namespace in root.iterdir():
try:
if namespace.is_dir() or namespace.is_symlink():
for name in root.iterdir():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this supposed to iterate through root a second time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely not ;-)

(And yes, we really need tests...)

copier.copy(collection.path, path, exclude_root=[".nox", ".tox"])


def _copy_collection_rsync_hard_links(collection: CollectionData, path: Path) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now no, but I'm thinking about offering this (or a variant of it) as an option in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also potentially implement this functionality as a separate Copier in antsibull_fileutils.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Totally, yes.

@@ -52,8 +62,56 @@ def install(session: nox.Session, *args: str, editable: bool = False, **kwargs):
session.install(*args, "-U", **kwargs)


@dataclass
class CollectionSetup:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you document what each of these attributes are? It's not immediately clear based on the names.

@gotmax23
Copy link
Collaborator

gotmax23 commented Mar 18, 2025

Another thing, it would be nice if something like this where dependencies are also installed in the flat structure was supported:

gh repo clone ansible-collections/community.internal_test_tools
gh repo clone ansible-collections/community.dns
cd community.dns
nox

@felixfontein
Copy link
Collaborator Author

felixfontein commented Mar 18, 2025

Another thing, it would be nice if something like this where dependencies are also installed in the flat structure was supported:

gh repo clone ansible-collections/community.internal_test_tools
gh repo clone ansible-collections/community.dns
cd community.dns
nox

I think your cd is missing a ansible-collections/ ;-) (Edit: misread something.) But yeah, that would be nice indeed, and should be pretty simple to add. (Edit: created #6)

Copy link
Collaborator

@gotmax23 gotmax23 left a comment

Choose a reason for hiding this comment

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

Other than the exception handling, this looks good to me

name=name.name,
root=root,
)
except: # noqa: E722, pylint: disable=bare-except
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except: # noqa: E722, pylint: disable=bare-except
except Exception:

at least, otherwise, this will catch KeyboardInterrupt and such. Or should this only catch ValueError because _load_collection_data_from_disk doesn't (directly) raise anything else?

(This also applies to the other callers of _load_collection_from_disk)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should also catch I/O errors if someone did something strange in that directory structure so that some other call fails.

copier.copy(collection.path, path, exclude_root=[".nox", ".tox"])


def _copy_collection_rsync_hard_links(collection: CollectionData, path: Path) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also potentially implement this functionality as a separate Copier in antsibull_fileutils.

@gotmax23
Copy link
Collaborator

I think your cd is missing a ansible-collections/ ;-) But yeah, that would be nice indeed, and should be pretty simple to add.

Doesn't this code allow checking out collections without a parent ansible_collections directory?

@felixfontein
Copy link
Collaborator Author

Yes, I only misread something.

@felixfontein felixfontein merged commit bbaa662 into ansible-community:main Mar 21, 2025
2 checks passed
@felixfontein
Copy link
Collaborator Author

Thanks for reviewing this, @gotmax23!

@felixfontein felixfontein deleted the improve-pylint-mypy branch March 21, 2025 21:45
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