Reputation: 615
As the title states, I am getting this ERROR when I run python -m build
locally using a version file. I have read the PEP 440 and to me, it appears compliant. I cannot see from the documentation on setuptools why I would be running into this issue
I would really appreciate some help on this since I don't see how I am able to run a debugger on python -m build
or get some more understanding of specifically why the _parse_version
of setuptools/config.py
is unhappy with my version file.
More details:
I have a project structured as follows:
src/
mypackage/
__init__.py
VERSION
pyproject.toml
setup.cfg
setup.py
VERSION
0.0.1
setup.cfg
name = mypackage
version = file: src/mypackage/VERSION
# etc. etc. etc.
setup.py
#!/usr/bin/env python
# Used to create editable installs
import setuptools
setuptools.setup()
pyproject.toml
[build-system]
# Minimum requirements for the build system to execute.
requires = [
"setuptools>=42",
"wheel"] # PEP 508 specifications.
build-backend = "setuptools.build_meta"
More detail on the error:
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/build_meta.py", line 154, in get_requires_for_build_wheel
return self._get_build_requires(
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires
self.run_setup()
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 5, in <module>
setuptools.setup()
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.8/distutils/core.py", line 121, in setup
dist.parse_config_files()
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/_virtualenv.py", line 21, in parse_config_files
result = old_parse_config_files(self, *args, **kwargs)
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/dist.py", line 778, in parse_config_files
parse_configuration(self, self.command_options,
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/config.py", line 157, in parse_configuration
meta.parse()
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/config.py", line 463, in parse
section_parser_method(section_options)
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/config.py", line 436, in parse_section
self[name] = value
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/config.py", line 220, in __setitem__
value = parser(value)
File "/tmp/build-env-2kboopyp/lib/python3.8/site-packages/setuptools/config.py", line 553, in _parse_version
raise DistutilsOptionError(tmpl.format(**locals()))
distutils.errors.DistutilsOptionError: Version loaded from file: src/mypackage/VERSION does not comply with PEP 440:
ERROR Backend subproccess exited when trying to invoke get_requires_for_build_wheel
Upvotes: 7
Views: 3875
Reputation: 615
I have solved this though I'm not happy with the current documentation or error messaging, as it stands I feel it's quite easy to fall into this trap.
So the solution was to create a MANIFEST.in
file with the line:
include src/mypackage/VERSION
at top level of my repo:
src/
mypackage/
__init__.py
VERSION
pyproject.toml
setup.cfg
setup.py
MANIFEST.in
Additionally, the following must be added to the setup.cfg
[options]
include_package_data = True
From docs:
include_package_data
If set to True, this tells setuptools to automatically include any data files it finds inside your package directories that are specified by your MANIFEST.in file. For more information, see the section on Including Data Files.
The setuptools documentation V57.1.0 had me believe it would be included:
Automatically include all relevant files in your source distributions, without needing to create a MANIFEST.in file, and without having to force regeneration of the MANIFEST file when your source tree changes.
And intuitively I would have thought a file:
key word with the path would be sufficient, or that the error message which as it turns out was produced because there was no such file, might have clued me in some more. This is also not apparent from the packaging-projects
But I suppose it can be inferred from the MANIFEST.in documentation.
I say all this since incase anyone has anything useful to add or counter reason my current feeling: that there might be an omission from the current guides regarding using a version file.
Upvotes: 5