def detectEarlyImports(): if Options.freezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except ImportError:\n" \ " pass\n" else: # TODO: Should recursively include all of encodings module. import_code = "import encodings.utf_8;import encodings.ascii;import encodings.idna;" if Utils.getOS() == "Windows": import_code += "import encodings.mbcs;import encodings.cp437;" # String method hex depends on it. if Utils.python_version < 300: import_code += "import encodings.hex_codec;" import_code += "import locale;" result = _detectImports(import_code, False) debug("Finished detecting early imports.") return result
def detectEarlyImports(): if Options.freezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except ImportError:\n" \ " pass\n" else: # TODO: Should recursively include all of encodings module. import_code = "import encodings.utf_8;import encodings.ascii;import encodings.idna;" if Utils.getOS() == "Windows": import_code += "import encodings.mbcs;import encodings.cp437;" # String method hex depends on it. if Utils.python_version < 300: import_code += "import encodings.hex_codec;" import_code += "import locale;" result = _detectImports(import_code, False) debug("Finished detecting early imports.") return result
def detectEarlyImports(): encoding_names = [ filename[:-3] for _path, filename in Utils.listDir( Utils.dirname(sys.modules["encodings"].__file__)) if filename.endswith(".py") if "__init__" not in filename ] if Utils.getOS() != "Windows": encoding_names.remove("mbcs") if "cp65001" in encoding_names: encoding_names.remove("cp65001") import_code = ';'.join("import encodings.%s" % encoding_name for encoding_name in encoding_names) import_code += ";import locale;" # For Python3 we patch inspect without knowing if it is used. if python_version >= 300: import_code += "import inspect;" # We might need the pickle module when creating global constants. if python_version >= 300: import_code += "import pickle;" else: import_code += "import cPickle;" result = _detectImports(command=import_code, user_provided=False, technical=True) if Options.shallFreezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except (ImportError, SyntaxError):\n" \ " pass\n" early_names = [module.getFullName() for module in result] result += [ module for module in _detectImports( command=import_code, user_provided=False, technical=False) if module.getFullName() not in early_names ] debug("Finished detecting early imports.") return result
def detectEarlyImports(): # TODO: Should recursively include all of encodings module. import_code = "import encodings.utf_8;import encodings.ascii;import encodings.idna;" if Utils.getOS() == "Windows": import_code += "import encodings.mbcs;import encodings.cp437;" # String method hex depends on it. if python_version < 300: import_code += "import encodings.hex_codec;" import_code += "import locale;" # For Python3 we patch inspect without knowing if it is used. if python_version >= 300: import_code += "import inspect;" # We might need the pickle module when creating global constants. if python_version >= 300: import_code += "import pickle;" else: import_code += "import cPickle;" result = _detectImports(command=import_code, user_provided=False, technical=True) if Options.shallFreezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except (ImportError, SyntaxError):\n" \ " pass\n" early_names = [module.getFullName() for module in result] result += [ module for module in _detectImports( command=import_code, user_provided=False, technical=False) if module.getFullName() not in early_names ] debug("Finished detecting early imports.") return result
def _detectEarlyImports(): encoding_names = [ m[1] for m in pkgutil.iter_modules(sys.modules["encodings"].__path__) ] if os.name != "nt": # On posix systems, and posix Python veriants on Windows, these won't # work and fail to import. for encoding_name in ("mbcs", "cp65001", "oem"): if encoding_name in encoding_names: encoding_names.remove(encoding_name) import_code = ";".join("import encodings.%s" % encoding_name for encoding_name in sorted(encoding_names)) import_code += ";import locale;" # For Python3 we patch inspect without knowing if it is used. if python_version >= 0x300: import_code += "import inspect;" result = _detectImports(command=import_code, user_provided=False, technical=True) if Options.shallFreezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) # Put here ones that should be imported first. first_ones = ("Tkinter", ) # We have to fight zombie modules in this, some things, e.g. Tkinter # on newer Python 2.7, comes back after failure without a second error # being raised, leading to other issues. So we fight it after each # module that was tried, and prevent re-try by adding a meta path # based loader that will never load it again, and remove it from the # "sys.modules" over and over, once it sneaks back. The root cause is # that extension modules sometimes only raise an error when first # imported, not the second time around. # Otherwise this just makes imports of everything so we can see where # it comes from and what it requires. import_code = """ imports = %r failed = set() class ImportBlocker(object): def find_module(self, fullname, path = None): if fullname in failed: return self return None def load_module(self, name): raise ImportError("%%s has failed before" %% name) sys.meta_path.insert(0, ImportBlocker()) for imp in imports: try: __import__(imp) except (ImportError, SyntaxError): failed.add(imp) except Exception: sys.stderr("PROBLEM with '%%s'\\n" %% imp) raise for fail in failed: if fail in sys.modules: del sys.modules[fail] """ % sorted(stdlib_modules, key=lambda name: (name not in first_ones, name)) early_names = [module.getFullName() for module in result] result += [ module for module in _detectImports( command=import_code, user_provided=False, technical=False) if module.getFullName() not in early_names ] return result
def detectEarlyImports(): encoding_names = [ filename[:-3] for _path, filename in Utils.listDir(Utils.dirname(sys.modules["encodings"].__file__)) if filename.endswith(".py") if "__init__" not in filename ] if Utils.getOS() != "Windows": encoding_names.remove("mbcs") if "cp65001" in encoding_names: encoding_names.remove("cp65001") import_code = ";".join( "import encodings.%s" % encoding_name for encoding_name in encoding_names ) import_code += ";import locale;" # For Python3 we patch inspect without knowing if it is used. if python_version >= 300: import_code += "import inspect;" # We might need the pickle module when creating global constants. if python_version >= 300: import_code += "import pickle;" else: import_code += "import cPickle;" result = _detectImports( command = import_code, user_provided = False, technical = True ) if Options.shallFreezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except (ImportError, SyntaxError):\n" \ " pass\n" early_names = [ module.getFullName() for module in result ] result += [ module for module in _detectImports( command = import_code, user_provided = False, technical = False ) if module.getFullName() not in early_names ] debug("Finished detecting early imports.") return result
def detectEarlyImports(): # TODO: Should recursively include all of encodings module. import_code = "import encodings.utf_8;import encodings.ascii;import encodings.idna;" if Utils.getOS() == "Windows": import_code += "import encodings.mbcs;import encodings.cp437;" # String method hex depends on it. if python_version < 300: import_code += "import encodings.hex_codec;" import_code += "import locale;" # For Python3 we patch inspect without knowing if it is used. if python_version >= 300: import_code += "import inspect;" # We might need the pickle module when creating global constants. if python_version >= 300: import_code += "import pickle;" else: import_code += "import cPickle;" result = _detectImports( command = import_code, user_provided = False, technical = True ) if Options.shallFreezeAllStdlib(): stdlib_modules = set() # Scan the standard library paths (multiple in case of virtualenv. for stdlib_dir in getStandardLibraryPaths(): for module_name in scanStandardLibraryPath(stdlib_dir): stdlib_modules.add(module_name) import_code = "imports = " + repr(sorted(stdlib_modules)) + '\n'\ "for imp in imports:\n" \ " try:\n" \ " __import__(imp)\n" \ " except (ImportError, SyntaxError):\n" \ " pass\n" early_names = [ module.getFullName() for module in result ] result += [ module for module in _detectImports( command = import_code, user_provided = False, technical = False ) if module.getFullName() not in early_names ] debug("Finished detecting early imports.") return result