diff options
author | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2020-12-31 17:58:45 +0100 |
---|---|---|
committer | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2020-12-31 18:38:49 +0100 |
commit | 08984781ec38f9ba8b35c70c6a5fff38e00b55aa (patch) | |
tree | 177b30ae86c56a1591a4e63b88b1e2e27530e84b | |
parent | 28b54b140cee8b33748833372ca6dbd7e305d94d (diff) | |
download | python-setuptools-git-08984781ec38f9ba8b35c70c6a5fff38e00b55aa.tar.gz |
Simplify `dist.Distribution._parse_config_files`
-rw-r--r-- | setuptools/dist.py | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 2c088ef8..186a407c 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -557,14 +557,12 @@ class Distribution(_Distribution): from configparser import ConfigParser # Ignore install directory options if we have a venv - if sys.prefix != sys.base_prefix: - ignore_options = [ - 'install-base', 'install-platbase', 'install-lib', - 'install-platlib', 'install-purelib', 'install-headers', - 'install-scripts', 'install-data', 'prefix', 'exec-prefix', - 'home', 'user', 'root'] - else: - ignore_options = [] + ignore_options = [] if sys.prefix == sys.base_prefix else [ + 'install-base', 'install-platbase', 'install-lib', + 'install-platlib', 'install-purelib', 'install-headers', + 'install-scripts', 'install-data', 'prefix', 'exec-prefix', + 'home', 'user', 'root', + ] ignore_options = frozenset(ignore_options) @@ -585,30 +583,34 @@ class Distribution(_Distribution): opt_dict = self.get_option_dict(section) for opt in options: - if opt != '__name__' and opt not in ignore_options: - val = parser.get(section, opt) - opt = opt.replace('-', '_') - opt_dict[opt] = (filename, val) + if opt == '__name__' or opt in ignore_options: + continue + + val = parser.get(section, opt) + opt = opt.replace('-', '_') + opt_dict[opt] = (filename, val) # Make the ConfigParser forget everything (so we retain # the original filenames that options come from) parser.__init__() + if 'global' not in self.command_options: + return + # If there was a "global" section in the config file, use it # to set Distribution options. - if 'global' in self.command_options: - for (opt, (src, val)) in self.command_options['global'].items(): - alias = self.negative_opt.get(opt) - try: - if alias: - setattr(self, alias, not strtobool(val)) - elif opt in ('verbose', 'dry_run'): # ugh! - setattr(self, opt, strtobool(val)) - else: - setattr(self, opt, val) - except ValueError as e: - raise DistutilsOptionError(e) from e + for (opt, (src, val)) in self.command_options['global'].items(): + alias = self.negative_opt.get(opt) + if alias: + val = not strtobool(val) + elif opt in ('verbose', 'dry_run'): # ugh! + val = strtobool(val) + + try: + setattr(self, alias or opt, val) + except ValueError as e: + raise DistutilsOptionError(e) from e def _set_command_options(self, command_obj, option_dict=None): """ |