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': makefile_dir = os.path.dirname(sysconfig.get_makefile_filename()) makefile_dir = os.path.realpath(makefile_dir) self.assertEqual(makefile_dir, 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 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": makefile_dir = os.path.dirname(sysconfig.get_makefile_filename()) # Issue #19340: srcdir has been realpath'ed already makefile_dir = os.path.realpath(makefile_dir) self.assertEqual(makefile_dir, srcdir)
def update_event(self, inp=-1): self.set_output_val(0, sysconfig._is_python_source_dir(self.input(0)))
def find_host_python(self, host): """ Find Python paths and other info based on a path. :param host: Path to the host Python executable. """ build_version = sysconfig.get_config_var('VERSION') host = os.path.abspath(host) if not os.path.exists(host): raise FileNotFoundError("%s does not exist" % host) elif not os.path.isfile(host): raise ValueError("Expected a path to a Python executable. " "Got %s" % host) else: self.host_project_base = os.path.dirname(host) if sysconfig._is_python_source_dir(self.host_project_base): self.host_makefile = os.path.join(self.host_project_base, 'Makefile') pybuilddir = os.path.join(self.host_project_base, 'pybuilddir.txt') try: with open(pybuilddir, 'r') as fp: build_dir = fp.read().strip() except IOError: raise IOError("Cannot read %s: Build the host Python first " % s) from None self.host_home = self.host_project_base sysconfig_paths = [os.path.join(self.host_project_base, build_dir)] else: self.host_home = self.find_installed_host_home() python_ver = 'python' + sysconfig.get_config_var( 'py_version_short') libdir = os.path.join(self.host_home, 'lib', python_ver) sysconfig_paths = [ libdir, # Ubuntu puts it in libdir/plat-<arch> os.path.join(libdir, '*'), # Below might be a version mismatch, but try to use it #os.path.join(self.host_home, 'lib', 'python*'), #os.path.join(self.host_home, 'lib', 'python*', '*'), ] makefile = glob.glob(os.path.join(libdir, '*', 'Makefile')) if not makefile: self.host_makefile = '' # fail later else: self.host_makefile = makefile[0] # We need paths to sysconfig data, and we need to import it to ask # a few questions. self.find_sysconfig_data(sysconfig_paths) # If the user wants to override host_cc, that takes precedence. host_cc = self.host_sysconfigdata.build_time_vars['CC'] self.real_host_cc = shlex.split(host_cc) if not self.host_cc: self.host_cc = self.real_host_cc if self.host_relativize: self.host_cc[0] = os.path.basename(self.host_cc[0]) # CC could be compound command, like 'gcc --sysroot=...' (Issue #5) # but that can cause issues (#7) so let the user know. if len(self.host_cc) > 1: logger.warning("CC is a compound command (%s)", self.host_cc) logger.warning("This can cause issues for modules that don't " "expect it.") logger.warning("Consider setting CC='%s' and CFLAGS='%s'", self.host_cc[0], ' '.join(self.host_cc[1:])) host_cxx = self.host_sysconfigdata.build_time_vars['CXX'] self.real_host_cxx = shlex.split(host_cxx) if not self.host_cxx: self.host_cxx = self.real_host_cxx if self.host_relativize: self.host_cxx[0] = os.path.basename(self.host_cxx[0]) if len(self.host_cxx) > 1: logger.warning("CXX is a compound command (%s)", self.host_cxx) logger.warning("This can cause issues for modules that don't " "expect it.") logger.warning("Consider setting CXX='%s' and CXXFLAGS='%s'", self.host_cxx[0], ' '.join(self.host_cxx[1:])) host_ar = self.host_sysconfigdata.build_time_vars['AR'] self.real_host_ar = shlex.split(host_ar) if not self.host_ar: self.host_ar = self.real_host_ar if self.host_relativize: self.host_ar[0] = os.path.basename(self.host_ar[0]) self.host_version = self.host_sysconfigdata.build_time_vars['VERSION'] # Ask the makefile a few questions too if not os.path.exists(self.host_makefile): raise FileNotFoundError("Cannot find Makefile") self.host_platform = sys.platform # Default: not actually cross compiling with open(self.host_makefile, 'r') as fp: lines = list(fp.readlines()) for line in lines: line = line.strip() if line.startswith('_PYTHON_HOST_PLATFORM='): host_platform = line.split('=', 1)[-1] if host_platform: self.host_platform = line.split('=', 1)[-1] break self.macosx_deployment_target = '' for line in lines: line = line.strip() if line.startswith('MACOSX_DEPLOYMENT_TARGET='): self.macosx_deployment_target = line.split('=', 1)[-1] break # Sanity checks if self.host_version != build_version: raise ValueError("Version mismatch: host=%s, build=%s" % (self.host_version, build_version))