[BUG] Options declared in `setup.cfg` can not override options declared in `setup()` function
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
setuptools version
setuptools==75.1.0
Python version
Python 3.12.2
OS
Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-51-generic x86_64)
Additional environment information
I use the Miniconda
Description
I am reading the source code of setuptools to understand how it works when building a Python project. I noticed there is a comment in the 158 line in setuptools/_distutils/core.py
Find and parse the config file(s): they will override options from the setup script, but be overridden by the command line.
It suggests that options declared in the setup.cfg file will override options declared in the setup() function. However, when looking at the code of ConfigHandler.__setitem__() in setuptools/config/setupcfg.py, I notice the following weird code:
try:
current_value = getattr(target_obj, option_name)
except AttributeError as e:
raise KeyError(option_name) from e
if current_value:
# Already inhabited. Skipping.
return
It seems that it will not override the options already declared in the setup() function
Expected behavior
If the comment is right, is the above code unnecessary?
How to Reproduce
- create a ``setup.cfg` file with the following content
[options]
include_package_data = False
install_requires =
requests
- open a terminal and type python and the following code
>>> from setuptools.dist import Distribution
>>> attrs = {"name": "test", "include_package_data": True, "install_requires": ["abc"]}
>>> dist = Distribution(attrs)
>>> dist.include_package_data, install_requires
(True, ['abc'])
>>> dist.parse_config_files(["setup.cfg"])
>>> dist.include_package_data, install_requires
(True, ['abc'])
According to the output, options in setup.cfg do not override options in setup(). Is it the correct or expected behavior?
Output
Please see the above section
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the comment near line 158 of setuptools/_distutils/core.py and ConfigHandler.setitem() in setuptools/config/setupcfg.py. Reproduce the behavior with Distribution(attrs) and parse_config_files(["setup.cfg"]) using the provided values, then compare the observed precedence with the documented expectation. Done means the precedence behavior is clarified or corrected and covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100