diff options
Diffstat (limited to 'setuptools/_distutils/dist.py')
-rw-r--r-- | setuptools/_distutils/dist.py | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/setuptools/_distutils/dist.py b/setuptools/_distutils/dist.py index 0406ab19..1dc25fe5 100644 --- a/setuptools/_distutils/dist.py +++ b/setuptools/_distutils/dist.py @@ -7,6 +7,8 @@ being built/installed/distributed. import sys import os import re +import pathlib +import contextlib from email import message_from_file try: @@ -322,47 +324,40 @@ Common commands: (see '--help-commands' for more) should be parsed. The filenames returned are guaranteed to exist (modulo nasty race conditions). - There are three possible config files: distutils.cfg in the - Distutils installation directory (ie. where the top-level - Distutils __inst__.py file lives), a file in the user's home - directory named .pydistutils.cfg on Unix and pydistutils.cfg - on Windows/Mac; and setup.cfg in the current directory. - - The file in the user's home directory can be disabled with the - --no-user-cfg option. + There are multiple possible config files: + - distutils.cfg in the Distutils installation directory (i.e. + where the top-level Distutils __inst__.py file lives) + - a file in the user's home directory named .pydistutils.cfg + on Unix and pydistutils.cfg on Windows/Mac; may be disabled + with the ``--no-user-cfg`` option + - setup.cfg in the current directory + - a file named by an environment variable """ - files = [] check_environ() + files = [str(path) for path in self._gen_paths() if path.is_file()] - # Where to look for the system-wide Distutils config file - sys_dir = os.path.dirname(sys.modules['distutils'].__file__) + if DEBUG: + self.announce("using config files: %s" % ', '.join(files)) - # Look for the system config file - sys_file = os.path.join(sys_dir, "distutils.cfg") - if os.path.isfile(sys_file): - files.append(sys_file) + return files - # What to call the per-user config file - if os.name == 'posix': - user_filename = ".pydistutils.cfg" - else: - user_filename = "pydistutils.cfg" + def _gen_paths(self): + # The system-wide Distutils config file + sys_dir = pathlib.Path(sys.modules['distutils'].__file__).parent + yield sys_dir / "distutils.cfg" - # And look for the user config file + # The per-user config file + prefix = '.' * (os.name == 'posix') + filename = prefix + 'pydistutils.cfg' if self.want_user_cfg: - user_file = os.path.join(os.path.expanduser('~'), user_filename) - if os.path.isfile(user_file): - files.append(user_file) + yield pathlib.Path('~').expanduser() / filename # All platforms support local setup.cfg - local_file = "setup.cfg" - if os.path.isfile(local_file): - files.append(local_file) + yield pathlib.Path('setup.cfg') - if DEBUG: - self.announce("using config files: %s" % ', '.join(files)) - - return files + # Additional config indicated in the environment + with contextlib.suppress(TypeError): + yield pathlib.Path(os.getenv("DIST_EXTRA_CONFIG")) def parse_config_files(self, filenames=None): # noqa: C901 from configparser import ConfigParser |