def make_lib_archive(self, *args, **kwargs): if self.distribution.distinfo_module is not None: imports = ['os', 'sys'] distinfo = [ ( 'install_data', 'os.path.dirname(sys.executable)', ), ( 'install_data_arch', 'os.path.dirname(sys.executable)', ), ( 'install_data_arch_pkg', 'os.path.dirname(sys.executable)', ), ( 'install_data_indep', 'os.path.dirname(sys.executable)', ), ( 'install_data_indep_pkg', 'os.path.dirname(sys.executable)', ), ] tmp_dir_path = mkdtemp() try: distinfo_package, distinfo_module = self._split_distinfo_module() tmp_file_parent_path = os.path.join( tmp_dir_path, *distinfo_package ) os.makedirs(tmp_file_parent_path) tmp_file_path = os.path.join( tmp_file_parent_path, ('%s.py' % distinfo_module), ) self._write_distinfo_module(tmp_file_path, distinfo, imports) sys.path.insert(0, tmp_dir_path) try: self._distinfo_compiled_files = byte_compile( [Module( name = self.distribution.distinfo_module, file = tmp_file_path, )], target_dir = self.collect_dir, optimize = self.optimize, force = 0, verbose = self.verbose, dry_run = self.dry_run, ) finally: del sys.path[0] finally: shutil.rmtree(tmp_dir_path) self.compiled_files.extend(self._distinfo_compiled_files) return _py2exe.make_lib_archive(self, *args, **kwargs)
def copy_extensions(self, extensions): # 获得pygame默认字体 pygamedir = os.path.split(pygame.base.__file__)[0] pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font()) # 加入拷贝文件列表 extensions.append(Module("pygame.font", pygame_default_font)) py2exe.build_exe.py2exe.copy_extensions(self, extensions)
def create_loader(self, item): ## ## Copied from build_exe.py2exe to add `if self.retain_times:` block ## # Hm, how to avoid needless recreation of this file? pathname = os.path.join(self.temp_dir, "%s.py" % item.__name__) if self.bundle_files > 2: # don't bundle pyds and dlls # all dlls are copied into the same directory, so modify # names to include the package name to avoid name # conflicts and tuck it away for future reference fname = item.__name__ + os.path.splitext(item.__file__)[1] item.__pydfile__ = fname else: fname = os.path.basename(item.__file__) # and what about dry_run? if self.verbose: print "creating python loader for extension '%s' (%s -> %s)" % ( item.__name__, item.__file__, fname) source = build_exe.LOADER % fname if not self.dry_run: open(pathname, "w").write(source) if self.retain_times: # Restore the times. st = os.stat(item.__file__) os.utime(pathname, (st[stat.ST_ATIME], st[stat.ST_MTIME])) else: return None from modulefinder import Module return Module(item.__name__, pathname)
def copy_extensions(self, extensions): #Get pygame default font pygamedir = os.path.split(pygame.base.__file__)[0] pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font()) #Add font to list of extension to be copied extensions.append(Module("pygame.font", pygame_default_font)) py2exe.build_exe.py2exe.copy_extensions(self, extensions)
def copy_extensions(self, extensions): # 禄帽碌�pygame�卢�����氓 pygamedir = os.path.split(pygame.base.__file__)[0] pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font()) # 录��毛驴陆卤麓��录镁��卤铆 extensions.append(Module("pygame.font", pygame_default_font)) py2exe.build_exe.py2exe.copy_extensions(self, extensions)
def find_pygame_dlls(): import pygame #dlls = [] pygamedir = os.path.split(pygame.base.__file__)[0] pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font()) yield Module("pygame.font", pygame_default_font) for r,d,f in os.walk(pygamedir): for files in f: if files.lower().endswith(".dll"): dll = os.path.join(r, files) try: m = Module("pygame", dll) m.__pydfile__ = ".".join(dll.split(".")[:-1]) + ".pyd" yield m except Exception: print "Warning, couldn't load", dll
def test_get_dep_modules(self): finder = ModuleFinder(self.path_for_search) new_finder = NewModuleFinder(self.path_for_search) modules, direct_imports, uses_mock, mocked_modules = \ self.evo_shark.get_dep_modules(finder, new_finder, self.path_to_test_1, self.project2_path, self.current_files) expected_direct_imports = [ # first, all init.py must be there Module('tests.data.project2', self.base_path + '/tests/data/project2/__init__.py'), Module('tests.data.project2.module', self.base_path + '/tests/data/project2/module/__init__.py'), Module( 'tests.data.project2.module.package1', self.base_path + '/tests/data/project2/module/package1/__init__.py'), Module( 'tests.data.project2.module.package1.sub_package1', self.base_path + '/tests/data/project2/module/package1/sub_package1/__init__.py' ), Module( 'tests.data.project2.module.package2', self.base_path + '/tests/data/project2/module/package2/__init__.py'), # Now the other modules Module( 'tests.data.project2.module.package1.sub_package1.module1', self.base_path + '/tests/data/project2/module/package1/sub_package1/module1.py' ), Module( 'tests.data.project2.module.package1.module2', self.base_path + '/tests/data/project2/module/package1/module2.py'), Module( 'tests.data.project2.module.package2.module3', self.base_path + '/tests/data/project2/module/package2/module3.py'), ] expected_modules = [ Module( 'tests.data.project2.module.package2.module4', self.base_path + '/tests/data/project2/module/package2/module4.py') ] self.assertTrue( self.checkEqualModuleList(direct_imports, expected_direct_imports)) self.assertTrue(self.checkEqualModuleList(modules, expected_modules)) self.assertFalse(uses_mock) self.assertFalse(mocked_modules)
def django(): import sys try: django = sys.modules['django'] = Module(name='django') django.conf = sys.modules['django.conf'] = Module(name='django.conf') django.conf.settings = object() django.globalnames['conf'] = django.conf django.core = sys.modules['django.core'] = Module(name='django.core') django.globalnames['core'] = django.conf django.core.cache = Module(name='django.core.cache') sys.modules['django.core.cache'] = django.core.cache django.core.globalnames['cache'] = django.core.cache django.core.cache.cache = StubCacheHandler() yield finally: del sys.modules['django'] del sys.modules['django.conf'] del sys.modules['django.core'] del sys.modules['django.core.cache']
def test_get_direct_imports(self): new_finder = NewModuleFinder(self.path_for_search) direct_imports = self.evo_shark.get_direct_imports( new_finder, self.path_to_test_1, self.project2_path) expected_modules = [ # first, all init.py must be there Module('tests.data.project2', self.base_path + '/tests/data/project2/__init__.py'), Module('tests.data.project2.module', self.base_path + '/tests/data/project2/module/__init__.py'), Module( 'tests.data.project2.module.package1', self.base_path + '/tests/data/project2/module/package1/__init__.py'), Module( 'tests.data.project2.module.package1.sub_package1', self.base_path + '/tests/data/project2/module/package1/sub_package1/__init__.py' ), Module( 'tests.data.project2.module.package2', self.base_path + '/tests/data/project2/module/package2/__init__.py'), # Now the other modules Module( 'tests.data.project2.module.package1.sub_package1.module1', self.base_path + '/tests/data/project2/module/package1/sub_package1/module1.py' ), Module( 'tests.data.project2.module.package1.module2', self.base_path + '/tests/data/project2/module/package1/module2.py'), Module( 'tests.data.project2.module.package2.module3', self.base_path + '/tests/data/project2/module/package2/module3.py'), ] self.assertTrue( self.checkEqualModuleList(direct_imports, expected_modules))
def test_get_what_is_mocked(self): # go through test 2 - test 5, which all mock module3 but differently mocked_test_2 = self.evo_shark.get_what_is_mocked( self.path_to_test_2, self.project2_path, self.current_files) mocked_test_3 = self.evo_shark.get_what_is_mocked( self.path_to_test_3, self.project2_path, self.current_files) mocked_test_4 = self.evo_shark.get_what_is_mocked( self.path_to_test_4, self.project2_path, self.current_files) mocked_test_5 = self.evo_shark.get_what_is_mocked( self.path_to_test_5, self.project2_path, self.current_files) expected_mocked_module = set([ Module('tests.data.project2.module.package2.module3', 'tests/data/project2/module/package2/module3.py') ]) self.assertTrue( self.checkEqualModuleList(mocked_test_2, expected_mocked_module)) self.assertTrue( self.checkEqualModuleList(mocked_test_3, expected_mocked_module)) self.assertTrue( self.checkEqualModuleList(mocked_test_4, expected_mocked_module)) self.assertTrue( self.checkEqualModuleList(mocked_test_5, expected_mocked_module))
# This will create a dist directory containing the executable file, all the data
def copy_extensions(self, extensions): defaultFont = os.path.join(PYGAMEDIR, pygame.font.get_default_font()) extensions.append(Module("pygame.font", defaultFont)) py2exe.build_exe.py2exe.copy_extensions(self, extensions)