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