예제 #1
0
 def build_wheel_from_sdist(self, sdist):
     """
     Given a sdist archive extract it, build in a temporary directory, and
     put the wheel into the downloads directory.
     """
     temp = tempfile.mkdtemp()
     try:
         source = self.extract_sdist(sdist, temp)
         # Make sure to import setuptools and wheel in the setup.py.
         # This is happening in a temporary directory, so we will just
         # overwrite the setup.py to add our own imports.
         setup_py = os.path.join(source, "setup.py")
         with open(setup_py, "r") as f:
             original = f.read()
         with open(setup_py, "w") as f:
             f.write("import setuptools\n")
             f.write("import wheel\n")
             f.write(original)
         # Build the wheel
         command = [
             sys.executable,
             setup_py,
             "bdist_wheel",
             "-d",
             os.path.abspath(self._dest),
         ]
         subprocess.check_call(command, cwd=source)
     except subprocess.CalledProcessError:
         raise BuildException("Failed to build %s" %
                              str(os.path.basename(sdist)))
     finally:
         xar_util.safe_rmtree(temp)
예제 #2
0
    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)
예제 #3
0
 def make_test_directory(self):
     try:
         dir = tempfile.mkdtemp()
         with open(os.path.join(dir, "__main__.py"), "w") as f:
             f.write("print('python')")
         with open(os.path.join(dir, "other.py"), "w") as f:
             f.write("print('other')")
         with open(os.path.join(dir, "__main__.sh"), "w") as f:
             f.write("#!/bin/sh\necho shell")
         with tempfile.NamedTemporaryFile("w") as xarfile:
             yield xarfile.name, dir
     finally:
         xar_util.safe_rmtree(dir)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
 def tearDown(self):
     xar_util.safe_rmtree(self.src)
     xar_util.safe_rmtree(self.dst)