def collect_folder_data( folder: str, visit_sub_folders=True, include_py_files=False, ): interpreter_path = os.path.dirname(sys.executable) folder_path = os.path.join(interpreter_path, folder) print("folder path: %s" % folder_path) # Walk through all file in the given package, looking for data files. data_toc = TOC() for dir_path, dir_names, files in os.walk(folder_path): for f in files: extension = os.path.splitext(f)[1] # print(f) if not include_py_files and (extension in PY_IGNORE_EXTENSIONS): continue source_file = os.path.join(dir_path, f) dest_folder = remove_prefix(dir_path, interpreter_path + os.sep) dest_file = os.path.join(dest_folder, f) data_toc.append((dest_file, source_file, 'DATA')) if not visit_sub_folders: break return data_toc
def collect_pkg_data(package, include_py_files=False, subdir=None): import os from PyInstaller.utils.hooks import get_package_paths, remove_prefix, PY_IGNORE_EXTENSIONS # Accept only strings as packages. if type(package) is not str: raise ValueError pkg_base, pkg_dir = get_package_paths(package) if subdir: pkg_dir = os.path.join(pkg_dir, subdir) # Walk through all file in the given package, looking for data files. data_toc = TOC() for dir_path, dir_names, files in os.walk(pkg_dir): copy_root_token = os.path.split(dir_path)[-1] copy_root = copy_root_token in ["support", "configdata"] # if copy_root: # print("- %s" % dir_path) for f in files: extension = os.path.splitext(f)[1] if include_py_files or (extension not in PY_IGNORE_EXTENSIONS): source_file = os.path.join(dir_path, f) dest_folder = remove_prefix(dir_path, os.path.dirname(pkg_base) + os.sep) dest_file = os.path.join(dest_folder, f) data_toc.append((dest_file, source_file, 'DATA')) if copy_root: source_file = os.path.join(dir_path, f) root_path = os.path.join(os.path.dirname(pkg_base), "hyo2", "grids") + os.sep dest_folder = remove_prefix(dir_path, root_path) dest_file = os.path.join(dest_folder, f) # print("%s -> %s" % (dest_file, source_file)) data_toc.append((dest_file, source_file, 'DATA')) return data_toc
def collect_dynamic_libs(package, destdir=None): """ This routine produces a list of (source, dest) of dynamic library files which reside in package. Its results can be directly assigned to ``binaries`` in a hook script. The package parameter must be a string which names the package. :param destdir: Relative path to ./dist/APPNAME where the libraries should be put. """ # Accept only strings as packages. if not isinstance(package, string_types): raise ValueError logger.debug("Collecting dynamic libraries for %s" % package) pkg_base, pkg_dir = get_package_paths(package) # Walk through all file in the given package, looking for dynamic libraries. dylibs = [] for dirpath, _, __ in os.walk(pkg_dir): # Try all file patterns in a given directory. for pattern in PY_DYLIB_PATTERNS: files = glob.glob(os.path.join(dirpath, pattern)) for source in files: # Produce the tuple # (/abs/path/to/source/mod/submod/file.pyd, # mod/submod/file.pyd) if destdir: # Libraries will be put in the same directory. dest = destdir else: # The directory hierarchy is preserved as in the original package. dest = remove_prefix(dirpath, os.path.dirname(pkg_base) + os.sep) logger.debug(" %s, %s" % (source, dest)) dylibs.append((source, dest)) return dylibs
def test_no_modific(self): assert 'atest' == remove_prefix('atest', 'test')
def test_just_prefix(self): assert 'ing' == remove_prefix('testing', 'test')
def test_string_prefix(self): assert '' == remove_prefix('test', 'test')
def test_emptystr_unmodif(self): assert 'test' == remove_prefix('test', '')
def test_empty_string(self): assert '' == remove_prefix('', 'prefix')
# Per the `docs <https://doc.qt.io/qt-5.10/qtwebengine-deploying.html#deploying-resources>`_, # ``DataPath`` is the base directory for ``resources``. # # When Python 3.4 goes EOL (see `PEP 448`_, this is better written as # ``os.path.join(*rel_data_path, resources)``. (os.path.join(pyqt5_library_info.location['DataPath'], resources), os.path.join(*(rel_data_path + [resources]))), # Include the webengine process. The ``LibraryExecutablesPath`` is only # valid on Windows and Linux. # # Again, rewrite when Python 3.4 is EOL to # ``os.path.join(*rel_data_path, remove_prefix(...``. (os.path.join(pyqt5_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), os.path.join(*(rel_data_path + [remove_prefix(pyqt5_library_info.location['LibraryExecutablesPath'], pyqt5_library_info.location['PrefixPath'] + '/')]))) ] # Add Linux-specific libraries. if compat.is_linux: # The automatic library detection fails for `NSS # <https://packages.ubuntu.com/search?keywords=libnss3>`_, which is used by # QtWebEngine. In some distributions, the ``libnss`` supporting libraries # are stored in a subdirectory ``nss``. Since ``libnss`` is not statically # linked to these, but dynamically loads them, we need to search for and add # them. # # First, get all libraries linked to ``PyQt5.QtWebEngineWidgets``. for imp in getImports(get_module_file_attribute('PyQt5.QtWebEngineWidgets')): # Look for ``libnss3.so``. if os.path.basename(imp).startswith('libnss3.so'):