Path: blob/master/venv/Lib/site-packages/setuptools/_distutils/command/build.py
811 views
"""distutils.command.build12Implements the Distutils 'build' command."""34import sys, os5from distutils.core import Command6from distutils.errors import DistutilsOptionError7from distutils.util import get_platform8910def show_compilers():11from distutils.ccompiler import show_compilers12show_compilers()131415class build(Command):1617description = "build everything needed to install"1819user_options = [20('build-base=', 'b',21"base directory for build library"),22('build-purelib=', None,23"build directory for platform-neutral distributions"),24('build-platlib=', None,25"build directory for platform-specific distributions"),26('build-lib=', None,27"build directory for all distribution (defaults to either " +28"build-purelib or build-platlib"),29('build-scripts=', None,30"build directory for scripts"),31('build-temp=', 't',32"temporary build directory"),33('plat-name=', 'p',34"platform name to build for, if supported "35"(default: %s)" % get_platform()),36('compiler=', 'c',37"specify the compiler type"),38('parallel=', 'j',39"number of parallel build jobs"),40('debug', 'g',41"compile extensions and libraries with debugging information"),42('force', 'f',43"forcibly build everything (ignore file timestamps)"),44('executable=', 'e',45"specify final destination interpreter path (build.py)"),46]4748boolean_options = ['debug', 'force']4950help_options = [51('help-compiler', None,52"list available compilers", show_compilers),53]5455def initialize_options(self):56self.build_base = 'build'57# these are decided only after 'build_base' has its final value58# (unless overridden by the user or client)59self.build_purelib = None60self.build_platlib = None61self.build_lib = None62self.build_temp = None63self.build_scripts = None64self.compiler = None65self.plat_name = None66self.debug = None67self.force = 068self.executable = None69self.parallel = None7071def finalize_options(self):72if self.plat_name is None:73self.plat_name = get_platform()74else:75# plat-name only supported for windows (other platforms are76# supported via ./configure flags, if at all). Avoid misleading77# other platforms.78if os.name != 'nt':79raise DistutilsOptionError(80"--plat-name only supported on Windows (try "81"using './configure --help' on your platform)")8283plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])8485# Make it so Python 2.x and Python 2.x with --with-pydebug don't86# share the same build directories. Doing so confuses the build87# process for C modules88if hasattr(sys, 'gettotalrefcount'):89plat_specifier += '-pydebug'9091# 'build_purelib' and 'build_platlib' just default to 'lib' and92# 'lib.<plat>' under the base build directory. We only use one of93# them for a given distribution, though --94if self.build_purelib is None:95self.build_purelib = os.path.join(self.build_base, 'lib')96if self.build_platlib is None:97self.build_platlib = os.path.join(self.build_base,98'lib' + plat_specifier)99100# 'build_lib' is the actual directory that we will use for this101# particular module distribution -- if user didn't supply it, pick102# one of 'build_purelib' or 'build_platlib'.103if self.build_lib is None:104if self.distribution.ext_modules:105self.build_lib = self.build_platlib106else:107self.build_lib = self.build_purelib108109# 'build_temp' -- temporary directory for compiler turds,110# "build/temp.<plat>"111if self.build_temp is None:112self.build_temp = os.path.join(self.build_base,113'temp' + plat_specifier)114if self.build_scripts is None:115self.build_scripts = os.path.join(self.build_base,116'scripts-%d.%d' % sys.version_info[:2])117118if self.executable is None and sys.executable:119self.executable = os.path.normpath(sys.executable)120121if isinstance(self.parallel, str):122try:123self.parallel = int(self.parallel)124except ValueError:125raise DistutilsOptionError("parallel should be an integer")126127def run(self):128# Run all relevant sub-commands. This will be some subset of:129# - build_py - pure Python modules130# - build_clib - standalone C libraries131# - build_ext - Python extensions132# - build_scripts - (Python) scripts133for cmd_name in self.get_sub_commands():134self.run_command(cmd_name)135136137# -- Predicates for the sub-command list ---------------------------138139def has_pure_modules(self):140return self.distribution.has_pure_modules()141142def has_c_libraries(self):143return self.distribution.has_c_libraries()144145def has_ext_modules(self):146return self.distribution.has_ext_modules()147148def has_scripts(self):149return self.distribution.has_scripts()150151152sub_commands = [('build_py', has_pure_modules),153('build_clib', has_c_libraries),154('build_ext', has_ext_modules),155('build_scripts', has_scripts),156]157158159