def do_build_and_install(self, dist): srcdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, srcdir) dstdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, dstdir) paths = install_dist(dist, srcdir) paths['prefix'] = srcdir w = Wheel() w.name = paths.pop('name') w.version = paths.pop('version') w.dirname = srcdir pathname = w.build(paths) self.assertTrue(os.path.exists(pathname)) paths = {'prefix': dstdir} for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'): paths[key] = os.path.join(dstdir, key) w = Wheel(pathname) executable = os.path.join(paths['scripts'], 'python') dist = w.install(paths, executable=executable) self.assertIsNotNone(dist) self.assertEqual(dist.name, w.name) self.assertEqual(dist.version, w.version) os.remove(pathname) sm = Manifest(srcdir) sm.findall() sfiles = set([os.path.relpath(p, srcdir) for p in sm.allfiles]) dm = Manifest(dstdir) dm.findall() dfiles = set([os.path.relpath(p, dstdir) for p in dm.allfiles]) omitted = sfiles - dfiles omitted = omitted.pop() endings = os.path.join('.dist-info', 'WHEEL'), '.pyc', '.pyo' self.assertTrue(omitted.endswith(endings))
def test_build_tags(self): workdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, workdir) name = 'dummy' version = '0.1' paths = {'prefix': workdir} for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'): paths[key] = p = os.path.join(workdir, key) os.makedirs(p) fn = os.path.join(p, '%s_file.txt' % key) with open(fn, 'w') as f: f.write('dummy data - %s' % key) if key in ('purelib', 'platlib'): p = os.path.join(p, '%s-%s.dist-info' % (name, version)) os.makedirs(p) fn = os.path.join(p, 'RECORD') purelib = paths.pop('purelib') platlib = paths.pop('platlib') # Make a pure wheel with default tags paths['purelib'] = purelib wheel = Wheel('%s-%s' % (name, version)) wheel.dirname = workdir wheel.build(paths) expected = { 'name': name, 'version': version, 'pyver': [PYVER], 'abi': ['none'], 'arch': ['any'], 'filename': 'dummy-0.1-%s-none-any.whl' % PYVER, } self.check_built_wheel(wheel, expected) # Make a pure wheel with custom tags pyver = [PYVER[:-1], PYVER] wheel.build(paths, {'pyver': pyver}) expected = { 'name': name, 'version': version, 'pyver': pyver, 'abi': ['none'], 'arch': ['any'], 'filename': 'dummy-0.1-%s-none-any.whl' % '.'.join(pyver), } self.check_built_wheel(wheel, expected) # Make a non-pure wheel with default tags paths.pop('purelib') paths['platlib'] = platlib wheel.build(paths) expected['pyver'] = [IMPVER] expected['abi'] = [ABI] expected['arch'] = [ARCH] expected['filename'] = 'dummy-0.1-%s-%s-%s.whl' % (IMPVER, ABI, ARCH) self.check_built_wheel(wheel, expected)
def test_build_tags(self): workdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, workdir) name = "dummy" version = "0.1" paths = {"prefix": workdir} for key in ("purelib", "platlib", "headers", "scripts", "data"): paths[key] = p = os.path.join(workdir, key) os.makedirs(p) fn = os.path.join(p, "%s_file.txt" % key) with open(fn, "w") as f: f.write("dummy data - %s" % key) if key in ("purelib", "platlib"): p = os.path.join(p, "%s-%s.dist-info" % (name, version)) os.makedirs(p) fn = os.path.join(p, "RECORD") purelib = paths.pop("purelib") platlib = paths.pop("platlib") # Make a pure wheel with default tags paths["purelib"] = purelib wheel = Wheel("%s-%s" % (name, version)) wheel.dirname = workdir wheel.build(paths) expected = { "name": name, "version": version, "pyver": [PYVER], "abi": ["none"], "arch": ["any"], "filename": "dummy-0.1-%s-none-any.whl" % PYVER, } self.check_built_wheel(wheel, expected) # Make a pure wheel with custom tags pyver = [PYVER[:-1], PYVER] wheel.build(paths, {"pyver": pyver}) expected = { "name": name, "version": version, "pyver": pyver, "abi": ["none"], "arch": ["any"], "filename": "dummy-0.1-%s-none-any.whl" % ".".join(pyver), } self.check_built_wheel(wheel, expected) # Make a non-pure wheel with default tags paths.pop("purelib") paths["platlib"] = platlib wheel.build(paths) expected["pyver"] = [IMPVER] expected["abi"] = [ABI] expected["arch"] = [ARCH] expected["filename"] = "dummy-0.1-%s-%s-%s.whl" % (IMPVER, ABI, ARCH) self.check_built_wheel(wheel, expected)
def pack(project_dir, wheelhouse, work_dir): dist_path = os.path.join(project_dir, 'dist-info', 'pydist.json') md = Metadata(path=dist_path) wheel = Wheel() wheel.name = md.name wheel.version = md.version dest_dist = os.path.join(work_dir, '{}.dist-info'.format(md.name)) os.makedirs(dest_dist) shutil.copyfile(dist_path, os.path.join(dest_dist, 'pydist.json')) for pkg_dir in os.listdir(os.path.join(project_dir, 'src')): shutil.copytree(os.path.join(project_dir, 'src', pkg_dir), os.path.join(work_dir, pkg_dir)) paths = { 'purelib': work_dir, } wheel.dirname = wheelhouse wheel.build(paths)
def do_build_and_install(self, dist): srcdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, srcdir) dstdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, dstdir) paths = install_dist(dist, srcdir) paths['prefix'] = srcdir w = Wheel() w.name = paths.pop('name') w.version = paths.pop('version') w.dirname = srcdir pathname = w.build(paths) self.assertTrue(os.path.exists(pathname)) paths = {'prefix': dstdir} for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'): paths[key] = os.path.join(dstdir, key) w = Wheel(pathname) maker = ScriptMaker(None, None, add_launchers=False) maker.executable = os.path.join(paths['scripts'], 'python') dist = w.install(paths, maker) self.assertIsNotNone(dist) self.assertEqual(dist.name, w.name) self.assertEqual(dist.version, w.version) shared = dist.shared_locations self.assertTrue(shared) os.remove(pathname) sm = Manifest(srcdir) sm.findall() sfiles = set([os.path.relpath(p, srcdir) for p in sm.allfiles]) dm = Manifest(dstdir) dm.findall() dfiles = set([os.path.relpath(p, dstdir) for p in dm.allfiles]) omitted = sfiles - dfiles omitted = omitted.pop() endings = os.path.join('.dist-info', 'WHEEL'), '.pyc', '.pyo' self.assertTrue(omitted.endswith(endings))
def do_build_and_install(self, dist): srcdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, srcdir) dstdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, dstdir) paths = install_dist(dist, srcdir) paths["prefix"] = srcdir w = Wheel() w.name = paths.pop("name") w.version = paths.pop("version") w.dirname = srcdir pathname = w.build(paths) self.assertTrue(os.path.exists(pathname)) paths = {"prefix": dstdir} for key in ("purelib", "platlib", "headers", "scripts", "data"): paths[key] = os.path.join(dstdir, key) w = Wheel(pathname) maker = ScriptMaker(None, None, add_launchers=False) maker.executable = os.path.join(paths["scripts"], "python") dist = w.install(paths, maker) self.assertIsNotNone(dist) self.assertEqual(dist.name, w.name) self.assertEqual(dist.version, w.version) shared = dist.shared_locations self.assertTrue(shared) os.remove(pathname) sm = Manifest(srcdir) sm.findall() sfiles = set([os.path.relpath(p, srcdir) for p in sm.allfiles]) dm = Manifest(dstdir) dm.findall() dfiles = set([os.path.relpath(p, dstdir) for p in dm.allfiles]) omitted = sfiles - dfiles omitted = omitted.pop() endings = os.path.join(".dist-info", "WHEEL"), ".pyc", ".pyo" self.assertTrue(omitted.endswith(endings))
def build_wheel(distname, options): result = None r = parse_requirement(distname) if not r: print('Invalid requirement: %r' % distname) else: dist = INSTALLED_DISTS.get_distribution(r.name) if dist: print('Can\'t build a wheel from already-installed ' 'distribution %s' % dist.name_and_version) else: workdir = tempfile.mkdtemp() # where the Wheel input files will live try: paths = install_dist(distname, workdir, options) paths['prefix'] = workdir wheel = Wheel() wheel.name = paths.pop('name') wheel.version = paths.pop('version') wheel.dirname = options.destdir wheel.build(paths) result = wheel finally: shutil.rmtree(workdir) return result