Skip to content

Misleading error message #131785

@MarcoCaspers

Description

@MarcoCaspers

Bug report

Bug description:

The problem is not with Python itself, but rather with the build tool.

Name: build
Version: 1.2.2.post1
Location: /proj/python/build_bug_poc/.venv/lib/python3.10/site-packages
Requires: packaging, pyproject-hooks, tomli
Required-by:

The misleading fact lies in the error message itself:

ModuleNotFoundError: No module named 'build_bug_poc'
ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist

Especially if you read this near the start of the messages:

discovered packages -- ['build_bug_poc', 'build_bug_poc.config']

It can find the module "build_bug_poc" just fine.

The actual problem is an error inside the pyproject.toml file:

[tool.setuptools.dynamic]
version = {attr = "build_bug_poc.__about__.__version__"}

The error is the location of the about.py file.

The correct value would have been:

[tool.setuptools.dynamic]
version = {attr = "build_bug_poc.config.__about__.__version__"}

The error message itself is not even close to pointing out what the problem is.

It should have beem something like this:

Error in pyproject.toml: File in dynamic version not found: src/build_bug_poc/__about__.py

An error message similar to that would have saved a lot of time and effort trying to figure out this small error.
If you consider that the actual project contains hundreds of files in dozens of directories and the Pyproject.toml file being significantly more complex than what i used here for showcasing the problem.


consider this project directory:
.../build_bug_poc
pyprojec.toml
/src
/build_bug_poc
main.py
/config
about.py

The Python files can be empty, it has nothing to do with the actual contents of the project.

The error message on build:

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

pyproject.toml contains the following:

[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__"}

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions