Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Options declared in setup.cfg can not override options declared in setup() function #4800

Open
gaokai320 opened this issue Jan 13, 2025 · 0 comments
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@gaokai320
Copy link

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

  1. create a ``setup.cfg` file with the following content
[options]
include_package_data = False
install_requires =
    requests
  1. 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

@gaokai320 gaokai320 added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

No branches or pull requests

1 participant