Skip to content

Commit

Permalink
Add DISTUTILS_EXTRA_CONFIG option for passing setup.cfg overrides dur…
Browse files Browse the repository at this point in the history
…ing build
  • Loading branch information
zooba committed Sep 1, 2022
1 parent 22b9bcf commit a6246aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions distutils/dist.py
Expand Up @@ -359,6 +359,10 @@ def find_config_files(self):
if os.path.isfile(local_file):
files.append(local_file)

extra_file = os.getenv("DISTUTILS_EXTRA_CONFIG")
if extra_file and os.path.isfile(extra_file):
files.append(extra_file)

if DEBUG:
self.announce("using config files: %s" % ', '.join(files))

Expand Down
21 changes: 21 additions & 0 deletions distutils/tests/test_dist.py
Expand Up @@ -492,6 +492,27 @@ def test_custom_pydistutils(self):
finally:
os.remove(user_filename)

def test_extra_pydistutils(self):
# make sure pydistutils.cfg is found
extra_filename = "overrides.cfg"

temp_dir = self.mkdtemp()
extra_filename = os.path.join(temp_dir, extra_filename)
with open(extra_filename, 'w') as f:
f.write('.')

# Testing will have been going terribly if this was set, but preserve
# it anyway (so it goes terribly but *consistently*)
old_extra_filename = os.environ.get("DISTUTILS_EXTRA_CONFIG")
os.environ["DISTUTILS_EXTRA_CONFIG"] = extra_filename
try:
dist = Distribution()
files = dist.find_config_files()
assert user_filename in files
finally:
os.remove(user_filename)
os.environ["DISTUTILS_EXTRA_CONFIG"] = old_extra_filename

def test_fix_help_options(self):
help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
fancy_options = fix_help_options(help_tuples)
Expand Down
3 changes: 2 additions & 1 deletion docs/distutils/configfile.rst
Expand Up @@ -36,7 +36,8 @@ consequences:
:file:`setup.py`

* installers can override anything in :file:`setup.cfg` using the command-line
options to :file:`setup.py`
options to :file:`setup.py` or by pointing :envvar:`DISTUTILS_EXTRA_CONFIG`
to another configuration file

The basic syntax of the configuration file is simple:

Expand Down

0 comments on commit a6246aa

Please sign in to comment.