pypa / pypa/setuptools

[BUG] dynamic attr fails if attribute name turns out to be empty string

Open
#3,928 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Needs Triage
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

setuptools version

current

Python version

3.11

OS

linux

Additional environment information

No response

Description

migrating setuptools_scm to a better config setup,
i misstyed the attr


[build-system]
build-backend = "_own_version_helper"
backend-path = ["."]
requires = [
  "setuptools",
]

[tool.setuptools.dynamic]
version = { attr = "_own_version_helper."} 

resulted in

         ...
        File "/home/ronny/Projects/pypa/setuptools_scm/_own_version_helper.py", line 63, in __getattr__
          raise AttributeError(name)
      AttributeError
Expected behavior

raising a error about the empty attribute name teling where its from

How to Reproduce
gh repo clone RonnyPfannschmidt/reproduce-setuptools-dynamic-attrgh repo clone RonnyPfannschmidt/reproduce-setuptools-dynamic-attr 
cd reproduce-setuptools-dynamic-attr
virtualenv venv
. venv/bin/activate
pip install build
python -m build 

### Output

```console
 $  python -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools)
* Getting build dependencies for sdist...
/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py:66: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
  config = read_configuration(filepath, True, ignore_option_errors, dist)
No `packages` or `py_modules` configuration, performing automatic discovery.
`flat-layout` detected -- analysing .
discovered packages -- []
discovered py_modules -- []
Traceback (most recent call last):
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/expand.py", line 81, in __getattr__
    return next(
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/expand.py", line 191, in read_attr
    return getattr(StaticModule(module_name, spec), attr_name)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/expand.py", line 87, in __getattr__
    raise AttributeError(f"{self.name} has no attribute {attr}") from e
AttributeError: _own_version_helper has no attribute 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ronny/Projects/pypa/reproduce-setuptools-dynamic-attr/venv/lib/python3.8/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
  File "/home/ronny/Projects/pypa/reproduce-setuptools-dynamic-attr/venv/lib/python3.8/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/home/ronny/Projects/pypa/reproduce-setuptools-dynamic-attr/venv/lib/python3.8/site-packages/pyproject_hooks/_in_process/_in_process.py", line 287, in get_requires_for_build_sdist
    return hook(config_settings)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/build_meta.py", line 344, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/__init__.py", line 107, in setup
    return distutils.core.setup(**attrs)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/_distutils/core.py", line 159, in setup
    dist.parse_config_files()
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/dist.py", line 908, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 66, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 143, in read_configuration
    return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 198, in expand_configuration
    return _ConfigExpander(config, root_dir, ignore_option_errors, dist).expand()
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 246, in expand
    self._expand_all_dynamic(dist, package_dir)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 291, in _expand_all_dynamic
    version=self._obtain_version(dist, package_dir),
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 340, in _obtain_version
    return _expand.version(self._obtain(dist, "version", package_dir))
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 329, in _obtain
    return self._expand_directive(
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 323, in _expand_directive
    return _expand.read_attr(directive["attr"], package_dir, root_dir)
  File "/tmp/build-env-cdmwgvcc/lib64/python3.8/site-packages/setuptools/config/expand.py", line 195, in read_attr
    return getattr(module, attr_name)
  File "/home/ronny/Projects/pypa/reproduce-setuptools-dynamic-attr/_own_version_helper.py", line 14, in __getattr__
    raise AttributeError(name)
AttributeError

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in setuptools/config/expand.py, especially read_attr and StaticModule, using the traceback as the entry point. Run python -m build in the linked reproduction setup to confirm the empty attribute case. Done means the failure reports the empty attribute name and its source instead of raising a bare AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.