def copyDataFiles(dist_dir): """ Copy the data files needed for standalone distribution. Args: dist_dir: The distribution folder under creation Notes: This is for data files only, not DLLs or even extension modules, those must be registered as entry points, and would not go through necessary handling if provided like this. """ # Cyclic dependency from nuitka import ModuleRegistry for module in ModuleRegistry.getDoneModules(): for _plugin_name, (source_desc, target_filename) in Plugins.considerDataFiles( module ): target_filename = os.path.join(dist_dir, target_filename) assert isPathBelow(dist_dir, target_filename) makePath(os.path.dirname(target_filename)) if inspect.isfunction(source_desc): content = source_desc(target_filename) if content is not None: # support creation of empty directories with open( target_filename, "wb" if type(content) is bytes else "w" ) as output: output.write(content) else: shutil.copy2(source_desc, target_filename)
def copyDataFiles(dist_dir, data_files): """ Copy the data files needed for standalone distribution. Args: dist_dir: The distribution folder under creation data_files: Tuple of pairs describing (source, dest) or (func, dest) that should be copied. Notes: This is for data files only, not DLLs or even extension modules, those must be registered as entry points, and would not go through necessary handling if provided like this. """ for source_desc, target_filename in data_files: target_filename = os.path.join(dist_dir, target_filename) assert isPathBelow(dist_dir, target_filename) makePath(os.path.dirname(target_filename)) if inspect.isfunction(source_desc): content = source_desc(target_filename) if content is not None: # support creation of empty directories with open( target_filename, "wb" if type(content) is bytes else "w" ) as output: output.write(content) else: shutil.copy2(source_desc, target_filename)
def _handleDataFile(dist_dir, tracer, included_datafile): """Handle a data file.""" if isinstance(included_datafile, IncludedDataFile): if included_datafile.kind == "empty_dirs": tracer.info("Included empty directories %s due to %s." % ( ",".join(included_datafile.dest_path), included_datafile.reason, )) for sub_dir in included_datafile.dest_path: makePath(os.path.join(dist_dir, sub_dir)) elif included_datafile.kind == "data_file": dest_path = os.path.join(dist_dir, included_datafile.dest_path) tracer.info("Included data file %r due to %s." % ( included_datafile.dest_path, included_datafile.reason, )) makePath(os.path.dirname(dest_path)) shutil.copyfile(included_datafile.source_path, dest_path) elif included_datafile.kind == "data_dir": dest_path = os.path.join(dist_dir, included_datafile.dest_path) makePath(os.path.dirname(dest_path)) copied = copyTree(included_datafile.source_path, dest_path) tracer.info("Included data dir %r with %d files due to %s." % ( included_datafile.dest_path, len(copied), included_datafile.reason, )) else: assert False, included_datafile else: # TODO: Goal is have this unused. source_desc, target_filename = included_datafile if not isPathBelow(dist_dir, target_filename): target_filename = os.path.join(dist_dir, target_filename) makePath(os.path.dirname(target_filename)) if inspect.isfunction(source_desc): content = source_desc(target_filename) if content is not None: # support creation of empty directories with open(target_filename, "wb" if type(content) is bytes else "w") as output: output.write(content) else: copyFileWithPermissions(source_desc, target_filename)
def isStandardLibraryPath(filename): """Check if a path is in the standard library.""" filename = os.path.normcase(os.path.normpath(filename)) # In virtualenv, the "site.py" lives in a place that suggests it is not in # standard library, although it is. if os.path.basename(filename) == "site.py": return True # These never are in standard library paths. if "dist-packages" in filename or "site-packages" in filename: return False for candidate in getStandardLibraryPaths(): if isPathBelow(path=candidate, filename=filename): return True return False
def _parseOtoolListingOutput(output): paths = OrderedSet() for line in output.split(b"\n")[1:]: if str is not bytes: line = line.decode("utf8") if not line: continue filename = line.split(" (", 1)[0].strip() # Ignore dependency from system paths. if not isPathBelow( path=( "/usr/lib/", "/System/Library/Frameworks/", "/System/Library/PrivateFrameworks/", ), filename=filename, ): paths.add(filename) return paths