From d1bea1b94583a4e581739a9cb8365a8177781134 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 17 Jun 2024 13:23:12 -0400 Subject: [PATCH] Use actual boolean parameters and variables (#4365) Co-authored-by: Anderson Bravalheri --- newsfragments/4365.misc.rst | 1 + pkg_resources/__init__.py | 2 +- setuptools/__init__.py | 2 +- setuptools/command/bdist_egg.py | 14 ++++++++------ setuptools/command/build_ext.py | 4 ++-- setuptools/command/build_py.py | 12 +++++++++--- setuptools/command/develop.py | 2 +- setuptools/command/easy_install.py | 16 ++++++++-------- setuptools/command/egg_info.py | 10 +++++----- setuptools/command/install_lib.py | 6 +++--- setuptools/command/test.py | 2 +- setuptools/package_index.py | 2 +- 12 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 newsfragments/4365.misc.rst diff --git a/newsfragments/4365.misc.rst b/newsfragments/4365.misc.rst new file mode 100644 index 0000000000..7badfff8f0 --- /dev/null +++ b/newsfragments/4365.misc.rst @@ -0,0 +1 @@ +Use actual boolean parameters and variables instead of 0-1 literals. -- by :user:`Avasam` diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 45a18bf73c..7e3cf54ab8 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -731,7 +731,7 @@ def __iter__(self): for key in self.entry_keys[item]: if key not in seen: - seen[key] = 1 + seen[key] = True yield self.by_key[key] def add( diff --git a/setuptools/__init__.py b/setuptools/__init__.py index a59bbe1177..5ef0f7dbd8 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -216,7 +216,7 @@ def ensure_string_list(self, option): "'%s' must be a list of strings (got %r)" % (option, val) ) - def reinitialize_command(self, command, reinit_subcommands=0, **kw): + def reinitialize_command(self, command, reinit_subcommands=False, **kw): cmd = _Command.reinitialize_command(self, command, reinit_subcommands) vars(cmd).update(kw) return cmd diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index f72294fe58..73476e0cec 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -85,9 +85,9 @@ class bdist_egg(Command): def initialize_options(self): self.bdist_dir = None self.plat_name = None - self.keep_temp = 0 + self.keep_temp = False self.dist_dir = None - self.skip_build = 0 + self.skip_build = False self.egg_output = None self.exclude_source_files = None @@ -136,7 +136,7 @@ def do_install_data(self): try: log.info("installing package data to %s", self.bdist_dir) - self.call_command('install_data', force=0, root=None) + self.call_command('install_data', force=False, root=None) finally: self.distribution.data_files = old @@ -164,7 +164,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME instcmd.root = None if self.distribution.has_c_libraries() and not self.skip_build: self.run_command('build_clib') - cmd = self.call_command('install_lib', warn_dir=0) + cmd = self.call_command('install_lib', warn_dir=False) instcmd.root = old_root all_outputs, ext_outputs = self.get_ext_outputs() @@ -192,7 +192,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s", script_dir) - self.call_command('install_scripts', install_dir=script_dir, no_ep=1) + self.call_command('install_scripts', install_dir=script_dir, no_ep=True) self.copy_metadata_to(egg_info) native_libs = os.path.join(egg_info, "native_libs.txt") @@ -427,7 +427,9 @@ def can_scan(): INSTALL_DIRECTORY_ATTRS = ['install_lib', 'install_dir', 'install_data', 'install_base'] -def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True, mode='w'): +def make_zipfile( + zip_filename, base_dir, verbose=False, dry_run=False, compress=True, mode='w' +): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 9d8aa7fcdc..508704f3c0 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -401,7 +401,7 @@ def link_shared_object( library_dirs=None, runtime_library_dirs=None, export_symbols=None, - debug=0, + debug=False, extra_preargs=None, extra_postargs=None, build_temp=None, @@ -436,7 +436,7 @@ def link_shared_object( library_dirs=None, runtime_library_dirs=None, export_symbols=None, - debug=0, + debug=False, extra_preargs=None, extra_postargs=None, build_temp=None, diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index e74946f601..ab49874635 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -46,7 +46,13 @@ def finalize_options(self): self.__updated_files = [] def copy_file( - self, infile, outfile, preserve_mode=1, preserve_times=1, link=None, level=1 + self, + infile, + outfile, + preserve_mode=True, + preserve_times=True, + link=None, + level=1, ): # Overwrite base class to allow using links if link: @@ -70,7 +76,7 @@ def run(self): # Only compile actual .py files, using our base class' idea of what our # output files are. - self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0)) + self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False)) def __getattr__(self, attr): "lazily compute data files" @@ -132,7 +138,7 @@ def find_data_files(self, package, src_dir): ) return self.exclude_data_files(package, src_dir, files) - def get_outputs(self, include_bytecode=1) -> list[str]: + def get_outputs(self, include_bytecode=True) -> list[str]: """See :class:`setuptools.commands.build.SubCommand`""" if self.editable_mode: return list(self.get_output_mapping().keys()) diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py index d07736a005..55f24f396c 100644 --- a/setuptools/command/develop.py +++ b/setuptools/command/develop.py @@ -109,7 +109,7 @@ def install_for_development(self): self.run_command('egg_info') # Build extensions in-place - self.reinitialize_command('build_ext', inplace=1) + self.reinitialize_command('build_ext', inplace=True) self.run_command('build_ext') if setuptools.bootstrap_install_from: diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index df4d34570d..eb6ba1025f 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -171,7 +171,7 @@ def initialize_options(self): # the --user option seems to be an opt-in one, # so the default should be False. - self.user = 0 + self.user = False self.zip_ok = self.local_snapshots_ok = None self.install_dir = self.script_dir = self.exclude_scripts = None self.index_url = None @@ -1059,10 +1059,10 @@ def process(src, dst): dl = dst.lower() if dl.endswith('.pyd') or dl.endswith('.dll'): parts[-1] = bdist_egg.strip_module(parts[-1]) - top_level[os.path.splitext(parts[0])[0]] = 1 + top_level[os.path.splitext(parts[0])[0]] = True native_libs.append(src) elif dl.endswith('.py') and old != 'SCRIPTS/': - top_level[os.path.splitext(parts[0])[0]] = 1 + top_level[os.path.splitext(parts[0])[0]] = True to_compile.append(dst) return dst if not src.endswith('.pth'): @@ -1318,12 +1318,12 @@ def byte_compile(self, to_compile): # try to make the byte compile messages quieter log.set_verbosity(self.verbose - 1) - byte_compile(to_compile, optimize=0, force=1, dry_run=self.dry_run) + byte_compile(to_compile, optimize=0, force=True, dry_run=self.dry_run) if self.optimize: byte_compile( to_compile, optimize=self.optimize, - force=1, + force=True, dry_run=self.dry_run, ) finally: @@ -1491,7 +1491,7 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME if dirname in seen: continue - seen[dirname] = 1 + seen[dirname] = True if not os.path.isdir(dirname): continue @@ -1520,7 +1520,7 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME if line in seen: continue - seen[line] = 1 + seen[line] = True if not os.path.isdir(line): continue @@ -1643,7 +1643,7 @@ def _load_raw(self): dirty = True paths.pop() continue - seen[normalized_path] = 1 + seen[normalized_path] = True f.close() # remove any trailing empty/blank line while paths and not paths[-1].strip(): diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 62d2feea9b..ccc2db8972 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -534,10 +534,10 @@ class manifest_maker(sdist): template = "MANIFEST.in" def initialize_options(self): - self.use_defaults = 1 - self.prune = 1 - self.manifest_only = 1 - self.force_manifest = 1 + self.use_defaults = True + self.prune = True + self.manifest_only = True + self.force_manifest = True self.ignore_egg_info_dir = False def finalize_options(self): @@ -623,7 +623,7 @@ def prune_file_list(self): self.filelist.prune(base_dir) sep = re.escape(os.sep) self.filelist.exclude_pattern( - r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep, is_regex=1 + r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep, is_regex=True ) def _safe_data_files(self, build_py): diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 9d76e429e8..5e74be247e 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -88,9 +88,9 @@ def copy_tree( self, infile: StrPath, outfile: str, - preserve_mode=1, - preserve_times=1, - preserve_symlinks=0, + preserve_mode=True, + preserve_times=True, + preserve_symlinks=False, level=1, ): assert preserve_mode and preserve_times and not preserve_symlinks diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 0a128f2a7a..af1349e1c6 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -136,7 +136,7 @@ def project_on_sys_path(self, include_dists=()): self.run_command('egg_info') # Build extensions in-place - self.reinitialize_command('build_ext', inplace=1) + self.reinitialize_command('build_ext', inplace=True) self.run_command('build_ext') ei_cmd = self.get_finalized_command("egg_info") diff --git a/setuptools/package_index.py b/setuptools/package_index.py index c3ffee41a7..c8789e279f 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -642,7 +642,7 @@ def find(req, env=None): "Skipping development or system egg: %s", dist, ) - skipped[dist] = 1 + skipped[dist] = True continue test = dist in req and (dist.precedence <= SOURCE_DIST or not source)