-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Revamp good practices #10206
Revamp good practices #10206
Conversation
No idea why there are test failures, but I’m going to assume you sort that out |
Note the PR should be against the
I don't think I agree with that. See Good Integration Practices — pytest documentation - however, they are still not really needed for the example, so I'd be fine with removing them.
From a quick look, they indeed don't look like they are related to your changes. They will probably go away when targetting the correct branch. |
I’m intimately familiar with that document:
(emphasis mine) and
|
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.
Unless the default import mode of pytest gets pep420 aware these are absolutely needed
@RonnyPfannschmidt please read the comment I made a few seconds before yours |
The files missing is a footgun, the failure modes i keep observing when people expand testsuites are a pain, it's simply horrendous to debug for less experienced developers So unless we fix the default import mode up im opposed to leaving them out |
Wait, so pytest doesn’t throw a simple clear error like
|
It can't know if it's a mistake or a fatal breakage in multiple ways |
So neither making it a package nor impormode are a viable fix in multiple cases of import missmatch errors |
So perhaps we should update the docs to at least add a note to that end? Because if we advertise to users that having or not having them is fine depending on the case, we should not be reluctant to remove the |
My personal preferences would be
|
Unfortunately we found that I'm OK with changing the good practices docs to mention it as an alternative approach (listing the benefits and drawbacks of each). |
Yeah, test suites relying on this misfeature* would break. If this was my personal project, I’d release a new major version with the change and tell people to do a) things this way and b) use *misfeature because now your tests rely on modifying
Alternative layoutThe Just define a subpackage with the same name as your main package.
Great, I’ll see if I can come up with something :D |
OK, I took a shot at updating
|
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.
Thanks @flying-sheep for the follow up.
Left a few comments, please take a look.
and a ``setup.cfg`` file containing your package's metadata with the following minimum content: | ||
|
||
.. code-block:: ini | ||
requires = ["hatchling"] |
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.
I personally prefer that we use setuptools
in our examples, because it is more traditional; using alternatives might give the impression that pytest recommends/only works with hatchling, or support requests on how to do the same with poetry, etc.
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.
hmm, maybe we can also use tabs like in the packaging tutorial?
I don’t recommend setuptools as it’s:
- slow
- messy (leaves a .egg-info folder lying around in your workspace, emits a bunch of unnecessary log messages during build)
- hard to configure (a bunch of legacy config files like MANIFEST.in, and misleadingly named config keys)
- no longer the first choice on the packaging tutorial
but of course I can leave it if you prefer. I’d still get rid of setup.cfg
since setuptools these days supports PEP 621. Unfortunately configuring it with more than just basic metadata is labelled as “beta”, e.g. this:
[tool.setuptools.packages.find]
where = ["src"] # ["."] by default
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.
no longer the first choice on the packaging tutorial
Ahh thanks for pointing that out, didn't know that has changed. If the packaging tutorial recommends hatchling
as first choice, I think we should follow suit then.
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.
In case you would like some context, I followed that discussion, and the reasoning went something like that:
- we don’t want to promote any standards following build backend above all others
- so we use tabs
- but since the first (auto-selected) tab is kind of an endorsement, we need something there that is good for the vast majority of people, i.e. ideal for pure python packages
- because of the above mentioned drawbacks of setuptools, the first tab will be hatchling, because it provides a better experience for people creating a pure python package than setuptools, has a plugin to use setuptool-scm for versioning (
hatch-vcs
)
Hatchling doesn’t have a sufficient amount of plugins or example code yet to allow a highly custom build like numpy or numba or so, but for anything with purely static build configuration, it’s a very good choice.
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Thanks @flying-sheep! |
Anybody else wants to review this? Otherwise I plan to merge this tomorrow. |
Thanks again @flying-sheep! |
* Recommend importlib import mode for new projects * Recommend src layout more strongly * Switch to hatchling as the packaging tool in the example (following PyPA) * Add explanation about the different import modes (cherry picked from commit 245a8c2)
Revamp good practices (#10206)
The importlib import mode has no* drawbacks while the default mode
prepend
has a major footgun. That one has one popular workaround which in turn has further drawbacks.Also one of the sections correctly says “subfolder”, but others misleadingly say “subpackage”. Should I get rid of that too?
*I consider the fact that you can’t import from test files a feature, as it cleans up the distinction between test files and python packages. It encourages to keep your test utils in one location and reduces dependencies between test files.