python (3.11.7)

(root)/
lib/
python3.11/
site-packages/
setuptools/
_distutils/
command/
clean.py
       1  """distutils.command.clean
       2  
       3  Implements the Distutils 'clean' command."""
       4  
       5  # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
       6  
       7  import os
       8  from distutils.core import Command
       9  from distutils.dir_util import remove_tree
      10  from distutils import log
      11  
      12  
      13  class ESC[4;38;5;81mclean(ESC[4;38;5;149mCommand):
      14  
      15      description = "clean up temporary files from 'build' command"
      16      user_options = [
      17          ('build-base=', 'b', "base build directory (default: 'build.build-base')"),
      18          (
      19              'build-lib=',
      20              None,
      21              "build directory for all modules (default: 'build.build-lib')",
      22          ),
      23          ('build-temp=', 't', "temporary build directory (default: 'build.build-temp')"),
      24          (
      25              'build-scripts=',
      26              None,
      27              "build directory for scripts (default: 'build.build-scripts')",
      28          ),
      29          ('bdist-base=', None, "temporary directory for built distributions"),
      30          ('all', 'a', "remove all build output, not just temporary by-products"),
      31      ]
      32  
      33      boolean_options = ['all']
      34  
      35      def initialize_options(self):
      36          self.build_base = None
      37          self.build_lib = None
      38          self.build_temp = None
      39          self.build_scripts = None
      40          self.bdist_base = None
      41          self.all = None
      42  
      43      def finalize_options(self):
      44          self.set_undefined_options(
      45              'build',
      46              ('build_base', 'build_base'),
      47              ('build_lib', 'build_lib'),
      48              ('build_scripts', 'build_scripts'),
      49              ('build_temp', 'build_temp'),
      50          )
      51          self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
      52  
      53      def run(self):
      54          # remove the build/temp.<plat> directory (unless it's already
      55          # gone)
      56          if os.path.exists(self.build_temp):
      57              remove_tree(self.build_temp, dry_run=self.dry_run)
      58          else:
      59              log.debug("'%s' does not exist -- can't clean it", self.build_temp)
      60  
      61          if self.all:
      62              # remove build directories
      63              for directory in (self.build_lib, self.bdist_base, self.build_scripts):
      64                  if os.path.exists(directory):
      65                      remove_tree(directory, dry_run=self.dry_run)
      66                  else:
      67                      log.warn("'%s' does not exist -- can't clean it", directory)
      68  
      69          # just for the heck of it, try to remove the base build directory:
      70          # we might have emptied it right now, but if not we don't care
      71          if not self.dry_run:
      72              try:
      73                  os.rmdir(self.build_base)
      74                  log.info("removing '%s'", self.build_base)
      75              except OSError:
      76                  pass