def bundle_func(args): def get_reqs(path): path = os.path.abspath(path) reqs = set() with open(path) as f: for line in f: line = line.strip() if not line or line.startswith('#'): continue reqs.add(line) return reqs if not args.packages: logger.fatal('Error: You must specify at least one package', exc=PygError) reqs = [] if args.req_file: reqs = [Requirement(r) for f in args.req_file for r in get_reqs(f)] b = Bundler(map(Requirement, args.packages) + reqs, args.bundlename) b.bundle()
def bundle_func(packages, bundlename, exclude, req_file, develop): def get_reqs(path): path = os.path.abspath(path) reqs = set() with open(path) as f: for line in f: line = line.strip() if not line or line.startswith('#'): continue reqs.add(line) return reqs if not packages and not req_file: logger.fatal('Error: You must specify at least one package', exc=PygError) reqs = [] if req_file: reqs = [Requirement(r) for f in req_file for r in get_reqs(f)] exclude = [Requirement(r) for r in (exclude or [])] bundlename = os.path.abspath(bundlename) dest, bundlename = os.path.dirname(bundlename), os.path.basename(bundlename) b = Bundler(map(Requirement, packages) + reqs, bundlename, exclude, use_develop=develop) b.bundle(dest=dest)
def gen_pack(self, exclude=[], use_develop=False): # This is where to download all packages # and where to build the pack with TempDir() as tempdir: # This is where to store the egg with TempDir() as bundle_dir: logger.info('Generating the bundle...') b = Bundler([self.req], self.bundle_name, exclude=exclude, \ callback=self._bundle_callback, use_develop=use_develop) # we download packages without creating the bundle to build # eggs b._download_all(tempdir) b._clean(tempdir) bundle = os.path.join(bundle_dir, self.req.name) + '.egg' with ZipFile(bundle, mode='w') as egg: # Create a new directory to store unpacked eggs with TempDir() as egg_dir: self._gen_eggs(tempdir, egg_dir) b._add_to_archive(egg, egg_dir, len(egg_dir)) egg_info, tl = self._mk_egg_info() b._add_to_archive(egg, egg_info, tl) pack = os.path.join(tempdir, self.pack_name) eggname = self.req.name + '.egg' folder_name = '{0.name}-{0.version}'.format(self.bundled[self.req.name]) with ZipFile(pack, mode='w') as z: z.write(bundle, '/'.join([folder_name, eggname])) # write executable files for command_name, code in self.entry_points.iteritems(): z.writestr('/'.join([folder_name, 'run_%s.py' % command_name]), _gen_executable(eggname, code, self.modules)) dest = os.path.join(self.dest, self.pack_name) if os.path.exists(dest): os.remove(dest) shutil.move(pack, self.dest)