CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
clean.py78 linesDownload Raw Back to command
1"""distutils.command.clean2 3Implements the Distutils 'clean' command."""4 5# contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-186 7import os8from distutils._log import log9from typing import ClassVar10 11from ..core import Command12from ..dir_util import remove_tree13 14 15class clean(Command):16    description = "clean up temporary files from 'build' command"17    user_options = [18        ('build-base=', 'b', "base build directory [default: 'build.build-base']"),19        (20            'build-lib=',21            None,22            "build directory for all modules [default: 'build.build-lib']",23        ),24        ('build-temp=', 't', "temporary build directory [default: 'build.build-temp']"),25        (26            'build-scripts=',27            None,28            "build directory for scripts [default: 'build.build-scripts']",29        ),30        ('bdist-base=', None, "temporary directory for built distributions"),31        ('all', 'a', "remove all build output, not just temporary by-products"),32    ]33 34    boolean_options: ClassVar[list[str]] = ['all']35 36    def initialize_options(self):37        self.build_base = None38        self.build_lib = None39        self.build_temp = None40        self.build_scripts = None41        self.bdist_base = None42        self.all = None43 44    def finalize_options(self):45        self.set_undefined_options(46            'build',47            ('build_base', 'build_base'),48            ('build_lib', 'build_lib'),49            ('build_scripts', 'build_scripts'),50            ('build_temp', 'build_temp'),51        )52        self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))53 54    def run(self):55        # remove the build/temp.<plat> directory (unless it's already56        # gone)57        if os.path.exists(self.build_temp):58            remove_tree(self.build_temp, dry_run=self.dry_run)59        else:60            log.debug("'%s' does not exist -- can't clean it", self.build_temp)61 62        if self.all:63            # remove build directories64            for directory in (self.build_lib, self.bdist_base, self.build_scripts):65                if os.path.exists(directory):66                    remove_tree(directory, dry_run=self.dry_run)67                else:68                    log.warning("'%s' does not exist -- can't clean it", directory)69 70        # just for the heck of it, try to remove the base build directory:71        # we might have emptied it right now, but if not we don't care72        if not self.dry_run:73            try:74                os.rmdir(self.build_base)75                log.info("removing '%s'", self.build_base)76            except OSError:77                pass78