def fix_python_lib(): if system=='Darwin': lib = os.path.join( dirname(get_makefile_filename()), 'libpython%s.%s.a' % sys.version_info[0:2] ) if os.path.islink(lib): os.remove(lib) os.symlink('../../../Python', lib) assert os.path.exists( os.path.realpath(lib)), "symbolic link is invalid"
def _extras_paths(cls): # type: () -> Iterator[str] standard_lib = sysconfig.get_python_lib(standard_lib=True) try: makefile = sysconfig.parse_makefile( # type: ignore[attr-defined] sysconfig.get_makefile_filename() ) except (AttributeError, IOError): # This is not available by default in PyPy's distutils.sysconfig or it simply is # no longer available on the system (IOError ENOENT) makefile = {} extras_paths = filter( None, makefile.get("EXTRASPATH", "").split(":") ) # type: Iterable[str] for path in extras_paths: yield os.path.join(standard_lib, path) # Handle .pth injected paths as extras. sitedirs = cls._get_site_packages() for pth_path in cls._scan_pth_files(sitedirs): TRACER.log("Found .pth file: %s" % pth_path, V=3) for extras_path in iter_pth_paths(pth_path): yield extras_path
def get_flags_linker_so(self): opt = self.linker_so[1:] if sys.platform == 'darwin': target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None) # If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value # and leave it alone. But, distutils will complain if the # environment's value is different from the one in the Python # Makefile used to build Python. We let disutils handle this # error checking. if not target: # If MACOSX_DEPLOYMENT_TARGET is not set in the environment, # we try to get it first from the Python Makefile and then we # fall back to setting it to 10.3 to maximize the set of # versions we can work with. This is a reasonable default # even when using the official Python dist and those derived # from it. import distutils.sysconfig as sc g = {} filename = sc.get_makefile_filename() sc.parse_makefile(filename, g) target = g.get('MACOSX_DEPLOYMENT_TARGET', '10.3') os.environ['MACOSX_DEPLOYMENT_TARGET'] = target opt.extend(['-undefined', 'dynamic_lookup', '-dynamic']) return opt
def _guess_toolchain_kwargs_from_python_config(): def strip_prefix(pfx, value): if value.startswith(pfx): return value[len(pfx):] else: return value from distutils.sysconfig import parse_makefile, get_makefile_filename make_vars = parse_makefile(get_makefile_filename()) cc_cmdline = (make_vars["CXX"].split() + make_vars["CFLAGS"].split() + make_vars["CFLAGSFORSHARED"].split()) object_suffix = '.' + make_vars['MODOBJS'].split()[0].split('.')[1] from os.path import join cflags = [] defines = [] undefines = [] for cflag in cc_cmdline[1:]: if cflag.startswith("-D"): defines.append(cflag[2:]) elif cflag.startswith("-U"): undefines.append(cflag[2:]) else: cflags.append(cflag) # on Mac OS X, "libraries" can also be "frameworks" libraries = [] for lib in make_vars["LIBS"].split(): if lib.startswith("-l"): libraries.append(strip_prefix("-l", lib)) else: cflags.append(lib) # need to add a workaround for bug at # http://bugs.python.org/issue3588 if "PYTHONFRAMEWORKPREFIX" in make_vars: cflags.append("-F"+make_vars["PYTHONFRAMEWORKPREFIX"]) return dict( cc=cc_cmdline[0], ld=make_vars["LDSHARED"].split()[0], cflags=cflags, ldflags=( make_vars["LDSHARED"].split()[1:] + make_vars["LINKFORSHARED"].split() ), libraries=libraries, include_dirs=[ make_vars["INCLUDEPY"] ], library_dirs=[make_vars["LIBDIR"]], so_ext=make_vars["SO"], o_ext=object_suffix, defines=defines, undefines=undefines, )
def _extras_paths(cls): standard_lib = sysconfig.get_python_lib(standard_lib=True) try: makefile = sysconfig.parse_makefile(sysconfig.get_makefile_filename()) except (AttributeError, IOError): # This is not available by default in PyPy's distutils.sysconfig or it simply is # no longer available on the system (IOError ENOENT) makefile = {} extras_paths = filter(None, makefile.get('EXTRASPATH', '').split(':')) for path in extras_paths: yield os.path.join(standard_lib, path)
def test_srcdir(self): srcdir = sysconfig.get_config_var('srcdir') self.assertTrue(os.path.isabs(srcdir), srcdir) self.assertTrue(os.path.isdir(srcdir), srcdir) if sysconfig.python_build: Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) self.assertTrue(sysconfig._is_python_source_dir(srcdir)) elif os.name == 'posix': self.assertEqual( os.path.dirname(sysconfig.get_makefile_filename()), srcdir)
def _guess_toolchain_kwargs_from_python_config(): def strip_prefix(pfx, value): if value.startswith(pfx): return value[len(pfx):] else: return value from distutils.sysconfig import parse_makefile, get_makefile_filename make_vars = parse_makefile(get_makefile_filename()) cc_cmdline = (make_vars["CXX"].split() + make_vars["CFLAGS"].split() + make_vars["CFLAGSFORSHARED"].split()) object_names = [ oname for oname in make_vars['OBJECT_OBJS'].split() if "(" not in oname and ")" not in oname ] object_suffix = '.' + object_names[0].split('.')[1] cflags = [] defines = [] undefines = [] for cflag in cc_cmdline[1:]: if cflag.startswith("-D"): defines.append(cflag[2:]) elif cflag.startswith("-U"): undefines.append(cflag[2:]) else: cflags.append(cflag) # on Mac OS X, "libraries" can also be "frameworks" libraries = [] for lib in make_vars["LIBS"].split(): if lib.startswith("-l"): libraries.append(strip_prefix("-l", lib)) else: cflags.append(lib) return dict( cc=cc_cmdline[0], ld=make_vars["LDSHARED"].split()[0], cflags=cflags, ldflags=(make_vars["LDSHARED"].split()[1:] + make_vars["LINKFORSHARED"].split()), libraries=libraries, include_dirs=[make_vars["INCLUDEPY"]], library_dirs=[make_vars["LIBDIR"]], so_ext=make_vars["SO"] if 'SO' in make_vars else '.so', o_ext=object_suffix, defines=defines, undefines=undefines, )
def main(): global verbose if '-q' in sys.argv or '-quiet' in sys.argv: verbose = False if verbose: print 'Fixing Python locations in directory: %r' % bin_dir for fname in os.listdir(bin_dir): fix_script(join(bin_dir, fname)) from distutils.sysconfig import get_makefile_filename fix_makefile(get_makefile_filename())
def test_srcdir(self): # See Issues #15322, #15364. srcdir = sysconfig.get_config_var('srcdir') self.assertTrue(os.path.isabs(srcdir), srcdir) self.assertTrue(os.path.isdir(srcdir), srcdir) if sysconfig.python_build: # The python executable has not been installed so srcdir # should be a full source checkout. Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) self.assertTrue(sysconfig._is_python_source_dir(srcdir)) elif os.name == 'posix': self.assertEqual( os.path.dirname(sysconfig.get_makefile_filename()), srcdir)
def test_srcdir(self): # See Issues #15322, #15364. srcdir = sysconfig.get_config_var('srcdir') self.assertTrue(os.path.isabs(srcdir), srcdir) self.assertTrue(os.path.isdir(srcdir), srcdir) if sysconfig.python_build: # The python executable has not been installed so srcdir # should be a full source checkout. Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) self.assertTrue(sysconfig._is_python_source_dir(srcdir)) elif os.name == 'posix': self.assertEqual(os.path.dirname(sysconfig.get_makefile_filename()), srcdir)
def _guess_toolchain_kwargs_from_python_config(): def strip_prefix(pfx, value): if value.startswith(pfx): return value[len(pfx):] else: return value from distutils.sysconfig import parse_makefile, get_makefile_filename make_vars = parse_makefile(get_makefile_filename()) cc_cmdline = (make_vars["CXX"].split() + make_vars["CFLAGS"].split() + make_vars["CFLAGSFORSHARED"].split()) object_suffix = '.' + make_vars['MODOBJS'].split()[0].split('.')[1] from os.path import join cflags = [] defines = [] undefines = [] for cflag in cc_cmdline[1:]: if cflag.startswith("-D"): defines.append(cflag[2:]) elif cflag.startswith("-U"): undefines.append(cflag[2:]) else: cflags.append(cflag) return dict( cc=cc_cmdline[0], ld=make_vars["LDSHARED"].split()[0], cflags=cflags, ldflags=( make_vars["LDSHARED"].split()[1:] + make_vars["LINKFORSHARED"].split() ), libraries=[strip_prefix("-l", lib) for lib in make_vars["LIBS"].split()], include_dirs=[ make_vars["INCLUDEPY"] ], library_dirs=[make_vars["LIBDIR"]], so_ext=make_vars["SO"], o_ext=object_suffix, defines=defines, undefines=undefines, )
def fix_makefile(): # fix paths in Makefile if os.name == "posix": # ensure python Makefile exists where expected makefile = get_makefile_filename() if not os.path.exists(makefile): print "PyMEL setup: Makefile not found: %s. Attempting to correct" % makefile libdir = get_python_lib(plat_specific=1, standard_lib=1) zipinstall = os.path.join(dirname(maya_bin_dir), "lib", "python%s%s.zip" % sys.version_info[0:2]) if os.path.exists(zipinstall): try: # extract the Makefile zip = ZipFile(zipinstall, "r") # remove libdir zipmakefile = makefile.replace(libdir + os.sep, "") data = zip.read(zipmakefile) os.makedirs(dirname(makefile)) f = open(makefile, "w") f.write(fix_makefile_prefix(data)) f.close() print "PyMEL setup: successfully extracted Makefile from zip install into proper location" return except Exception, e: import traceback print "PyMEL setup: an error occurred while trying to fix the Makefile" traceback.print_exc(e) else: print "PyMEL setup: cannot fix Makefile. zip install was not found: %s" % zipinstall print ( "distutils will most likely fail, complaining that this is an invalid python install. PyMEL setup\n" + "was unable to properly correct the problem. The root problem is that your python Makefile is missing" ) else: f = open(makefile, "r") data = f.read() f.close() try: f = open(makefile, "w") f.write(fix_makefile_prefix(data)) except Exception, e: import traceback print "PyMEL setup: an error occurred while trying to fix the Makefile" traceback.print_exc(e) finally:
def fix_makefile(): # fix paths in Makefile if os.name == 'posix': # ensure python Makefile exists where expected makefile = get_makefile_filename() if not os.path.exists(makefile): print "PyMEL setup: Makefile not found: %s. Attempting to correct" % makefile libdir = get_python_lib(plat_specific=1, standard_lib=1) zipinstall = os.path.join(dirname(maya_bin_dir), 'lib', 'python%s%s.zip' % sys.version_info[0:2]) if os.path.exists(zipinstall): try: # extract the Makefile zip = ZipFile(zipinstall, 'r') # remove libdir zipmakefile = makefile.replace(libdir + os.sep, '') data = zip.read(zipmakefile) os.makedirs(dirname(makefile)) f = open(makefile, 'w') f.write(fix_makefile_prefix(data)) f.close() print "PyMEL setup: successfully extracted Makefile from zip install into proper location" return except Exception, e: import traceback print "PyMEL setup: an error occurred while trying to fix the Makefile" traceback.print_exc(e) else: print "PyMEL setup: cannot fix Makefile. zip install was not found: %s" % zipinstall print( "distutils will most likely fail, complaining that this is an invalid python install. PyMEL setup\n" + "was unable to properly correct the problem. The root problem is that your python Makefile is missing" ) else: f = open(makefile, 'r') data = f.read() f.close() try: f = open(makefile, 'w') f.write(fix_makefile_prefix(data)) except Exception, e: import traceback print "PyMEL setup: an error occurred while trying to fix the Makefile" traceback.print_exc(e) finally:
def _guess_toolchain_kwargs_from_python_config(): def strip_prefix(pfx, value): if value.startswith(pfx): return value[len(pfx):] else: return value from distutils.sysconfig import parse_makefile, get_makefile_filename make_vars = parse_makefile(get_makefile_filename()) cc_cmdline = (make_vars["CXX"].split() + make_vars["CFLAGS"].split() + make_vars["CFLAGSFORSHARED"].split()) object_suffix = '.' + make_vars['MODOBJS'].split()[0].split('.')[1] from os.path import join cflags = [] defines = [] undefines = [] for cflag in cc_cmdline[1:]: if cflag.startswith("-D"): defines.append(cflag[2:]) elif cflag.startswith("-U"): undefines.append(cflag[2:]) else: cflags.append(cflag) return dict( cc=cc_cmdline[0], ld=make_vars["LDSHARED"].split()[0], cflags=cflags, ldflags=(make_vars["LDSHARED"].split()[1:] + make_vars["LINKFORSHARED"].split()), libraries=[ strip_prefix("-l", lib) for lib in make_vars["LIBS"].split() ], include_dirs=[make_vars["INCLUDEPY"]], library_dirs=[make_vars["LIBDIR"]], so_ext=make_vars["SO"], o_ext=object_suffix, defines=defines, undefines=undefines, )
def _extras_paths(cls): standard_lib = sysconfig.get_python_lib(standard_lib=True) try: makefile = sysconfig.parse_makefile(sysconfig.get_makefile_filename()) except (AttributeError, IOError): # This is not available by default in PyPy's distutils.sysconfig or it simply is # no longer available on the system (IOError ENOENT) makefile = {} extras_paths = filter(None, makefile.get('EXTRASPATH', '').split(':')) for path in extras_paths: yield os.path.join(standard_lib, path) # Handle .pth injected paths as extras. sitedirs = cls._get_site_packages() for pth_path in cls._scan_pth_files(sitedirs): TRACER.log('Found .pth file: %s' % pth_path, V=3) for extras_path in iter_pth_paths(pth_path): yield extras_path
def test_srcdir(self): # See Issues #15322, #15364. srcdir = sysconfig.get_config_var('srcdir') self.assertTrue(os.path.isabs(srcdir), srcdir) self.assertTrue(os.path.isdir(srcdir), srcdir) if sysconfig.python_build: # The python executable has not been installed so srcdir # should be a full source checkout. Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) # <srcdir>/PC/pyconfig.h always exists even if unused on POSIX. pyconfig_h = os.path.join(srcdir, 'PC', 'pyconfig.h') self.assertTrue(os.path.exists(pyconfig_h), pyconfig_h) pyconfig_h_in = os.path.join(srcdir, 'pyconfig.h.in') self.assertTrue(os.path.exists(pyconfig_h_in), pyconfig_h_in) elif os.name == 'posix': self.assertEqual( os.path.dirname(sysconfig.get_makefile_filename()), srcdir)
def get_flags_linker_so(self): opt = self.linker_so[1:] if sys.platform == "darwin": target = os.environ.get("MACOSX_DEPLOYMENT_TARGET", None) # If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value # and leave it alone. But, distutils will complain if the # environment's value is different from the one in the Python # Makefile used to build Python. We let disutils handle this # error checking. if not target: # If MACOSX_DEPLOYMENT_TARGET is not set in the environment, # we try to get it first from the Python Makefile and then we # fall back to setting it to 10.3 to maximize the set of # versions we can work with. This is a reasonable default # even when using the official Python dist and those derived # from it. import distutils.sysconfig as sc g = {} filename = sc.get_makefile_filename() sc.parse_makefile(filename, g) target = g.get("MACOSX_DEPLOYMENT_TARGET", "10.3") os.environ["MACOSX_DEPLOYMENT_TARGET"] = target if target == "10.3": s = "Env. variable MACOSX_DEPLOYMENT_TARGET set to 10.3" warnings.warn(s) opt.extend(["-undefined", "dynamic_lookup", "-bundle"]) else: opt.append("-shared") if sys.platform.startswith("sunos"): # SunOS often has dynamically loaded symbols defined in the # static library libg2c.a The linker doesn't like this. To # ignore the problem, use the -mimpure-text flag. It isn't # the safest thing, but seems to work. 'man gcc' says: # ".. Instead of using -mimpure-text, you should compile all # source code with -fpic or -fPIC." opt.append("-mimpure-text") return opt
def get_flags_linker_so(self): opt = self.linker_so[1:] if sys.platform == 'darwin': target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None) # If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value # and leave it alone. But, distutils will complain if the # environment's value is different from the one in the Python # Makefile used to build Python. We let disutils handle this # error checking. if not target: # If MACOSX_DEPLOYMENT_TARGET is not set in the environment, # we try to get it first from the Python Makefile and then we # fall back to setting it to 10.3 to maximize the set of # versions we can work with. This is a reasonable default # even when using the official Python dist and those derived # from it. import distutils.sysconfig as sc g = {} if '__pypy__' not in sys.builtin_module_names: filename = sc.get_makefile_filename() sc.parse_makefile(filename, g) target = g.get('MACOSX_DEPLOYMENT_TARGET', '10.3') os.environ['MACOSX_DEPLOYMENT_TARGET'] = target if target == '10.3': s = 'Env. variable MACOSX_DEPLOYMENT_TARGET set to 10.3' warnings.warn(s) opt.extend(['-undefined', 'dynamic_lookup', '-bundle']) else: opt.append("-shared") if sys.platform.startswith('sunos'): # SunOS often has dynamically loaded symbols defined in the # static library libg2c.a The linker doesn't like this. To # ignore the problem, use the -mimpure-text flag. It isn't # the safest thing, but seems to work. 'man gcc' says: # ".. Instead of using -mimpure-text, you should compile all # source code with -fpic or -fPIC." opt.append('-mimpure-text') return opt
# # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- # distutils module requires Makefile and pyconfig.h files from Python # installation. import os import sys import time from distutils import sysconfig config_h = sysconfig.get_config_h_filename() print(('pyconfig.h: ' + config_h)) files = [config_h] # On Windows Makefile does not exist. if not sys.platform.startswith('win'): makefile = sysconfig.get_makefile_filename() print(('Makefile: ' + makefile)) files.append(makefile) for f in files: if not os.path.exists(f): raise SystemExit('File does not exist: %s' % f)
sys.exit(1) try: from distutils.core import Command from distutils.errors import DistutilsPlatformError from distutils.sysconfig import get_makefile_filename except ImportError, e: print "\nUh oh. You have Python installed, but I didn't find the distutils" print "module, which is supposed to come with the standard library.\n" requirePythonDev() try: # This catches failures to install python2-dev on some redhats. get_makefile_filename() except IOError: print "\nUh oh. You have Python installed, but distutils can't find the" print "Makefile it needs to build additional Python components.\n" requirePythonDev() #====================================================================== # Now, tell setup.py how to cope. import distutils.core, distutils.command.install from distutils.core import setup, Distribution class InstallCommand(distutils.command.install.install): def run(self): script_path = None sys_path = map(os.path.normpath, sys.path)
def test_get_makefile_filename(self): makefile = sysconfig.get_makefile_filename() self.assertTrue(os.path.isfile(makefile), makefile)
(options, args) = p.parse_args() from distutils import sysconfig sysconfig.PREFIX = '@PREFIX@' sysconfig.EXEC_PREFIX = '@PREFIX@' if options.prefix: sysconfig.EXEC_PREFIX = options.prefix sysconfig.PREFIX = options.prefix if options.cflags: sys.stdout.write('-I%s\n' % sysconfig.get_python_inc()) if options.ldflags: extra = "@EXTRA_LDFLAGS@" if 0: mf = sysconfig.get_makefile_filename() d = sysconfig.parse_makefile(mf) if options.verbose: sys.stderr.write(mf + '\n') # Using flags from native python build is asking for trouble, # ie, arch or $$ORIGIN may break things. extra = d['LDFLAGS'] sys.stdout.write( '-L%s -L%s %s\n' % (sysconfig.get_python_lib(), sysconfig.PREFIX + '/lib/', extra)) ## -*-Python-*-
try: from distutils.core import Command from distutils.errors import DistutilsPlatformError from distutils.sysconfig import get_makefile_filename except ImportError, e: print "\nUh oh. You have Python installed, but I didn't find the distutils" print "module, which is supposed to come with the standard library.\n" requirePythonDev() if 'py2exe' in sys.argv: import py2exe try: # This catches failures to install python2-dev on some recent Redhats. mf = get_makefile_filename() print mf except IOError: print "\nUh oh. You have Python installed, but distutils can't find the" print "Makefile it needs to build additional Python components.\n" requirePythonDev() class runMMCommand(Command): # Based on setup.py from Zooko's pyutil package, which is in turn based on # http://mail.python.org/pipermail/distutils-sig/2002-January/002714.html description = "Run a subcommand from mixminion.Main" user_options = [ ('subcommand=', None, 'Subcommand to run')]