From 5779276005a28e7d3d052267e6bf668d51fa088b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 14:06:28 -0400 Subject: Remove wildcard imports from distutils.command.sdist --- Lib/distutils/command/sdist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index 4fd1d4715d..690bd66f2c 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -4,17 +4,17 @@ Implements the Distutils 'sdist' command (create a source distribution).""" import os import sys -from types import * from glob import glob from warnings import warn from distutils.core import Command from distutils import dir_util, dep_util, file_util, archive_util from distutils.text_file import TextFile -from distutils.errors import * from distutils.filelist import FileList from distutils import log from distutils.util import convert_path +from distutils.errors import DistutilsTemplateError, DistutilsOptionError + def show_formats(): """Print all possible values for the 'formats' option (used by -- cgit v1.2.1 From 68a742a7fce7099d2a7249e06fa438f22a9d5d21 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 14:08:28 -0400 Subject: Remove unused import and reorganize imports of modules. --- Lib/distutils/command/sdist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index 690bd66f2c..c13dbbf895 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -8,7 +8,9 @@ from glob import glob from warnings import warn from distutils.core import Command -from distutils import dir_util, dep_util, file_util, archive_util +from distutils import dir_util +from distutils import file_util +from distutils import archive_util from distutils.text_file import TextFile from distutils.filelist import FileList from distutils import log -- cgit v1.2.1 From 514aca13053adba591a4afbe1957a61dad578544 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 14:10:07 -0400 Subject: Replace trailing comments with block-level comments --- Lib/distutils/command/sdist.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index c13dbbf895..28cd0d9ef1 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -261,11 +261,13 @@ class sdist(Command): # getting distribution.data_files if self.distribution.has_data_files(): for item in self.distribution.data_files: - if isinstance(item, str): # plain file + if isinstance(item, str): + # plain file item = convert_path(item) if os.path.isfile(item): self.filelist.append(item) - else: # a (dirname, filenames) tuple + else: + # a (dirname, filenames) tuple dirname, filenames = item for f in filenames: f = convert_path(f) -- cgit v1.2.1 From 0e4054ce9cbc1e2c02c9ccca484f07ffce2ef03e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 14:44:11 -0400 Subject: Get names for README files from class attribute, allowing subclass to override. --- Lib/distutils/command/sdist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index 28cd0d9ef1..e5121666b8 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -95,6 +95,8 @@ class sdist(Command): sub_commands = [('check', checking_metadata)] + READMES = 'README', 'README.txt' + def initialize_options(self): # 'template' and 'manifest' are, respectively, the names of # the manifest template and manifest file. @@ -218,7 +220,7 @@ class sdist(Command): Warns if (README or README.txt) or setup.py are missing; everything else is optional. """ - standards = [('README', 'README.txt'), self.distribution.script_name] + standards = [self.READMES, self.distribution.script_name] for fn in standards: if isinstance(fn, tuple): alts = fn -- cgit v1.2.1 From 0291da18206fba7b1fcf10aaeceaf9ce72f7f040 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 14:53:32 -0400 Subject: Extract methods from sdist.add_defaults, allowing subclasses to override or inject different behaviors. --- Lib/distutils/command/sdist.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index e5121666b8..c66d82713d 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -220,6 +220,15 @@ class sdist(Command): Warns if (README or README.txt) or setup.py are missing; everything else is optional. """ + self._add_defaults_standards() + self._add_defaults_optional() + self._add_defaults_python() + self._add_defaults_data_files() + self._add_defaults_ext() + self._add_defaults_c_libs() + self._add_defaults_scripts() + + def _add_defaults_standards(self): standards = [self.READMES, self.distribution.script_name] for fn in standards: if isinstance(fn, tuple): @@ -240,11 +249,13 @@ class sdist(Command): else: self.warn("standard file '%s' not found" % fn) + def _add_defaults_optional(self): optional = ['test/test*.py', 'setup.cfg'] for pattern in optional: files = filter(os.path.isfile, glob(pattern)) self.filelist.extend(files) + def _add_defaults_python(self): # build_py is used to get: # - python modules # - files defined in package_data @@ -260,6 +271,7 @@ class sdist(Command): for filename in filenames: self.filelist.append(os.path.join(src_dir, filename)) + def _add_defaults_data_files(self): # getting distribution.data_files if self.distribution.has_data_files(): for item in self.distribution.data_files: @@ -276,14 +288,17 @@ class sdist(Command): if os.path.isfile(f): self.filelist.append(f) + def _add_defaults_ext(self): if self.distribution.has_ext_modules(): build_ext = self.get_finalized_command('build_ext') self.filelist.extend(build_ext.get_source_files()) + def _add_defaults_c_libs(self): if self.distribution.has_c_libraries(): build_clib = self.get_finalized_command('build_clib') self.filelist.extend(build_clib.get_source_files()) + def _add_defaults_scripts(self): if self.distribution.has_scripts(): build_scripts = self.get_finalized_command('build_scripts') self.filelist.extend(build_scripts.get_source_files()) -- cgit v1.2.1 From 573ccac9c6d1d19da28076ac473ed1343fa8ab13 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 15:39:01 -0400 Subject: Add case-sensitive file comparison for detecting/adding standard default files. --- Lib/distutils/command/sdist.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index c66d82713d..0cc01192f3 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -32,6 +32,24 @@ def show_formats(): FancyGetopt(formats).print_help( "List of available source distribution formats:") + +def cs_path_exists(fspath): + """ + Case-sensitive path existence check + + >>> cs_path_exists(__file__) + True + >>> cs_path_exists(__file__.upper()) + False + """ + if not os.path.exists(fspath): + return False + # make absolute so we always have a directory + abspath = os.path.abspath(fspath) + directory, filename = os.path.split(abspath) + return filename in os.listdir(directory) + + class sdist(Command): description = "create a source distribution (tarball, zip file, etc.)" @@ -235,7 +253,7 @@ class sdist(Command): alts = fn got_it = False for fn in alts: - if os.path.exists(fn): + if cs_path_exists(fn): got_it = True self.filelist.append(fn) break @@ -244,7 +262,7 @@ class sdist(Command): self.warn("standard file not found: should have one of " + ', '.join(alts)) else: - if os.path.exists(fn): + if cs_path_exists(fn): self.filelist.append(fn) else: self.warn("standard file '%s' not found" % fn) -- cgit v1.2.1 From 0fc92e5a02a012440a288db610387b337034d715 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 14 Oct 2016 15:41:42 -0400 Subject: Make cs_path_exists a protected, static method --- Lib/distutils/command/sdist.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'Lib/distutils/command/sdist.py') diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index 0cc01192f3..180e28626d 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -33,23 +33,6 @@ def show_formats(): "List of available source distribution formats:") -def cs_path_exists(fspath): - """ - Case-sensitive path existence check - - >>> cs_path_exists(__file__) - True - >>> cs_path_exists(__file__.upper()) - False - """ - if not os.path.exists(fspath): - return False - # make absolute so we always have a directory - abspath = os.path.abspath(fspath) - directory, filename = os.path.split(abspath) - return filename in os.listdir(directory) - - class sdist(Command): description = "create a source distribution (tarball, zip file, etc.)" @@ -246,6 +229,23 @@ class sdist(Command): self._add_defaults_c_libs() self._add_defaults_scripts() + @staticmethod + def _cs_path_exists(fspath): + """ + Case-sensitive path existence check + + >>> sdist._cs_path_exists(__file__) + True + >>> sdist._cs_path_exists(__file__.upper()) + False + """ + if not os.path.exists(fspath): + return False + # make absolute so we always have a directory + abspath = os.path.abspath(fspath) + directory, filename = os.path.split(abspath) + return filename in os.listdir(directory) + def _add_defaults_standards(self): standards = [self.READMES, self.distribution.script_name] for fn in standards: @@ -253,7 +253,7 @@ class sdist(Command): alts = fn got_it = False for fn in alts: - if cs_path_exists(fn): + if self._cs_path_exists(fn): got_it = True self.filelist.append(fn) break @@ -262,7 +262,7 @@ class sdist(Command): self.warn("standard file not found: should have one of " + ', '.join(alts)) else: - if cs_path_exists(fn): + if self._cs_path_exists(fn): self.filelist.append(fn) else: self.warn("standard file '%s' not found" % fn) -- cgit v1.2.1