def test_wheel_copy_installation(self): dist = mock.MagicMock() dist.location = "/path/to/lib/xar" dist.egg_info = "/path/to/lib/xar-18.7.12.dist-info" wheel = py_util.Wheel(distribution=dist) wheel.is_purelib = mock.MagicMock(return_value=True) wheel.records = mock.MagicMock(return_value=[ [ "xar/0", "sha256=uU0nuZNNPgilLlLX2n2r-sSE7-N6U4DukIj3rOLvzek", 11 ], ["xar/1", "", 11], [ "xar/2", "sha256=uU0nuZNNPgilLlLX2n2r-sSE7-N6U4DukIj3rOLvzek", 11 ], [ "xar/2", "sha256=uU0nuZNNPgilLlLX2n2r-sSE7-N6U4DukIj3rOLvzek", 11 ], ]) src = tempfile.mkdtemp() os.mkdir(os.path.join(src, "xar")) dst = tempfile.mkdtemp() for file, _, _ in wheel.records(): with open(os.path.join(src, file), "wb") as f: f.write(b"hello world") def temppaths(root): return { "purelib": root, "platlib": root, "headers": os.path.join(root, "include/xar"), "scripts": os.path.join(root, "bin"), "data": root, } wheel.copy_installation(temppaths(src), temppaths(dst)) for file, hash, _ in wheel.records(): dst_file = os.path.join(dst, file) self.assertTrue(os.path.exists(dst_file)) matches = py_util.does_sha256_match(dst_file, hash) if hash: self.assertTrue(matches) else: self.assertFalse(matches) xar_util.safe_rmtree(src) xar_util.safe_rmtree(dst)
def _add_distribution(self, xar): bdist_wheel = self.reinitialize_command("bdist_wheel") bdist_wheel.skip_build = self.skip_build bdist_wheel.keep_temp = self.keep_temp bdist_wheel.bdist_dir = os.path.join(self.bdist_dir, "wheel-bdist") bdist_wheel.dist_dir = os.path.join(self.bdist_dir, "wheel-dist") bdist_wheel.universal = False bdist_wheel.exclude_source_files = self.exclude_source_files bdist_wheel.distribution.dist_files = [] self.run_command("bdist_wheel") assert len(bdist_wheel.distribution.dist_files) == 1 wheel = bdist_wheel.distribution.dist_files[0][2] dist = py_util.Wheel(location=wheel).distribution xar.add_distribution(dist) return dist
def test_wheel_install(self): archived_wheel = py_util.Wheel(location=TESTWHEEL) src = tempfile.mkdtemp() dst = tempfile.mkdtemp() src_paths = self._temppaths(src) dst_paths = self._temppaths(dst) # Install the archive to src archived_wheel.install(None, src_paths) self._check_install(src_paths) # Copy the installation to dst src_location = os.path.join(src, "test-1.0.dist-info") self.assertFalse(py_util.Wheel.is_wheel_archive(src_location)) installed_wheel = py_util.Wheel(location=src_location) installed_wheel.install(src_paths, dst_paths, force=False) self._check_install(dst_paths) # Reinstall copy to dst with force installed_wheel.install(src_paths, dst_paths, force=True) self._check_install(dst_paths) xar_util.safe_rmtree(src) xar_util.safe_rmtree(dst)
def test_wheel_install_archive(self): print(TESTWHEEL) self.assertTrue(py_util.Wheel.is_wheel_archive(TESTWHEEL)) wheel = py_util.Wheel(location=TESTWHEEL) dst = tempfile.mkdtemp() paths = self._temppaths(dst) # Install without force wheel.install_archive(paths, force=False) self._check_install(paths) # Reinstall with force wheel.install_archive(paths, force=True) self._check_install(paths) xar_util.safe_rmtree(dst)
def add_distribution(self, distribution): """ Add a `pkg_resources.Distribution` to the XAR. The distribution must be a wheel, but it may be either a zipfile or already unpacked. Handles all the installation, and adding the distribution to the Python path. """ self._ensure_unfrozen() # We only support wheels. if not distribution.has_metadata(py_util.Wheel.WHEEL_INFO): raise self.InvalidDistributionError( "'%s' is not a wheel! It might be an egg, try reinstalling as " "a wheel." % distribution.project_name) wheel = py_util.Wheel(distribution=distribution) sys_paths = wheel.sys_install_paths() xar_paths = self._xar_install_paths(wheel.name, absolute=True) wheel.install(sys_paths, xar_paths, force=False) self._distributions.add(wheel.distinfo_location(xar_paths))
def test_wheel_determine_kind_mac(self): distribution = mock.MagicMock(egg_info="xar-18.6.11-py3-none-any.whl") wheel = py_util.Wheel(distribution=distribution) lib = "/usr/lib/python/site-packages" paths = { "purelib": lib, "platlib": lib, "headers": "/bad/prefix/include/xar", "scripts": "/bad/prefix/bin", "data": "/bad/prefix", } k, p = wheel._determine_kind(lib, paths, paths, lib + "/tmp") self.assertTrue(k == "purelib" or k == "platlib") self.assertEqual(p, lib) k, p = wheel._determine_kind(lib, paths, paths, "/usr/none") self.assertEqual(k, "data") self.assertEqual(p, "/usr") k, p = wheel._determine_kind(lib, paths, paths, "/usr/bin/make_xar") self.assertEqual(k, "scripts") self.assertEqual(p, "/usr/bin") k, p = wheel._determine_kind(lib, paths, paths, "/usr/include/xar/x") self.assertEqual(k, "headers") self.assertEqual(p, "/usr/include/xar")
def test_wheel_is_purelib(self): print(TESTWHEEL) wheel = py_util.Wheel(location=TESTWHEEL) self.assertFalse(wheel.is_purelib())
def test_wheel_sys_install_paths(self): print(TESTWHEEL) wheel = py_util.Wheel(location=TESTWHEEL) sys_paths = wheel.sys_install_paths() for path in self._temppaths(""): self.assertTrue(path in sys_paths)
def find_wheels_in_zip(importer, path_item, only=False): try: yield py_util.Wheel(location=path_item, importer=importer).distribution except Exception: pass
def _fixup_distributions(self): """Fixup the distributions.""" for distinfo_location in self._distributions: wheel = py_util.Wheel(location=distinfo_location) xar_paths = self._xar_install_paths(wheel.name, absolute=True) wheel.fixup(xar_paths)