def get_sysconfigdata(args: argparse.Namespace) -> pathlib.Path: """Get path to sysconfigdata relative to build root """ data_name = sysconfig._get_sysconfigdata_name() assert "emscripten_wasm32" in data_name filename = data_name + ".py" return args.builddir / filename
def check(cmd, mf): # As of Python 3.6 the sysconfig module # dynamically imports a module using the # __import__ function. m = mf.findNode("sysconfig") if m is not None: import sysconfig mf.import_hook(sysconfig._get_sysconfigdata_name(), m)
def get_sysconfigdata(args: argparse.Namespace) -> pathlib.Path: """Get path to sysconfigdata relative to build root """ data_name = sysconfig._get_sysconfigdata_name() if not data_name.startswith(SYSCONFIG_NAMES): raise ValueError(f"Invalid sysconfig data name '{data_name}'.", SYSCONFIG_NAMES) filename = data_name + ".py" return args.builddir / filename
def load_sysconfig(finder, module): """The sysconfig module implicitly loads _sysconfigdata.""" import sysconfig if hasattr(sysconfig, '_get_sysconfigdata_name'): if not hasattr(sys, "abiflags"): sys.abiflags = "" datafile = sysconfig._get_sysconfigdata_name() else: datafile = "_sysconfigdata" finder.IncludeModule(datafile)
def extend_imports(module): if module.name == 'sysconfig' and os.name == 'posix': import sysconfig if hasattr(sysconfig, '_get_sysconfigdata_name'): args = [] if getargspec(sysconfig._get_sysconfigdata_name).args: args = [True] sysconfig_name = sysconfig._get_sysconfigdata_name(*args) else: sysconfig_name = '_sysconfigdata' module.imports.append(sysconfig_name)
def check(cmd, mf): if sys.version_info[:2] >= (3, 6): # As of Python 3.6 the sysconfig module # dynamicly imports a module using the # __import__ function. m = mf.findNode('sysconfig') if m is not None: import sysconfig mf.import_hook(sysconfig._get_sysconfigdata_name(), m) else: return None
def clean_sysconfigdata(): import sys, sysconfig, os.path, pprint build_path = sys.argv[1] libdir = os.path.dirname(sysconfig.__file__) configdata = sysconfig._get_sysconfigdata_name() configpath = os.path.join(libdir, configdata + ".py") mod = __import__(configdata, globals(), locals(), ["build_time_vars"], 0) print("mod", configdata, mod) clean_vars = {} for key, value in mod.build_time_vars.items(): clean_vars[key] = clean_data_value(key, value, build_path) print("path", configpath) with open(configpath, "w") as output: print( "# system configuration generated and used by" " the sysconfig module", file=output) print("# cleaned as part of ChimeraX build", file=output) print("build_time_vars = ", file=output, end='') pprint.pprint(clean_vars, stream=output)
# 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()]
print (dep_path) continue dep_path = fix_path(dep_path) import sysconfig soabi = sysconfig.get_config_var('SOABI') # Check if its a shared library and deconstruct it if soabi in dep_path: if debug == True: log.write('Shared library found in %s\n' % dep_path) dep_path = dep_path.replace(soabi,'*') print (dep_path) continue if "_sysconfigdata" in dep_path: dep_path = dep_path.replace(sysconfig._get_sysconfigdata_name(), "_sysconfigdata*") if debug == True: log.write(dep_path+'\n') # Prints out result, which is what will be used by create_manifest print (dep_path) cpython_tag = sys.implementation.cache_tag cached = '' # Theres no naive way to find *.pyc files on python3 try: if debug == True: log.write('\nCalling: sys.modules[' + '%s' % item + '].__cached__\n') cached = sys.modules['%s' % item].__cached__ except AttributeError as e:
def update_event(self, inp=-1): self.set_output_val(0, sysconfig._get_sysconfigdata_name())
# 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_py36, is_win _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() 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 is_py36 and not is_win: # 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 hiddenimports = [sysconfig._get_sysconfigdata_name()]
def makewheel(version, output_dir, platform=None): if sys.platform not in ( "win32", "darwin") and not sys.platform.startswith("cygwin"): if not LocateBinary("patchelf"): raise Exception( "patchelf is required when building a Linux wheel.") if sys.version_info < (3, 6): raise Exception("Python 3.6 or higher is required to produce a wheel.") if platform is None: # Determine the platform from the build. platform_dat = os.path.join(output_dir, 'tmp', 'platform.dat') if os.path.isfile(platform_dat): platform = open(platform_dat, 'r').read().strip() else: print("Could not find platform.dat in build directory") platform = get_platform() if platform.startswith("linux-") and os.path.isdir("/opt/python"): # Is this manylinux? if os.path.isfile("/lib/libc-2.5.so") or os.path.isfile( "/lib64/libc-2.5.so"): platform = platform.replace("linux", "manylinux1") elif os.path.isfile("/lib/libc-2.12.so") or os.path.isfile( "/lib64/libc-2.12.so"): platform = platform.replace("linux", "manylinux2010") elif os.path.isfile("/lib/libc-2.17.so") or os.path.isfile( "/lib64/libc-2.17.so"): platform = platform.replace("linux", "manylinux2014") elif os.path.isfile( "/lib/i386-linux-gnu/libc-2.24.so") or os.path.isfile( "/lib/x86_64-linux-gnu/libc-2.24.so"): platform = platform.replace("linux", "manylinux_2_24") platform = platform.replace('-', '_').replace('.', '_') is_windows = platform == 'win32' \ or platform.startswith('win_') \ or platform.startswith('cygwin_') is_macosx = platform.startswith('macosx_') # Global filepaths panda3d_dir = join(output_dir, "panda3d") pandac_dir = join(output_dir, "pandac") direct_dir = join(output_dir, "direct") models_dir = join(output_dir, "models") etc_dir = join(output_dir, "etc") bin_dir = join(output_dir, "bin") if is_windows: libs_dir = join(output_dir, "bin") else: libs_dir = join(output_dir, "lib") ext_mod_dir = get_python_ext_module_dir() license_src = "LICENSE" readme_src = "README.md" # Update relevant METADATA entries METADATA['version'] = version # Build out the metadata details = METADATA["extensions"]["python.details"] homepage = details["project_urls"]["Home"] author = details["contacts"][0]["name"] email = details["contacts"][0]["email"] metadata = ''.join([ "Metadata-Version: {metadata_version}\n" \ "Name: {name}\n" \ "Version: {version}\n" \ "Summary: {summary}\n" \ "License: {license}\n".format(**METADATA), "Home-page: {0}\n".format(homepage), ] + ["Project-URL: {0}, {1}\n".format(*url) for url in PROJECT_URLS.items()] + [ "Author: {0}\n".format(author), "Author-email: {0}\n".format(email), "Platform: {0}\n".format(platform), ] + ["Classifier: {0}\n".format(c) for c in METADATA['classifiers']]) metadata += '\n' + DESCRIPTION.strip() + '\n' # Zip it up and name it the right thing whl = WheelFile('panda3d', version, platform) whl.lib_path = [libs_dir] if is_windows: whl.lib_path.append(ext_mod_dir) if platform.startswith("manylinux"): # On manylinux1, we pick up all libraries except for the ones specified # by the manylinux1 ABI. whl.lib_path.append("/usr/local/lib") if platform.endswith("_x86_64"): whl.lib_path += ["/lib64", "/usr/lib64"] else: whl.lib_path += ["/lib", "/usr/lib"] whl.ignore_deps.update(MANYLINUX_LIBS) # Add libpython for deployment. if is_windows: pylib_name = 'python{0}{1}.dll'.format(*sys.version_info) pylib_path = os.path.join(get_config_var('BINDIR'), pylib_name) elif is_macosx: pylib_name = 'libpython{0}.{1}.dylib'.format(*sys.version_info) pylib_path = os.path.join(get_config_var('LIBDIR'), pylib_name) else: pylib_name = get_config_var('LDLIBRARY') pylib_arch = get_config_var('MULTIARCH') libdir = get_config_var('LIBDIR') if pylib_arch and os.path.exists( os.path.join(libdir, pylib_arch, pylib_name)): pylib_path = os.path.join(libdir, pylib_arch, pylib_name) else: pylib_path = os.path.join(libdir, pylib_name) # If Python was linked statically, we don't need to include this. if not pylib_name.endswith('.a'): whl.write_file('deploy_libs/' + pylib_name, pylib_path) # Add the trees with Python modules. whl.write_directory('direct', direct_dir) # Write the panda3d tree. We use a custom empty __init__ since the # default one adds the bin directory to the PATH, which we don't have. p3d_init = """"Python bindings for the Panda3D libraries" __version__ = '{0}' """.format(version) if '27' in ABI_TAG: p3d_init += """ if __debug__: if 1 / 2 == 0: raise ImportError(\"Python 2 is not supported.\") """ whl.write_file_data('panda3d/__init__.py', p3d_init) # Copy the extension modules from the panda3d directory. ext_suffix = GetExtensionSuffix() for file in sorted(os.listdir(panda3d_dir)): if file == '__init__.py': pass elif file.endswith('.py') or (file.endswith(ext_suffix) and '.' not in file[:-len(ext_suffix)]): source_path = os.path.join(panda3d_dir, file) if file.endswith('.pyd') and platform.startswith('cygwin'): # Rename it to .dll for cygwin Python to be able to load it. target_path = 'panda3d/' + os.path.splitext(file)[0] + '.dll' elif file.endswith(ext_suffix) and platform.startswith('android'): # Strip the extension suffix on Android. target_path = 'panda3d/' + file[:-len(ext_suffix)] + '.so' else: target_path = 'panda3d/' + file whl.write_file(target_path, source_path) # And copy the extension modules from the Python installation into the # deploy_libs directory, for use by deploy-ng. ext_suffix = '.pyd' if is_windows else '.so' for file in sorted(os.listdir(ext_mod_dir)): if file.endswith(ext_suffix): if file.startswith('_tkinter.'): # Tkinter is supplied in a separate wheel. continue source_path = os.path.join(ext_mod_dir, file) if file.endswith('.pyd') and platform.startswith('cygwin'): # Rename it to .dll for cygwin Python to be able to load it. target_path = 'deploy_libs/' + os.path.splitext( file)[0] + '.dll' else: target_path = 'deploy_libs/' + file whl.write_file(target_path, source_path) # Include the special sysconfigdata module. if os.name == 'posix': import sysconfig if hasattr(sysconfig, '_get_sysconfigdata_name'): modname = sysconfig._get_sysconfigdata_name() + '.py' else: modname = '_sysconfigdata.py' for entry in sys.path: source_path = os.path.join(entry, modname) if os.path.isfile(source_path): whl.write_file('deploy_libs/' + modname, source_path) break # Add plug-ins. for lib in PLUGIN_LIBS: plugin_name = 'lib' + lib if is_windows: plugin_name += '.dll' elif is_macosx: plugin_name += '.dylib' else: plugin_name += '.so' plugin_path = os.path.join(libs_dir, plugin_name) if os.path.isfile(plugin_path): whl.write_file('panda3d/' + plugin_name, plugin_path) if platform.startswith('android'): deploy_stub_path = os.path.join(libs_dir, 'libdeploy-stubw.so') if os.path.isfile(deploy_stub_path): whl.write_file('deploy_libs/libdeploy-stubw.so', deploy_stub_path) classes_dex_path = os.path.join(output_dir, 'classes.dex') if os.path.isfile(classes_dex_path): whl.write_file('deploy_libs/classes.dex', classes_dex_path) # Add the .data directory, containing additional files. data_dir = 'panda3d-{0}.data'.format(version) #whl.write_directory(data_dir + '/data/etc', etc_dir) #whl.write_directory(data_dir + '/data/models', models_dir) # Actually, let's not. That seems to install the files to the strangest # places in the user's filesystem. Let's instead put them in panda3d. whl.write_directory('panda3d/etc', etc_dir) whl.write_directory('panda3d/models', models_dir) # Add the pandac tree for backward compatibility. for file in sorted(os.listdir(pandac_dir)): if file.endswith('.py'): whl.write_file('pandac/' + file, os.path.join(pandac_dir, file)) # Let's also add the interrogate databases. input_dir = os.path.join(pandac_dir, 'input') if os.path.isdir(input_dir): for file in sorted(os.listdir(input_dir)): if file.endswith('.in'): whl.write_file('pandac/input/' + file, os.path.join(input_dir, file)) # Add a panda3d-tools directory containing the executables. entry_points = '[console_scripts]\n' entry_points += 'eggcacher = direct.directscripts.eggcacher:main\n' entry_points += 'pfreeze = direct.dist.pfreeze:main\n' tools_init = '' for file in sorted(os.listdir(bin_dir)): basename = os.path.splitext(file)[0] if basename in ('eggcacher', 'packpanda'): continue source_path = os.path.join(bin_dir, file) if is_executable(source_path): # Put the .exe files inside the panda3d-tools directory. whl.write_file('panda3d_tools/' + file, source_path) if basename.endswith('_bin'): # These tools won't be invoked by the user directly. continue # Tell pip to create a wrapper script. funcname = basename.replace('-', '_') entry_points += '{0} = panda3d_tools:{1}\n'.format( basename, funcname) tools_init += '{0} = lambda: _exec_tool({1!r})\n'.format( funcname, file) entry_points += '[distutils.commands]\n' entry_points += 'build_apps = direct.dist.commands:build_apps\n' entry_points += 'bdist_apps = direct.dist.commands:bdist_apps\n' whl.write_file_data('panda3d_tools/__init__.py', PANDA3D_TOOLS_INIT.format(tools_init)) # Add the dist-info directory last. info_dir = 'panda3d-{0}.dist-info'.format(version) whl.write_file_data(info_dir + '/entry_points.txt', entry_points) whl.write_file_data(info_dir + '/metadata.json', json.dumps(METADATA, indent=4, separators=(',', ': '))) whl.write_file_data(info_dir + '/METADATA', metadata) whl.write_file_data(info_dir + '/WHEEL', WHEEL_DATA.format(PY_VERSION, ABI_TAG, platform)) whl.write_file(info_dir + '/LICENSE.txt', license_src) whl.write_file(info_dir + '/README.md', readme_src) whl.write_file_data(info_dir + '/top_level.txt', 'direct\npanda3d\npandac\npanda3d_tools\n') whl.close()
# Hack to get mpi4py to build with conda https://bitbucket.org/mpi4py/mpi4py/issues/143/build-failure-with-python-installed-from # Add this file to the mpi4py conf/ directory # sysconfigdata-conda-user.py import os, sysconfig from distutils.util import split_quoted _key = '_PYTHON_SYSCONFIGDATA_NAME' _val = os.environ.pop(_key, None) _name = sysconfig._get_sysconfigdata_name(True) _data = __import__(_name, globals(), locals(), ['build_time_vars'], 0) build_time_vars = _data.build_time_vars def _fix_options(opt): if not isinstance(opt, str): return opt try: opt = split_quoted(opt) except: return opt try: i = opt.index('-B') del opt[i:i + 2] except ValueError: pass try: i = opt.index('-Wl,--sysroot=/') del opt[i] except ValueError: