You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[project]
name = "build-bug-poc"dynamic = ["version"]
description = "Add your description here"readme = "README.md"requires-python = ">=3.10"dependencies = []
[tool.setuptools.dynamic]
version = {attr = "build_bug_poc.__about__.__version__"}
Description
Python 3.10.12
Upon building this project the build fails with this exception error:
ModuleNotFoundError: No module named 'build_bug_poc'
ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist
This is clearly false, as several lines before going into the crash it shows this information:
discovered packages -- ['build_bug_poc', 'build_bug_poc.config'] so it's detecting things just fine.
Expected behavior
I expect an error message saying that there is a problem in pyproject.toml, specifically that the file "about.py" isn't found in the location defined.
i.e. a file not found error rather than a module not found, and with the correct name about instead of "buid_bug_poc".
How to Reproduce
with this pyproject.toml issue python3 -m build and it'll crash with the error.
Output
python3 -m build --verbose
* Creating isolated environment: venv+pip...
> /tmp/build-env-u65zu66r/bin/python -Im pip uninstall -y setuptools
< Found existing installation: setuptools 59.6.0
< Uninstalling setuptools-59.6.0:
< Successfully uninstalled setuptools-59.6.0
* Installing packages in isolated environment:
- setuptools >= 40.8.0
> /tmp/build-env-u65zu66r/bin/python -Im pip install --use-pep517 --no-warn-script-location --no-compile -r
/tmp/build-reqs-wt42rltx.txt
< Collecting setuptools>=40.8.0
< Using cached setuptools-78.1.0-py3-none-any.whl (1.3 MB)
< Installing collected packages: setuptools
< Successfully installed setuptools-78.1.0
* Getting build dependencies for sdist...
No `packages` or `py_modules` configuration, performing automatic discovery.
`src-layout` detected -- analysing ./src
discovered packages -- ['build_bug_poc', 'build_bug_poc.config']
discovered py_modules -- []
Traceback (most recent call last):
File "/proj/python/build_bug_poc/.venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in<module>main()
File "/proj/python/build_bug_poc/.venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
File "/proj/python/build_bug_poc/.venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 317, in get_requires_for_build_sdist
return hook(config_settings)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/build_meta.py", line 337, in get_requires_for_build_sdist
return self._get_build_requires(config_settings, requirements=[])
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
self.run_setup()
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/build_meta.py", line 522, in run_setup
super().run_setup(setup_script=setup_script)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in run_setup
exec(code, locals())
File "<string>", line 1, in<module>
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/__init__.py", line 117, in setup
return distutils.core.setup(**attrs)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 160, in setup
dist.parse_config_files()
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/dist.py", line 756, in parse_config_files
pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 72, in apply_configuration
config = read_configuration(filepath, True, ignore_option_errors, dist)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 144, in read_configuration
return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 169, in expand_configuration
return _ConfigExpander(config, root_dir, ignore_option_errors, dist).expand()
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 217, in expand
self._expand_all_dynamic(dist, package_dir)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 262, in _expand_all_dynamic
version=self._obtain_version(dist, package_dir),
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 313, in _obtain_version
self._obtain(dist, "version", package_dir) # pyright: ignore[reportArgumentType]
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 300, in _obtain
return self._expand_directive(
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 294, in _expand_directive
return _expand.read_attr(directive["attr"], package_dir, root_dir)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/expand.py", line 182, in read_attr
spec = _find_spec(module_name, path)
File "/tmp/build-env-u65zu66r/lib/python3.10/site-packages/setuptools/config/expand.py", line 196, in _find_spec
spec = spec or importlib.util.find_spec(module_name)
File "/usr/lib/python3.10/importlib/util.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'build_bug_poc'
ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist
The text was updated successfully, but these errors were encountered:
Thanks @MarcoCaspers. Would you like to submit a PR with a fix for that?
What probably happens is that when setuptools does not find build_bug_poc.__about__ it falls back to simply trying to import it. But Python's stdlib does not know how to handle it because the project folder is not added to sys.path (you would need to do that in a setup.py file1). In a sense, the exception message is not misleading, it is only describing the situation from Python's import machinery point of view. Because I cannot think right now on a better of handling this I will rely on a fix to be provided by the community.
Finally I slightly disagree with the suggestion of "file not found error rather than a module not found". The documentation describes attr as trying to read an attribute from a module. It is only natural to have a "module not found" if the module cannot be found. If we were talking about the file directive, that would be a different story...
Footnotes
Adding the project root to sys.path automatically is not an option. This detail was intentionally changed during the adoption of PEP 517 because it was deemed problematic. ↩
setuptools version
setuptools==78.1.0
Python version
Python 3.10.12
OS
Linux, Ubuntu 22.04.5 LTS
Additional environment information
Path info:
.../build_bug_poc
pyprojec.toml
/src
/build_bug_poc
main.py
/config
about.py
pyproject.toml contains the following:
Description
Python 3.10.12
Upon building this project the build fails with this exception error:
ModuleNotFoundError: No module named 'build_bug_poc'
ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist
This is clearly false, as several lines before going into the crash it shows this information:
discovered packages -- ['build_bug_poc', 'build_bug_poc.config'] so it's detecting things just fine.
Expected behavior
I expect an error message saying that there is a problem in pyproject.toml, specifically that the file "about.py" isn't found in the location defined.
i.e. a file not found error rather than a module not found, and with the correct name about instead of "buid_bug_poc".
How to Reproduce
with this pyproject.toml issue python3 -m build and it'll crash with the error.
Output
The text was updated successfully, but these errors were encountered: