[Python-checkins] CVS: distutils/distutils/command sdist.py,1.25,1.26

Greg Ward python-dev@python.org
Wed, 7 Jun 2000 17:08:17 -0700


Update of /cvsroot/python/distutils/distutils/command
In directory slayer.i.sourceforge.net:/tmp/cvs-serv15881

Modified Files:
	sdist.py 
Log Message:
Made all debug output go through the 'debug_print()' method instead of
directly printing to stdout.  This was a bit more work than it sounds like
it should have been:
  * turned 'select_pattern()' and 'exclude_pattern()' from functions into
    methods, so they can refer to 'self' to access the method
  * commented out the *other* 'exclude_pattern()' method, which appears
    to be vestigial code that was never cleaned up when the
    'exclude_pattern()' function was created
  * changed the one use of the old 'exclude_pattern()' method to use the
    new 'exclude_pattern()' (same behaviour, slightly different args)
  * some code and docstring reformatting
  * and, of course, changed all the debugging prints to 'debug_print()' calls
Added/tweaked some regular ('self.announce()') output for better runtime
  feedback.


Index: sdist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/sdist.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** sdist.py	2000/06/07 03:00:06	1.25
--- sdist.py	2000/06/08 00:08:14	1.26
***************
*** 5,9 ****
  # created 1999/09/22, Greg Ward
  
! __revision__ = "$Id: sdist.py,v 1.25 2000/06/07 03:00:06 gward Exp $"
  
  import sys, os, string, re
--- 5,9 ----
  # created 1999/09/22, Greg Ward
  
! __revision__ = "$Id: sdist.py,v 1.26 2000/06/08 00:08:14 gward Exp $"
  
  import sys, os, string, re
***************
*** 273,284 ****
  
  
!     def exclude_pattern (self, pattern):
!         """Remove filenames from 'self.files' that match 'pattern'."""
!         print "exclude_pattern: pattern=%s" % pattern
!         pattern_re = translate_pattern (pattern)
!         for i in range (len (self.files)-1, -1, -1):
!             if pattern_re.match (self.files[i]):
!                 print "removing %s" % self.files[i]
!                 del self.files[i]
  
  
--- 273,284 ----
  
  
! #     def exclude_pattern (self, pattern):
! #         """Remove filenames from 'self.files' that match 'pattern'."""
! #         self.debug_print("exclude_pattern: pattern=%s" % pattern)
! #         pattern_re = translate_pattern (pattern)
! #         for i in range (len (self.files)-1, -1, -1):
! #             if pattern_re.match (self.files[i]):
! #                 self.debug_print("removing %s" % self.files[i])
! #                 del self.files[i]
  
  
***************
*** 287,291 ****
             and whose basenames match 'pattern'."""
  
!         print "recursive_exclude_pattern: dir=%s, pattern=%s" % (dir, pattern)
          if pattern is None:
              pattern_re = None
--- 287,292 ----
             and whose basenames match 'pattern'."""
  
!         self.debug_print("recursive_exclude_pattern: dir=%s, pattern=%s" %
!                          (dir, pattern))
          if pattern is None:
              pattern_re = None
***************
*** 297,301 ****
              if (cur_dir == dir and
                  (pattern_re is None or pattern_re.match (cur_base))):
!                 print "removing %s" % self.files[i]
                  del self.files[i]
  
--- 298,302 ----
              if (cur_dir == dir and
                  (pattern_re is None or pattern_re.match (cur_base))):
!                 self.debug_print("removing %s" % self.files[i])
                  del self.files[i]
  
***************
*** 308,311 ****
--- 309,313 ----
  
          assert self.files is not None and type (self.files) is ListType
+         self.announce("reading manifest template '%s'" % self.template)
  
          template = TextFile (self.template,
***************
*** 375,390 ****
  
              if action == 'include':
!                 print "include", string.join(pattern_list)
                  for pattern in pattern_list:
!                     files = select_pattern (all_files, pattern, anchor=1)
                      if not files:
!                         template.warn ("no files found matching '%s'" % pattern)
                      else:
                          self.files.extend (files)
  
              elif action == 'exclude':
!                 print "exclude", string.join(pattern_list)
                  for pattern in pattern_list:
!                     num = exclude_pattern (self.files, pattern, anchor=1)
                      if num == 0:
                          template.warn (
--- 377,393 ----
  
              if action == 'include':
!                 self.debug_print("include " + string.join(pattern_list))
                  for pattern in pattern_list:
!                     files = self.select_pattern (all_files, pattern, anchor=1)
                      if not files:
!                         template.warn ("no files found matching '%s'" %
!                                        pattern)
                      else:
                          self.files.extend (files)
  
              elif action == 'exclude':
!                 self.debug_print("exclude " + string.join(pattern_list))
                  for pattern in pattern_list:
!                     num = self.exclude_pattern (self.files, pattern, anchor=1)
                      if num == 0:
                          template.warn (
***************
*** 393,399 ****
  
              elif action == 'global-include':
!                 print "global-include", string.join(pattern_list)
                  for pattern in pattern_list:
!                     files = select_pattern (all_files, pattern, anchor=0)
                      if not files:
                          template.warn (("no files found matching '%s' " +
--- 396,402 ----
  
              elif action == 'global-include':
!                 self.debug_print("global-include " + string.join(pattern_list))
                  for pattern in pattern_list:
!                     files = self.select_pattern (all_files, pattern, anchor=0)
                      if not files:
                          template.warn (("no files found matching '%s' " +
***************
*** 404,410 ****
  
              elif action == 'global-exclude':
!                 print "global-exclude", string.join(pattern_list)
                  for pattern in pattern_list:
!                     num = exclude_pattern (self.files, pattern, anchor=0)
                      if num == 0:
                          template.warn \
--- 407,413 ----
  
              elif action == 'global-exclude':
!                 self.debug_print("global-exclude " + string.join(pattern_list))
                  for pattern in pattern_list:
!                     num = self.exclude_pattern (self.files, pattern, anchor=0)
                      if num == 0:
                          template.warn \
***************
*** 414,420 ****
  
              elif action == 'recursive-include':
!                 print "recursive-include", dir, string.join(pattern_list)
                  for pattern in pattern_list:
!                     files = select_pattern (all_files, pattern, prefix=dir)
                      if not files:
                          template.warn (("no files found matching '%s' " +
--- 417,425 ----
  
              elif action == 'recursive-include':
!                 self.debug_print("recursive-include %s %s" %
!                                  (dir, string.join(pattern_list)))
                  for pattern in pattern_list:
!                     files = self.select_pattern (
!                         all_files, pattern, prefix=dir)
                      if not files:
                          template.warn (("no files found matching '%s' " +
***************
*** 425,431 ****
  
              elif action == 'recursive-exclude':
!                 print "recursive-exclude", dir, string.join(pattern_list)
                  for pattern in pattern_list:
!                     num = exclude_pattern (self.files, pattern, prefix=dir)
                      if num == 0:
                          template.warn \
--- 430,438 ----
  
              elif action == 'recursive-exclude':
!                 self.debug_print("recursive-exclude %s %s" %
!                                  (dir, string.join(pattern_list)))
                  for pattern in pattern_list:
!                     num = self.exclude_pattern(
!                         self.files, pattern, prefix=dir)
                      if num == 0:
                          template.warn \
***************
*** 435,440 ****
  
              elif action == 'graft':
!                 print "graft", dir_pattern
!                 files = select_pattern (all_files, None, prefix=dir_pattern)
                  if not files:
                      template.warn ("no directories found matching '%s'" %
--- 442,448 ----
  
              elif action == 'graft':
!                 self.debug_print("graft " + dir_pattern)
!                 files = self.select_pattern(
!                     all_files, None, prefix=dir_pattern)
                  if not files:
                      template.warn ("no directories found matching '%s'" %
***************
*** 444,449 ****
  
              elif action == 'prune':
!                 print "prune", dir_pattern
!                 num = exclude_pattern (self.files, None, prefix=dir_pattern)
                  if num == 0:
                      template.warn \
--- 452,458 ----
  
              elif action == 'prune':
!                 self.debug_print("prune " + dir_pattern)
!                 num = self.exclude_pattern(
!                     self.files, None, prefix=dir_pattern)
                  if num == 0:
                      template.warn \
***************
*** 459,470 ****
          # Prune away the build and source distribution directories
          build = self.get_finalized_command ('build')
!         exclude_pattern (self.files, None, prefix=build.build_base)
  
          base_dir = self.distribution.get_fullname()
!         exclude_pattern (self.files, None, prefix=base_dir)
  
      # read_template ()
  
  
      def write_manifest (self):
          """Write the file list in 'self.files' (presumably as filled in
--- 468,528 ----
          # Prune away the build and source distribution directories
          build = self.get_finalized_command ('build')
!         self.exclude_pattern (self.files, None, prefix=build.build_base)
  
          base_dir = self.distribution.get_fullname()
!         self.exclude_pattern (self.files, None, prefix=base_dir)
  
      # read_template ()
  
  
+     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
+         quite the same as implemented by the 'fnmatch' module: '*' and '?'
+         match non-special characters, where "special" is platform-dependent:
+         slash on Unix, colon, slash, and backslash on DOS/Windows, and colon on
+         Mac OS.
+ 
+         If 'anchor' is true (the default), then the pattern match is more
+         stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
+         'anchor' is false, both of these will match.
+ 
+         If 'prefix' is supplied, then only filenames starting with 'prefix'
+         (itself a pattern) and ending with 'pattern', with anything in between
+         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)
+         for name in files:
+             if pattern_re.search (name):
+                 matches.append (name)
+                 self.debug_print(" adding " + name)
+ 
+         return matches
+ 
+     # select_pattern ()
+ 
+ 
+     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)
+         for i in range (len(files)-1, -1, -1):
+             if pattern_re.search (files[i]):
+                 self.debug_print(" removing " + files[i])
+                 del files[i]
+ 
+     # exclude_pattern ()
+ 
+ 
      def write_manifest (self):
          """Write the file list in 'self.files' (presumably as filled in
***************
*** 474,478 ****
          self.execute(write_file,
                       (self.manifest, self.files),
!                      "writing manifest file")
  
      # write_manifest ()
--- 532,536 ----
          self.execute(write_file,
                       (self.manifest, self.files),
!                      "writing manifest file '%s'" % self.manifest)
  
      # write_manifest ()
***************
*** 484,487 ****
--- 542,546 ----
             in the source distribution."""
  
+         self.announce("reading manifest file '%s'" % self.manifest)
          manifest = open (self.manifest)
          while 1:
***************
*** 496,500 ****
              
  
- 
      def make_release_tree (self, base_dir, files):
  
--- 555,558 ----
***************
*** 534,538 ****
          # Remove any files that match "base_dir" from the fileset -- we
          # don't want to go distributing the distribution inside itself!
!         self.exclude_pattern (base_dir + "*")
   
          self.make_release_tree (base_dir, self.files)
--- 592,596 ----
          # Remove any files that match "base_dir" from the fileset -- we
          # don't want to go distributing the distribution inside itself!
!         self.exclude_pattern (self.files, base_dir + "*")
   
          self.make_release_tree (base_dir, self.files)
***************
*** 582,628 ****
  
      return list
- 
- 
- def select_pattern (files, pattern, anchor=1, prefix=None):
-     """Select strings (presumably filenames) from 'files' that match
-        'pattern', a Unix-style wildcard (glob) pattern.  Patterns are not
-        quite the same as implemented by the 'fnmatch' module: '*' and '?'
-        match non-special characters, where "special" is platform-dependent:
-        slash on Unix, colon, slash, and backslash on DOS/Windows, and colon
-        on Mac OS.
- 
-        If 'anchor' is true (the default), then the pattern match is more
-        stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
-        'anchor' is false, both of these will match.
- 
-        If 'prefix' is supplied, then only filenames starting with 'prefix'
-        (itself a pattern) and ending with 'pattern', with anything in
-        between 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)
-     print "select_pattern: applying re %s" % pattern_re.pattern
-     for name in files:
-         if pattern_re.search (name):
-             matches.append (name)
-             print " adding", name
- 
-     return matches
- 
- # select_pattern ()
- 
- 
- def exclude_pattern (files, pattern, anchor=1, prefix=None):
- 
-     pattern_re = translate_pattern (pattern, anchor, prefix)
-     print "exclude_pattern: applying re %s" % pattern_re.pattern
-     for i in range (len(files)-1, -1, -1):
-         if pattern_re.search (files[i]):
-             print " removing", files[i]
-             del files[i]
- 
- # exclude_pattern ()
  
  
--- 640,643 ----