-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[BUG] attr: not working in version field of setup.cfg #3266
Comments
Hi @solsword, thank you very much for reporting this. I think the main problem is the following: [options]
python_requires = >=3.7
provides = pkg
- py_modules = pkg
+ packages = pkg
What would be your suggestion? |
Thanks for the quick response! I actually just figured this out myself as well, and indeed, that was the issue. Something that would have helped me in this case is some kind of error or warning message when py_modules and/or py_packages is used incorrectly! The ultimate cause of the It's actually good that the build crashes in a way because it indicates that the source distribution is missing something important! But googling the specific error message that I got led me down the wrong rabbit-hole. Sorry for the mostly-spurious bug here! I'm not closing because I think some kind of error or warning about the mis-use of py_modules vs. pacakges would be helpful. This error came about because unsurprisingly I forget a lot of config details between starting new projects, and I copied over a config from a single-file project into my pacakge-based project. Note that if you try to set Looking into the code, in at least one place (line 278 of _distutils/command/build_py.py) the code says:
so there is code to check that a module exists, but if it doesn't, we ignore that fact (the parallel code for packages prints the error I just mentioned). Maybe that line could print a warning at least? The comment implies that there might be a .pyc file which could have been the motivation for ignoring missing .py files? |
That makes some sense to me... With packages that is very clear right? Even if you have a I don't know exactly how to proceed here, but it seems that this issue involves changes in https://github.com/pypa/distutils... would you like to give it a go and propose a PR there? |
Hmmm. That repo says that it's a shadow of the builtin distutils which are scheduled for removal, presumably in favor of setuptools... So I feel like even if they were receptive to adding code to generate a warning, and even if that got ported to Python core, it would eventually be phased out and replaced by the code in this package? But maybe I'm misunderstanding the status of this repo, that one, and the Python built-in code itself. Their README does say (about synchronizing with setuptools): Simply merge the changes directly into setuptools' repo. So if the version of build_py.py which is going to be used once distutils is removed from the python stdlib is the one in _distutils inside of setuptools, this seems like the place to make the change? |
There is always a chance the maintainers in The workflow setuptools use is to constantly merge the changes from |
Okay that makes perfect sense to me. I'll file a request over there and reference this; I'll mark this as closed now since further work belongs there. |
setuptools version
62.1.0
Python version
3.10.2
OS
macOS
Additional environment information
I get the same error in each of:
My Python versions 3.9 and 3.10 were installed using homebrew, and 3.7.9 comes with Thonny.
Description
I'm trying to build a basic package and maintain a version number in one place, using declarative
setup.cfg
and building withpython -m build
. I'm following option #1 from this guide:https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
Which also corresponds with the example provided at the top of this page:
https://setuptools.pypa.io/en/latest/userguide/declarative_config.html
I've looked at issues like:
But I'm not using a namespace package and I'm not using any imports (see file contents below). Essentially, even if the package JUST has
version: attr:mypackage.__version__
, the build fails. Interestingly, it's able to create the egg info directory, and picks up the package version correctly there, but fails with aModuleNotFoundError
at a later step. The full log is included at the end of this report.I can confirm that with at least the 3.9.10 Python and setuptools 62.0.0, this issue does NOT occur if the package is provided as a single file rather than as a directory with an
__init__.py
file. Perhaps the bug is as simple as a code path in the AST parsing branch (which we seem to be triggering) that isn't checking for that and assumesmypackage.__version__
could only be found inmypackage.py
? I have tried usingattr:mypackage.__init__.__version__
but unsurprisingly that didn't work. I even tried putting the version number in a different filemypackage/_verison.py
and usingattr:mypackage._version.__version__
but that didn't work either.This seems similar to #2605, but I'm not getting the first error from that bug involving
NoneType
, and from the info in that bug, it seems like it might be related to #2919 if they're using namespace packages, which I'm not.Note: If it turns out I'm doing something I shouldn't be, it might be worth considering a docs update in one of the places I pointed to, since I feel like I'm following the documentation to the letter here.
Files used to reproduce (I also included the creation of these files in my reproduction steps):
pyproject.toml
:setup.cfg
:pkg.__init__.py
(just this one line, nothing else):Expected behavior
Creating a minimal package using
attr: my_project.__version__
inseutp.cfg
and building usingpython -m build
should work without errors, even if the package is a directory with an__init__.py
where the version variable is defined, especially if that__init__.py
doesn't have any other imports in it.How to Reproduce
These commands create the
pyproject.toml
,setup.cfg
andpkg/__init__.py
files described above and runpython -m build
:Output
The text was updated successfully, but these errors were encountered: