def add_module_dir(self, module_name, verbose=False, exclude_dirs=[]): """ Collect all module files for module *module_name* and add them to *data_files* """ module_dir = get_module_path(module_name) nstrip = len(module_dir) + len(osp.sep) for dirpath, dirnames, filenames in os.walk(module_dir): if osp.basename(dirpath) in exclude_dirs: continue for dn in dirnames[:]: if not osp.isfile(osp.join(dirpath, dn, '__init__.py')): dirnames.remove(dn) dirname = osp.join(module_name, dirpath[nstrip:]) for filename in filenames: ext = osp.splitext(filename)[1].lower() if ext in ('.py', '.pyd'): if filename == '__init__.py': fn = dirname else: fn = osp.splitext(osp.join(dirname, filename))[0] if fn.endswith(os.sep): fn = fn[:-1] modname = ".".join(fn.split(os.sep)) self.includes += [modname] if verbose: print(" + ", modname)
def add_module_data_files(self, module_name, data_dir_names, extensions, copy_to_root=True, verbose=False, exclude_dirs=[]): """ Collect data files for module *module_name* and add them to *data_files* *data_dir_names*: list of dirnames, e.g. ('images', ) *extensions*: list of file extensions, e.g. ('.png', '.svg') """ print("Adding module '%s' data files in %s (%s)"\ % (module_name, ", ".join(data_dir_names), ", ".join(extensions))) module_dir = get_module_path(module_name) for data_dir_name in data_dir_names: self.add_module_data_dir(module_name, data_dir_name, extensions, copy_to_root, verbose, exclude_dirs) translation_file = osp.join(module_dir, "locale", "fr", "LC_MESSAGES", "%s.mo" % module_name) if osp.isfile(translation_file): self.data_files.append( (osp.join(module_name, "locale", "fr", "LC_MESSAGES"), (translation_file, ))) print("Adding module '%s' translation file: %s" % (module_name, osp.basename(translation_file)))
def add_module_data_dir(self, module_name, data_dir_name, extensions, copy_to_root=True, verbose=False, exclude_dirs=[]): """ Collect data files in *data_dir_name* for module *module_name* and add them to *data_files* *extensions*: list of file extensions, e.g. ('.png', '.svg') """ module_dir = get_module_path(module_name) nstrip = len(module_dir) + len(osp.sep) data_dir = osp.join(module_dir, data_dir_name) if not osp.isdir(data_dir): raise IOError("Directory not found: %s" % data_dir) for dirpath, _dirnames, filenames in os.walk(data_dir): dirname = dirpath[nstrip:] if osp.basename(dirpath) in exclude_dirs: continue if not copy_to_root: dirname = osp.join(module_name, dirname) pathlist = [osp.join(dirpath, f) for f in filenames if osp.splitext(f)[1].lower() in extensions] self.data_files.append( (dirname, pathlist) ) if verbose: for name in pathlist: print(" ", name)
def add_module_data_dir(self, module_name, data_dir_name, extensions, copy_to_root=True, verbose=False, exclude_dirs=[]): """ Collect data files in *data_dir_name* for module *module_name* and add them to *data_files* *extensions*: list of file extensions, e.g. ('.png', '.svg') """ module_dir = get_module_path(module_name) nstrip = len(module_dir) + len(osp.sep) data_dir = osp.join(module_dir, data_dir_name) if not osp.isdir(data_dir): raise IOError("Directory not found: %s" % data_dir) for dirpath, _dirnames, filenames in os.walk(data_dir): dirname = dirpath[nstrip:] if osp.basename(dirpath) in exclude_dirs: continue if not copy_to_root: dirname = osp.join(module_name, dirname) pathlist = [ osp.join(dirpath, f) for f in filenames if osp.splitext(f)[1].lower() in extensions ] self.data_files.append((dirname, pathlist)) if verbose: for name in pathlist: print(" ", name)
def add_module_data_files(self, module_name, data_dir_names, extensions, copy_to_root=True, verbose=False, exclude_dirs=[]): """ Collect data files for module *module_name* and add them to *data_files* *data_dir_names*: list of dirnames, e.g. ('images', ) *extensions*: list of file extensions, e.g. ('.png', '.svg') """ print("Adding module '%s' data files in %s (%s)"\ % (module_name, ", ".join(data_dir_names), ", ".join(extensions))) module_dir = get_module_path(module_name) for data_dir_name in data_dir_names: self.add_module_data_dir(module_name, data_dir_name, extensions, copy_to_root, verbose, exclude_dirs) translation_file = osp.join(module_dir, "locale", "fr", "LC_MESSAGES", "%s.mo" % module_name) if osp.isfile(translation_file): self.data_files.append((osp.join(module_name, "locale", "fr", "LC_MESSAGES"), (translation_file, ))) print("Adding module '%s' translation file: %s" % (module_name, osp.basename(translation_file)))
def add_modules(self, *module_names): """Include module *module_name*""" for module_name in module_names: print("Configuring module '%s'" % module_name) if module_name in ('PyQt4', 'PyQt5'): self.add_pyqt() elif module_name == 'PySide': self.add_pyside() elif module_name == 'scipy': self.add_module_dir('scipy') elif module_name == 'matplotlib': self.add_matplotlib() elif module_name == 'h5py': self.add_module_dir('h5py') if self.bin_path_excludes is not None and os.name == 'nt': # Specific to cx_Freeze on Windows: avoid including a zlib dll # built with another version of Microsoft Visual Studio self.bin_path_excludes += [r'C:\Program Files', r'C:\Program Files (x86)'] self.data_files.append( # necessary for cx_Freeze only ('', (osp.join(get_module_path('h5py'), 'zlib1.dll'), )) ) elif module_name in ('docutils', 'rst2pdf', 'sphinx'): self.includes += ['docutils.writers.null', 'docutils.languages.en', 'docutils.languages.fr'] if module_name == 'rst2pdf': self.add_module_data_files("rst2pdf", ("styles", ), ('.json', '.style'), copy_to_root=True) if module_name == 'sphinx': import sphinx.ext for fname in os.listdir(osp.dirname(sphinx.ext.__file__)): if osp.splitext(fname)[1] == '.py': modname = 'sphinx.ext.%s' % osp.splitext(fname)[0] self.includes.append(modname) elif module_name == 'pygments': self.includes += ['pygments', 'pygments.formatters', 'pygments.lexers', 'pygments.lexers.agile'] elif module_name == 'zmq': # FIXME: this is not working, yet... (missing DLL) self.includes += ['zmq', 'zmq.core._poll', 'zmq.core._version', 'zmq.core.constants', 'zmq.core.context', 'zmq.core.device', 'zmq.core.error', 'zmq.core.message', 'zmq.core.socket', 'zmq.core.stopwatch'] if os.name == 'nt': self.bin_includes += ['libzmq.dll'] elif module_name == 'guidata': self.add_module_data_files('guidata', ("images", ), ('.png', '.svg'), copy_to_root=False) self.add_qt_bindings() elif module_name == 'guiqwt': self.add_module_data_files('guiqwt', ("images", ), ('.png', '.svg'), copy_to_root=False) if os.name == 'nt': # Specific to cx_Freeze: including manually MinGW DLLs self.bin_includes += ['libgcc_s_dw2-1.dll', 'libstdc++-6.dll'] else: try: # Modules based on the same scheme as guidata and guiqwt self.add_module_data_files(module_name, ("images", ), ('.png', '.svg'), copy_to_root=False) except IOError: raise RuntimeError("Module not supported: %s" % module_name)
def add_modules(self, *module_names): """Include module *module_name*""" for module_name in module_names: print("Configuring module '%s'" % module_name) if module_name in ('PyQt4', 'PyQt5'): self.add_pyqt() elif module_name == 'PySide': self.add_pyside() elif module_name == 'scipy': self.add_module_dir('scipy') elif module_name == 'scipy.io': self.includes += ['scipy.io.matlab.streams'] elif module_name == 'matplotlib': self.add_matplotlib() elif module_name == 'h5py': import h5py for attr in [ '_stub', '_sync', 'utils', '_conv', '_proxy', 'defs' ]: if hasattr(h5py, attr): self.includes.append('h5py.%s' % attr) if self.bin_path_excludes is not None and os.name == 'nt': # Specific to cx_Freeze on Windows: avoid including a zlib dll # built with another version of Microsoft Visual Studio self.bin_path_excludes += [ r'C:\Program Files', r'C:\Program Files (x86)' ] self.data_files.append( # necessary for cx_Freeze only ('', (osp.join(get_module_path('h5py'), 'zlib1.dll'), ))) elif module_name in ('docutils', 'rst2pdf', 'sphinx'): self.includes += [ 'docutils.writers.null', 'docutils.languages.en', 'docutils.languages.fr' ] if module_name == 'rst2pdf': self.add_module_data_files("rst2pdf", ("styles", ), ('.json', '.style'), copy_to_root=True) if module_name == 'sphinx': import sphinx.ext for fname in os.listdir(osp.dirname(sphinx.ext.__file__)): if osp.splitext(fname)[1] == '.py': modname = 'sphinx.ext.%s' % osp.splitext(fname)[0] self.includes.append(modname) elif module_name == 'pygments': self.includes += [ 'pygments', 'pygments.formatters', 'pygments.lexers', 'pygments.lexers.agile' ] elif module_name == 'zmq': # FIXME: this is not working, yet... (missing DLL) self.includes += [ 'zmq', 'zmq.core._poll', 'zmq.core._version', 'zmq.core.constants', 'zmq.core.context', 'zmq.core.device', 'zmq.core.error', 'zmq.core.message', 'zmq.core.socket', 'zmq.core.stopwatch' ] if os.name == 'nt': self.bin_includes += ['libzmq.dll'] elif module_name == 'guidata': self.add_module_data_files('guidata', ("images", ), ('.png', '.svg'), copy_to_root=False) self.add_qt_bindings() elif module_name == 'guiqwt': self.add_module_data_files('guiqwt', ("images", ), ('.png', '.svg'), copy_to_root=False) if os.name == 'nt': # Specific to cx_Freeze: including manually MinGW DLLs self.bin_includes += [ 'libgcc_s_dw2-1.dll', 'libstdc++-6.dll' ] else: try: # Modules based on the same scheme as guidata and guiqwt self.add_module_data_files(module_name, ("images", ), ('.png', '.svg'), copy_to_root=False) except IOError: raise RuntimeError("Module not supported: %s" % module_name)
def add_modules(self, *module_names): """Include module *module_name*""" for module_name in module_names: print("Configuring module '%s'" % module_name) if module_name in ("PyQt4", "PyQt5"): self.add_pyqt() elif module_name == "PySide": self.add_pyside() elif module_name == "scipy": self.add_module_dir("scipy") elif module_name == "matplotlib": self.add_matplotlib() elif module_name == "h5py": self.add_module_dir("h5py") if self.bin_path_excludes is not None and os.name == "nt": # Specific to cx_Freeze on Windows: avoid including a zlib dll # built with another version of Microsoft Visual Studio self.bin_path_excludes += [ r"C:\Program Files", r"C:\Program Files (x86)", ] self.data_files.append( # necessary for cx_Freeze only ("", (osp.join(get_module_path("h5py"), "zlib1.dll"), ))) elif module_name in ("docutils", "rst2pdf", "sphinx"): self.includes += [ "docutils.writers.null", "docutils.languages.en", "docutils.languages.fr", ] if module_name == "rst2pdf": self.add_module_data_files("rst2pdf", ("styles", ), (".json", ".style"), copy_to_root=True) if module_name == "sphinx": import sphinx.ext for fname in os.listdir(osp.dirname(sphinx.ext.__file__)): if osp.splitext(fname)[1] == ".py": modname = "sphinx.ext.%s" % osp.splitext(fname)[0] self.includes.append(modname) elif module_name == "pygments": self.includes += [ "pygments", "pygments.formatters", "pygments.lexers", "pygments.lexers.agile", ] elif module_name == "zmq": # FIXME: this is not working, yet... (missing DLL) self.includes += [ "zmq", "zmq.core._poll", "zmq.core._version", "zmq.core.constants", "zmq.core.context", "zmq.core.device", "zmq.core.error", "zmq.core.message", "zmq.core.socket", "zmq.core.stopwatch", ] if os.name == "nt": self.bin_includes += ["libzmq.dll"] elif module_name == "guidata": self.add_module_data_files("guidata", ("images", ), (".png", ".svg"), copy_to_root=False) self.add_qt_bindings() elif module_name == "guiqwt": self.add_module_data_files("guiqwt", ("images", ), (".png", ".svg"), copy_to_root=False) if os.name == "nt": # Specific to cx_Freeze: including manually MinGW DLLs self.bin_includes += [ "libgcc_s_dw2-1.dll", "libstdc++-6.dll" ] else: try: # Modules based on the same scheme as guidata and guiqwt self.add_module_data_files(module_name, ("images", ), (".png", ".svg"), copy_to_root=False) except IOError: raise RuntimeError("Module not supported: %s" % module_name)