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

Document contributors convention to respect skeleton and distutils #4609

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

abravalheri
Copy link
Contributor

Summary of changes

I created these paragraphs based on the comment in #4212. The idea is to document to setuptools developers how the compat/pyXX convention works.

Closes

Pull Request Checklist

@abravalheri abravalheri marked this pull request as ready for review August 28, 2024 10:05
@Avasam
Copy link
Contributor

Avasam commented Aug 28, 2024

I have two questions. If these are implementation details, should the module be named _compat? And should it include _importlib.py which are just conditional imports based on Python version?

@abravalheri
Copy link
Contributor Author

Yes, I think they could be moved to _compat. @jaraco would that be OK?

Probably importlib is treated as a special case, the file used to be much more complex than it is nowadays.

@jaraco
Copy link
Member

jaraco commented Aug 29, 2024

Thanks for doing this!

I have two questions. If these are implementation details, should the module be named _compat?

I find the _ prefix for modules particularly abrasive. It looks like lint, like a typo. I don't want to be forced to add weird characters to modules. Especially because in many packages, all of the public interfaces are available from the top-level package, so everything else is de facto private. I'd much rather have simple, clean names like compat.

Presumably to address this concern, I've seen other projects put everything under a separate, top-level package (e.g. pytest [although even there, they have private packages below]) or move everything private into an underscore-prefixed private package (e.g. pip).

I've resisted these approaches because they add extra indirection and top-level names. I'd much rather be able to name modules with a clean, natural form and flag visibility using some orthogonal signal. Since the language doesn't provide a good orthogonal signal, I'm fine with documenting the expectation.

I do think downstream consumers should have an instinct to avoid using functionality from a package that's not part of the advertised interface. That is, I don't think users would be particularly tempted to use these modules.

In cases where the functionality might be valuable across more than a couple of projects, I've worked to expose those under jaraco.compat.

And should it include _importlib.py which are just conditional imports based on Python version?

In my opinion, yes. In fact, it might be worthwhile refactoring those imports into py39 and py310 modules, but it'd be fine to call it compat/importlib.py (or compat/_importlib.py) and use as-is. It would also be fine to leave it where it is. It's not crucial that a module go there, but if you find yourself creating a module called macos_compat, it should probably be compat.macos.

I also use this namespace for things unrelated to the Python version, such as keyring.compat.properties or zipp.compat.overlay. In the case of zipp.compat.overlay, I do expect it to be used by external consumers.

Yes, I think they could be moved to _compat. @jaraco would that be OK?

Yes, it would be okay, but then it will deviate from the convention I've followed in most other projects. IMO, it'd be better to keep it consistent across projects.

Document internal convention on compat modules

Thinking about this concept in general, I apply it across many projects, so it feels a little weird to document it here. It will be a little unsustainable to copy this documentation to each and every project that employs this approach. Better would be to have a blog entry or (even better) have documentation in a shared system (like skeleton or coherent) that can possibly be linked from Setuptools if needed.

What do you think about contributing this guidance instead to a "conventions" section in https://github.com/jaraco/skeleton/blob/gh-pages/index.md?

@jaraco
Copy link
Member

jaraco commented Aug 29, 2024

In cases where the functionality might be valuable across more than a couple of projects, I've worked to expose those under jaraco.compat.

The only reason I haven't added shims for importlib resources and importlib metadata to jaraco.compat is because there's no one-size-fits-all approach - each consumer can have different compatibility expectations. Although, it occurs to me that some package could present a compat.pyNNN.importlib.{resources,metadata} for each pertinent value of NNN. Maybe I'll explore that at some point.

@abravalheri abravalheri changed the title Document internal convention on compat modules Document contributors convention to respect skeleton and distutils Aug 29, 2024
@abravalheri
Copy link
Contributor Author

Thank you very much for the feedback @jaraco, I have extracted the "compat" docs into jaraco/skeleton#145.

I have also repurposed this PR to talk about how setuptools uses skeleton and that setuptools/_distutils should not be changed directly.

@abravalheri abravalheri merged commit 99a4927 into pypa:main Aug 29, 2024
23 checks passed
@abravalheri abravalheri deleted the doc-compat branch August 29, 2024 15:50
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.

3 participants