Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/distutils/unixccompiler.py
7763 views
"""1unixccompiler - can handle very long argument lists for ar.23"""4import os5import sys6import subprocess7import shlex89from distutils.errors import CompileError, DistutilsExecError, LibError10from distutils.unixccompiler import UnixCCompiler11from numpy.distutils.ccompiler import replace_method12from numpy.distutils.misc_util import _commandline_dep_string13from numpy.distutils import log1415# Note that UnixCCompiler._compile appeared in Python 2.316def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):17"""Compile a single source files with a Unix-style compiler."""18# HP ad-hoc fix, see ticket 138319ccomp = self.compiler_so20if ccomp[0] == 'aCC':21# remove flags that will trigger ANSI-C mode for aCC22if '-Ae' in ccomp:23ccomp.remove('-Ae')24if '-Aa' in ccomp:25ccomp.remove('-Aa')26# add flags for (almost) sane C++ handling27ccomp += ['-AA']28self.compiler_so = ccomp29# ensure OPT environment variable is read30if 'OPT' in os.environ:31# XXX who uses this?32from sysconfig import get_config_vars33opt = shlex.join(shlex.split(os.environ['OPT']))34gcv_opt = shlex.join(shlex.split(get_config_vars('OPT')[0]))35ccomp_s = shlex.join(self.compiler_so)36if opt not in ccomp_s:37ccomp_s = ccomp_s.replace(gcv_opt, opt)38self.compiler_so = shlex.split(ccomp_s)39llink_s = shlex.join(self.linker_so)40if opt not in llink_s:41self.linker_so = self.linker_so + shlex.split(opt)4243display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src)4445# gcc style automatic dependencies, outputs a makefile (-MF) that lists46# all headers needed by a c file as a side effect of compilation (-MMD)47if getattr(self, '_auto_depends', False):48deps = ['-MMD', '-MF', obj + '.d']49else:50deps = []5152try:53self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps +54extra_postargs, display = display)55except DistutilsExecError as e:56msg = str(e)57raise CompileError(msg) from None5859# add commandline flags to dependency file60if deps:61# After running the compiler, the file created will be in EBCDIC62# but will not be tagged as such. This tags it so the file does not63# have multiple different encodings being written to it64if sys.platform == 'zos':65subprocess.check_output(['chtag', '-tc', 'IBM1047', obj + '.d'])66with open(obj + '.d', 'a') as f:67f.write(_commandline_dep_string(cc_args, extra_postargs, pp_opts))6869replace_method(UnixCCompiler, '_compile', UnixCCompiler__compile)707172def UnixCCompiler_create_static_lib(self, objects, output_libname,73output_dir=None, debug=0, target_lang=None):74"""75Build a static library in a separate sub-process.7677Parameters78----------79objects : list or tuple of str80List of paths to object files used to build the static library.81output_libname : str82The library name as an absolute or relative (if `output_dir` is used)83path.84output_dir : str, optional85The path to the output directory. Default is None, in which case86the ``output_dir`` attribute of the UnixCCompiler instance.87debug : bool, optional88This parameter is not used.89target_lang : str, optional90This parameter is not used.9192Returns93-------94None9596"""97objects, output_dir = self._fix_object_args(objects, output_dir)9899output_filename = \100self.library_filename(output_libname, output_dir=output_dir)101102if self._need_link(objects, output_filename):103try:104# previous .a may be screwed up; best to remove it first105# and recreate.106# Also, ar on OS X doesn't handle updating universal archives107os.unlink(output_filename)108except OSError:109pass110self.mkpath(os.path.dirname(output_filename))111tmp_objects = objects + self.objects112while tmp_objects:113objects = tmp_objects[:50]114tmp_objects = tmp_objects[50:]115display = '%s: adding %d object files to %s' % (116os.path.basename(self.archiver[0]),117len(objects), output_filename)118self.spawn(self.archiver + [output_filename] + objects,119display = display)120121# Not many Unices required ranlib anymore -- SunOS 4.x is, I122# think the only major Unix that does. Maybe we need some123# platform intelligence here to skip ranlib if it's not124# needed -- or maybe Python's configure script took care of125# it for us, hence the check for leading colon.126if self.ranlib:127display = '%s:@ %s' % (os.path.basename(self.ranlib[0]),128output_filename)129try:130self.spawn(self.ranlib + [output_filename],131display = display)132except DistutilsExecError as e:133msg = str(e)134raise LibError(msg) from None135else:136log.debug("skipping %s (up-to-date)", output_filename)137return138139replace_method(UnixCCompiler, 'create_static_lib',140UnixCCompiler_create_static_lib)141142143