def copy_python_framework(info, dst): # XXX - In this particular case we know exactly what we can # get away with.. should this be extended to the general # case? Per-framework recipes? indir = os.path.dirname(os.path.join(info["location"], info["name"])) outdir = os.path.dirname(os.path.join(dst, info["name"])) mkpath(os.path.join(outdir, "Resources")) # Since python 3.2, the naming scheme for config files location has considerably # complexified. The old, simple way doesn't work anymore. Fortunately, a new module was # added to get such paths easily. # It's possible that virtualenv is messing with us here, so we only use the rightmost part of # each of the two paths below. For pyconfig_path, it's the last 3 elements of the path # (include/python3.2m/pyconfig.h) and for makefile_path it's the last 4 # (lib/python3.2/config-3.2m/Makefile). Yes, this kind of location can change depending on the # platform, but we're only supporting Mac OS X eh? We'll take these last path parts and append # them to indir and we'll have our non-virtualenv paths. pyconfig_path = sysconfig.get_config_h_filename() makefile_path = sysconfig.get_makefile_filename() pyconfig_path = op.join(*pyconfig_path.split(os.sep)[-3:]) makefile_path = op.join(*makefile_path.split(os.sep)[-4:]) assert pyconfig_path.startswith("include") assert makefile_path.startswith("lib") # distutils looks for some files relative to sys.executable, which # means they have to be in the framework... mkpath(op.join(outdir, op.dirname(pyconfig_path))) mkpath(op.join(outdir, op.dirname(makefile_path))) fmwkfiles = [os.path.basename(info["name"]), "Resources/Info.plist", pyconfig_path, makefile_path] for fn in fmwkfiles: copy_file(os.path.join(indir, fn), os.path.join(outdir, fn))
def clean_makefile(): import sys, os, sysconfig build_path = sys.argv[1] makefile = sysconfig.get_makefile_filename() save_name = makefile + ".save" os.rename(makefile, save_name) with open(save_name) as input, open(makefile, "w") as output: for line in input: output.write(clean_make_line(line, build_path))
def build_executable(self, target, copyexts, script): # Build an executable for the target appdir, resdir, plist = self.create_bundle(target, script) self.appdir = appdir self.opts.plist = plist for src, dest in self.iter_data_files(): dest = os.path.join(resdir, dest) mkpath(os.path.dirname(dest)) copy_resource(src, dest, dry_run=self.opts.dry_run) bootfn = '__boot__' bootfile = open(os.path.join(resdir, bootfn + '.py'), 'w') for fn in target.prescripts: bootfile.write(get_bootstrap_data(fn)) bootfile.write('\n\n') bootfile.write('_run(%r)\n' % (os.path.basename(script), )) bootfile.close() copy_file(script, resdir) pydir = os.path.join(resdir, 'lib', 'python' + sys.version[:3]) mkpath(pydir) force_symlink('../../site.py', os.path.join(pydir, 'site.py')) realcfg = os.path.dirname(sysconfig.get_makefile_filename()) cfgdir = os.path.join(resdir, os.path.relpath(realcfg, sys.prefix)) mkpath(cfgdir) for fn in 'Makefile', 'Setup', 'Setup.local', 'Setup.config': rfn = os.path.join(realcfg, fn) if os.path.exists(rfn): copy_file(rfn, os.path.join(cfgdir, fn)) # see copy_python_framework() for explanation. pyconfig_path = sysconfig.get_config_h_filename() pyconfig_path_relative = os.path.relpath( os.path.dirname(pyconfig_path), sys.prefix) inc_dir = os.path.join(resdir, pyconfig_path_relative) mkpath(inc_dir) copy_file(pyconfig_path, os.path.join(inc_dir, 'pyconfig.h')) copy_tree(self.folders.collect_dir, pydir) ext_dir = os.path.join(pydir, os.path.basename(self.folders.ext_dir)) copy_tree(self.folders.ext_dir, ext_dir, preserve_symlinks=True) copy_tree(self.folders.framework_dir, os.path.join(appdir, 'Contents', 'Frameworks'), preserve_symlinks=True) for pkg in self.opts.packages: pkg = get_bootstrap(pkg) dst = os.path.join(pydir, os.path.basename(pkg)) mkpath(dst) copy_tree(pkg, dst) self.copyexts(copyexts, ext_dir) target.appdir = appdir return appdir
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 build_executable(self, target, copyexts, script): # Build an executable for the target appdir, resdir, plist = self.create_bundle(target, script) self.appdir = appdir self.opts.plist = plist for src, dest in self.iter_data_files(): dest = os.path.join(resdir, dest) mkpath(os.path.dirname(dest)) copy_resource(src, dest, dry_run=self.opts.dry_run) bootfn = "__boot__" bootfile = open(os.path.join(resdir, bootfn + ".py"), "w") for fn in target.prescripts: bootfile.write(get_bootstrap_data(fn)) bootfile.write("\n\n") bootfile.write("_run(%r)\n" % (os.path.basename(script),)) bootfile.close() copy_file(script, resdir) pydir = os.path.join(resdir, "lib", "python" + sys.version[:3]) mkpath(pydir) force_symlink("../../site.py", os.path.join(pydir, "site.py")) realcfg = os.path.dirname(sysconfig.get_makefile_filename()) cfgdir = os.path.join(resdir, os.path.relpath(realcfg, sys.prefix)) mkpath(cfgdir) for fn in "Makefile", "Setup", "Setup.local", "Setup.config": rfn = os.path.join(realcfg, fn) if os.path.exists(rfn): copy_file(rfn, os.path.join(cfgdir, fn)) # see copy_python_framework() for explanation. pyconfig_path = sysconfig.get_config_h_filename() pyconfig_path_relative = os.path.relpath(os.path.dirname(pyconfig_path), sys.prefix) inc_dir = os.path.join(resdir, pyconfig_path_relative) mkpath(inc_dir) copy_file(pyconfig_path, os.path.join(inc_dir, "pyconfig.h")) copy_tree(self.folders.collect_dir, pydir) ext_dir = os.path.join(pydir, os.path.basename(self.folders.ext_dir)) copy_tree(self.folders.ext_dir, ext_dir, preserve_symlinks=True) copy_tree(self.folders.framework_dir, os.path.join(appdir, "Contents", "Frameworks"), preserve_symlinks=True) for pkg in self.opts.packages: pkg = get_bootstrap(pkg) dst = os.path.join(pydir, os.path.basename(pkg)) mkpath(dst) copy_tree(pkg, dst) self.copyexts(copyexts, ext_dir) target.appdir = appdir return appdir
def copy_sysconfig_files_for_embed(destpath): # This normally shouldn't be needed for Python 3.3+. makefile = sysconfig.get_makefile_filename() configh = sysconfig.get_config_h_filename() shutil.copy(makefile, destpath) shutil.copy(configh, destpath) with open(op.join(destpath, 'site.py'), 'w') as fp: fp.write(""" import os.path as op from distutils import sysconfig sysconfig.get_makefile_filename = lambda: op.join(op.dirname(__file__), 'Makefile') sysconfig.get_config_h_filename = lambda: op.join(op.dirname(__file__), 'pyconfig.h') """)
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 test_sysconfig_symlinks(self): """ Test that the sysconfig functions work in a virtual environment. """ rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir, symlinks=True) envpy = os.path.join(self.env_dir, self.bindir, self.exe) cmd = [envpy, '-c', None] for call, expected in ( # installation scheme ('get_preferred_scheme("prefix")', 'venv'), ('get_default_scheme()', 'venv'), # build environment ('is_python_build()', str(sysconfig.is_python_build())), ('get_makefile_filename()', sysconfig.get_makefile_filename()), ('get_config_h_filename()', sysconfig.get_config_h_filename())): with self.subTest(call): cmd[2] = 'import sysconfig; print(sysconfig.%s)' % call out, err = check_output(cmd) self.assertEqual(out.strip(), expected.encode(), err)
def copy_python_framework(info, dst): # XXX - In this particular case we know exactly what we can # get away with.. should this be extended to the general # case? Per-framework recipes? indir = os.path.dirname(os.path.join(info['location'], info['name'])) outdir = os.path.dirname(os.path.join(dst, info['name'])) mkpath(os.path.join(outdir, 'Resources')) # Since python 3.2, the naming scheme for config files location has considerably # complexified. The old, simple way doesn't work anymore. Fortunately, a new module was # added to get such paths easily. # It's possible that virtualenv is messing with us here, so we only use the rightmost part of # each of the two paths below. For pyconfig_path, it's the last 3 elements of the path # (include/python3.2m/pyconfig.h) and for makefile_path it's the last 4 # (lib/python3.2/config-3.2m/Makefile). Yes, this kind of location can change depending on the # platform, but we're only supporting Mac OS X eh? We'll take these last path parts and append # them to indir and we'll have our non-virtualenv paths. pyconfig_path = sysconfig.get_config_h_filename() makefile_path = sysconfig.get_makefile_filename() pyconfig_path = op.join(*pyconfig_path.split(os.sep)[-3:]) makefile_path = op.join(*makefile_path.split(os.sep)[-4:]) assert pyconfig_path.startswith('include') assert makefile_path.startswith('lib') # distutils looks for some files relative to sys.executable, which # means they have to be in the framework... mkpath(op.join(outdir, op.dirname(pyconfig_path))) mkpath(op.join(outdir, op.dirname(makefile_path))) fmwkfiles = [ os.path.basename(info['name']), 'Resources/Info.plist', pyconfig_path, makefile_path, ] for fn in fmwkfiles: copy_file(os.path.join(indir, fn), os.path.join(outdir, fn))
def test_get_makefile_filename(self): makefile = sysconfig.get_makefile_filename() self.assertTrue(os.path.isfile(makefile), makefile)
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- # The 'sysconfig' module requires Makefile and pyconfig.h files from # Python installation. 'sysconfig' parses these files to get some # information from them. # TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3. import sysconfig import os from PyInstaller.utils.hooks import relpath_to_config_or_make from PyInstaller.compat import is_win _CONFIG_H = sysconfig.get_config_h_filename() _MAKEFILE = sysconfig.get_makefile_filename() datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))] # The Makefile does not exist on all platforms, eg. on Windows if os.path.exists(_MAKEFILE): datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE))) if not is_win and hasattr(sysconfig, '_get_sysconfigdata_name'): # Python 3.6 uses additional modules like # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417 # Note: Some versions of Anaconda backport this feature to before 3.6. # See issue #3105 hiddenimports = [sysconfig._get_sysconfigdata_name()]
#----------------------------------------------------------------------------- """ `distutils`-specific post-import hook. This hook freezes the external `Makefile` and `pyconfig.h` files bundled with the active Python interpreter, which the `distutils.sysconfig` module parses at runtime for platform-specific metadata. """ # TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3. import os import sysconfig from PyInstaller.utils.hooks import relpath_to_config_or_make _CONFIG_H = sysconfig.get_config_h_filename() if hasattr(sysconfig, 'get_makefile_filename'): # sysconfig.get_makefile_filename is missing in Python < 2.7.9 _MAKEFILE = sysconfig.get_makefile_filename() else: _MAKEFILE = sysconfig._get_makefile_filename() # Data files in PyInstaller hook format. datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))] # The Makefile does not exist on all platforms, eg. on Windows if os.path.exists(_MAKEFILE): datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))
# Copyright (c) 2005-2021, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- # distutils module requires Makefile and pyconfig.h files from Python # installation. import os import sys 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)
print(sysconfig.get_config_var('LIBDIR')) print(sysconfig.get_config_vars('posix_home', 'prefix')) print(sysconfig.get_config_vars()) print(sysconfig.get_scheme_names()) """ stdlib: directory containing the standard Python library files that are not platform-specific. platstdlib: directory containing the standard Python library files that are platform-specific. platlib: directory for site-specific, platform-specific files. purelib: directory for site-specific, non-platform-specific files. include: directory for non-platform-specific header files. platinclude: directory for platform-specific header files. scripts: directory for script files. data: directory for data files. """ print(sysconfig.get_path_names()) print(sysconfig.get_path("data")) print(sysconfig.get_paths("nt")) print(sysconfig.get_python_version()) print(sysconfig.get_platform()) print(sysconfig.is_python_build()) print(sysconfig.get_config_h_filename()) print(sysconfig.get_makefile_filename())
def update_event(self, inp=-1): self.set_output_val(0, sysconfig.get_makefile_filename())
def test_get_makefile_filename(self): makefile = sysconfig.get_makefile_filename() self.assertTrue(os.path.isfile(makefile), makefile) # Issue 22199 self.assertEqual(sysconfig._get_makefile_filename(), makefile)
def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" return sysconfig.get_makefile_filename()
# for distributing bootloader. # # 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 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)
def run(): """print debug data about the virtual environment""" try: from collections import OrderedDict except ImportError: # pragma: no cover # this is possible if the standard library cannot be accessed # noinspection PyPep8Naming OrderedDict = dict # pragma: no cover result = OrderedDict([("sys", OrderedDict())]) path_keys = ( "executable", "_base_executable", "prefix", "base_prefix", "real_prefix", "exec_prefix", "base_exec_prefix", "path", "meta_path", ) for key in path_keys: value = getattr(sys, key, None) if isinstance(value, list): value = encode_list_path(value) else: value = encode_path(value) result["sys"][key] = value result["sys"]["fs_encoding"] = sys.getfilesystemencoding() result["sys"]["io_encoding"] = getattr(sys.stdout, "encoding", None) result["version"] = sys.version try: import sysconfig result["makefile_filename"] = encode_path( sysconfig.get_makefile_filename()) except ImportError: pass import os # landmark result["os"] = repr(os) try: # noinspection PyUnresolvedReferences import site # site result["site"] = repr(site) except ImportError as exception: # pragma: no cover result["site"] = repr(exception) # pragma: no cover try: # noinspection PyUnresolvedReferences import datetime # site result["datetime"] = repr(datetime) except ImportError as exception: # pragma: no cover result["datetime"] = repr(exception) # pragma: no cover try: # noinspection PyUnresolvedReferences import math # site result["math"] = repr(math) except ImportError as exception: # pragma: no cover result["math"] = repr(exception) # pragma: no cover # try to print out, this will validate if other core modules are available (json in this case) try: import json result["json"] = repr(json) except ImportError as exception: result["json"] = repr(exception) else: try: content = json.dumps(result, indent=2) sys.stdout.write(content) except (ValueError, TypeError) as exception: # pragma: no cover sys.stderr.write(repr(exception)) sys.stdout.write(repr(result)) # pragma: no cover raise SystemExit(1) # pragma: no cover