[Python-checkins] CVS: distutils/distutils/command sdist.py,1.35,1.36
Greg Ward
python-dev@python.org
2000年6月28日 19:06:33 -0700
Update of /cvsroot/python/distutils/distutils/command
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17312
Modified Files:
sdist.py
Log Message:
Fixed 'findall()' so it only returns regular files -- no directories.
Changed 'prune_file_list()' so it also prunes out RCS and CVS directories.
Added 'is_regex' parameter to 'select_pattern()', 'exclude_pattern()',
and 'translate_pattern()', so that you don't have to be constrained
by the simple shell-glob-like pattern language, and can escape into
full-blown regexes when needed. Currently this is only available
in code -- it's not exposed in the manifest template mini-language.
Added 'prune' option (controlled by --prune and --no-prune) to determine
whether we call 'prune_file_list()' or not -- it's true by default.
Fixed 'negative_opt' -- it was misnamed and not being seen by dist.py.
Added --no-defaults to the option table, so it's seen by FancyGetopt.
Index: sdist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/sdist.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** sdist.py 2000年06月24日 01:23:37 1.35
--- sdist.py 2000年06月29日 02:06:29 1.36
***************
*** 47,50 ****
--- 47,58 ----
"include the default file set in the manifest "
"[default; disable with --no-defaults]"),
+ ('no-defaults', None,
+ "don't include the default file set"),
+ ('prune', None,
+ "specifically exclude files/directories that should not be "
+ "distributed (build tree, RCS/CVS dirs, etc.) "
+ "[default; disable with --no-prune]"),
+ ('no-prune', None,
+ "don't automatically exclude anything"),
('manifest-only', 'o',
"just regenerate the manifest and then stop "
***************
*** 65,69 ****
]
! negative_opts = {'use-defaults': 'no-defaults'}
default_format = { 'posix': 'gztar',
--- 73,78 ----
]
! negative_opt = {'no-defaults': 'use-defaults',
! 'no-prune': 'prune' }
default_format = { 'posix': 'gztar',
***************
*** 79,82 ****
--- 88,92 ----
# in the manifest
self.use_defaults = 1
+ self.prune = 1
self.manifest_only = 0
***************
*** 218,223 ****
self.read_template ()
! # Prune away the build and source distribution directories
! self.prune_file_list()
# File list now complete -- sort it so that higher-level files
--- 228,235 ----
self.read_template ()
! # Prune away any directories that don't belong in the source
! # distribution
! if self.prune:
! self.prune_file_list()
# File list now complete -- sort it so that higher-level files
***************
*** 510,517 ****
def prune_file_list (self):
"""Prune off branches that might slip into the file list as created
! by 'read_template()', but really don't belong there: specifically,
! the build tree (typically "build") and the release tree itself
! (only an issue if we ran "sdist" previously with --keep-tree, or it
! aborted).
"""
build = self.get_finalized_command('build')
--- 522,530 ----
def prune_file_list (self):
"""Prune off branches that might slip into the file list as created
! by 'read_template()', but really don't belong there:
! * the build tree (typically "build")
! * the release tree itself (only an issue if we ran "sdist"
! previously with --keep-tree, or it aborted)
! * any RCS or CVS directories
"""
build = self.get_finalized_command('build')
***************
*** 519,525 ****
self.exclude_pattern (self.files, None, prefix=build.build_base)
self.exclude_pattern (self.files, None, prefix=base_dir)
! def select_pattern (self, files, pattern, anchor=1, prefix=None):
"""Select strings (presumably filenames) from 'files' that match
'pattern', a Unix-style wildcard (glob) pattern. Patterns are not
--- 532,540 ----
self.exclude_pattern (self.files, None, prefix=build.build_base)
self.exclude_pattern (self.files, None, prefix=base_dir)
+ self.exclude_pattern (self.files, r'/(RCS|CVS)/.*', is_regex=1)
! def select_pattern (self, files, pattern,
! anchor=1, prefix=None, is_regex=0):
"""Select strings (presumably filenames) from 'files' that match
'pattern', a Unix-style wildcard (glob) pattern. Patterns are not
***************
*** 537,544 ****
them, will match. 'anchor' is ignored in this case.
Return the list of matching strings, possibly empty.
"""
matches = []
! pattern_re = translate_pattern (pattern, anchor, prefix)
self.debug_print("select_pattern: applying regex r'%s'" %
pattern_re.pattern)
--- 552,564 ----
them, will match. 'anchor' is ignored in this case.
+ If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
+ 'pattern' is assumed to be either a string containing a regex or a
+ regex object -- no translation is done, the regex is just compiled
+ and used as-is.
+
Return the list of matching strings, possibly empty.
"""
matches = []
! pattern_re = translate_pattern (pattern, anchor, prefix, is_regex)
self.debug_print("select_pattern: applying regex r'%s'" %
pattern_re.pattern)
***************
*** 553,563 ****
! def exclude_pattern (self, files, pattern, anchor=1, prefix=None):
"""Remove strings (presumably filenames) from 'files' that match
! 'pattern'. 'pattern', 'anchor', 'and 'prefix' are the same
! as for 'select_pattern()', above. The list 'files' is modified
! in place.
"""
! pattern_re = translate_pattern (pattern, anchor, prefix)
self.debug_print("exclude_pattern: applying regex r'%s'" %
pattern_re.pattern)
--- 573,584 ----
! def exclude_pattern (self, files, pattern,
! anchor=1, prefix=None, is_regex=0):
"""Remove strings (presumably filenames) from 'files' that match
! 'pattern'. Other parameters are the same as for
! 'select_pattern()', above. The list 'files' is modified in place.
"""
!
! pattern_re = translate_pattern (pattern, anchor, prefix, is_regex)
self.debug_print("exclude_pattern: applying regex r'%s'" %
pattern_re.pattern)
***************
*** 675,678 ****
--- 696,701 ----
(relative to 'dir').
"""
+ from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
+
list = []
stack = [dir]
***************
*** 689,694 ****
else:
fullname = name
! list.append (fullname)
! if os.path.isdir (fullname) and not os.path.islink(fullname):
push (fullname)
--- 712,722 ----
else:
fullname = name
!
! # Avoid excess stat calls -- just one will do, thank you!
! stat = os.stat(fullname)
! mode = stat[ST_MODE]
! if S_ISREG(mode):
! list.append (fullname)
! elif S_ISDIR(mode) and not S_ISLNK(mode):
push (fullname)
***************
*** 717,724 ****
! def translate_pattern (pattern, anchor=1, prefix=None):
"""Translate a shell-like wildcard pattern to a compiled regular
! expression. Return the compiled regex.
"""
if pattern:
pattern_re = glob_to_re (pattern)
--- 745,760 ----
! def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
"""Translate a shell-like wildcard pattern to a compiled regular
! expression. Return the compiled regex. If 'is_regex' true,
! then 'pattern' is directly compiled to a regex (if it's a string)
! or just returned as-is (assumes it's a regex object).
"""
+ if is_regex:
+ if type(pattern) is StringType:
+ return re.compile(pattern)
+ else:
+ return pattern
+
if pattern:
pattern_re = glob_to_re (pattern)