Beispiel #1
0
    def test_dependencies(self):
        # Given
        egg = LEGACY_EGG_INFO_EGG
        source = os.path.join(self.prefix, os.path.basename(egg))
        shutil.copy(egg, source)
        r_runtime_dependencies = EggMetadata.from_egg(egg).runtime_dependencies

        target = os.path.join(self.prefix, egg)

        # When
        repack(source, 11, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        metadata = EggMetadata.from_egg(target)
        self.assertEqual(metadata.runtime_dependencies, r_runtime_dependencies)
def iter_invalid_unicode(top):
    for root, dirs, files in os.walk(top):
        print(root, file=sys.stderr)
        nfiles = len(files)
        for i, f in enumerate(files):
            if i % 100 == 0:
                print("{}/{}".format(i, nfiles), end="\r", file=sys.stderr)
                sys.stderr.flush()
            if f.endswith(".egg"):
                path = os.path.normpath(os.path.abspath(os.path.join(root, f)))
                try:
                    EggMetadata.from_egg(path)
                except OkonomiyakiError as e:
                    msg = "Okonomiyaki error parsing {!r} ({!r})"
                    print(msg.format(path, str(e)), file=sys.stderr)
                except UnicodeDecodeError:
                    yield path
Beispiel #3
0
    def test_repack_metadata_version_control(self, ignored):
        # Given
        source = os.path.join(self.prefix, "nose-1.2.1-py2.7.egg")
        shutil.copy(STANDARD_EGG, source)

        target = os.path.join(self.prefix, "nose-1.2.1-1.egg")

        # When
        repack(source, 1)

        # Then
        self.assertTrue(os.path.exists(target))
        metadata = EggMetadata.from_egg(target)
        self.assertEqual(metadata.metadata_version, DEFAULT_METADATA_VERSION)

        # When
        repack(source, 1, metadata_version=MetadataVersion(1, 2))

        # Then
        self.assertTrue(os.path.exists(target))
        metadata = EggMetadata.from_egg(target)
        self.assertEqual(metadata.metadata_version, MetadataVersion(1, 2))
Beispiel #4
0
    def test_enthought_name_upper_case(self):
        # Given
        source = os.path.join(self.prefix,
                              os.path.basename(MKL_10_3))
        shutil.copy(MKL_10_3, source)

        target = os.path.join(self.prefix, "MKL-10.3-11.egg")

        # When
        repack(source, 11, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        metadata = EggMetadata.from_egg(target)
        self.assertEqual(metadata.egg_basename, "MKL")
def build_list(top):
    ret = collections.defaultdict(dict)

    for root, dirs, files in os.walk(top):
        for f in files:
            principal = os.path.splitext(f)[0].lower()
            if f.endswith(".egg") and principal in names:
                path = os.path.join(root, f)
                try:
                    metadata = EggMetadata.from_egg(path)
                except zipfile.BadZipfile:
                    pass
                else:
                    ret[f][compute_sha256(path)] = "py27"
    return dict(ret)
def dummy_egg_from_egg(existing_egg, force=False, platform=None):
    metadata = EggMetadata.from_egg(existing_egg)
    if platform is not None:
        metadata.platform = platform

    if os.path.exists(metadata.egg_name):
        if force:
            os.unlink(metadata.egg_name)
        else:
            raise ValueError(
                "file {0!r} already exists.".format(metadata.egg_name)
            )

    metadata.metadata_version_info = (1, 3)
    with EggBuilder(metadata) as builder:
        pass

    return metadata.egg_name
Beispiel #7
0
    def test_no_pkg_info(self):
        # Given
        path = os.path.join(
            self.tempdir, os.path.basename(NOSE_1_3_4_RH5_X86_64)
        )
        m = EggMetadata.from_egg(NOSE_1_3_4_RH5_X86_64)
        m._pkg_info = None
        m.dump(path)

        # When/Then
        with testfixtures.OutputCapture() as capture:
            with self.assertRaises(SystemExit) as exc:
                main(["pkg-info", path])
            if sys.version_info < (2, 7):
                code = exc.exception
            else:
                code = exc.exception.code
            self.assertEqual(code, -1)

        capture.compare("No PKG-INFO")
def may_be_invalid(path):
    principal = os.path.splitext(os.path.basename(path))[0].lower()

    with zipfile2.ZipFile(path) as zp:
        metadata = EggMetadata.from_egg(zp)

        name = _get_name(zp, metadata)
        if name is not None:
            print(
                "CP27 {} (because of {})".format(path, name),
                file=sys.stderr
            )
            return u"cp27"
        elif principal in PY27_INVALID_LIST:
            if metadata.python is None:
                print("PY27 {}".format(path), file=sys.stderr)
                return u"py27"
        elif principal in CP27_INVALID_LIST:
            if metadata.python is None:
                print("CP27 {}".format(path), file=sys.stderr)
                return u"cp27"
        return None
Beispiel #9
0
def _get_spec_data(source_egg_path, build_number, platform_string=None,
                   python=_UNSPECIFIED, abi_tag=_UNSPECIFIED):
    if _looks_like_setuptools_egg(source_egg_path):
        parsed_platform_string = parse_filename(source_egg_path)[3]
        if parsed_platform_string is not None and platform_string is None:
            msg = ("Platform-specific egg detected (platform string is "
                   "{0!r}), you *must* specify the platform.")
            raise EnstallerException(msg.format(parsed_platform_string))

        if platform_string is not None:
            platform = EPDPlatform.from_epd_string(platform_string)
        else:
            platform = None
        metadata = SetuptoolsEggMetadata.from_egg(
            source_egg_path, platform, python, abi_tag
        )
        egg_basename = metadata.name
        version = str(metadata.version)
        dependencies = []
    elif _looks_like_enthought_egg(source_egg_path):
        metadata = EggMetadata.from_egg(source_egg_path)
        # The name as used in spec/depend and endist.dat is the so-called
        # egg basename (i.e. not normalied to lower case)
        egg_basename = metadata.egg_basename
        version = metadata.upstream_version
        dependencies = metadata.runtime_dependencies
    else:
        msg = "Unrecognized format: {0!r}".format(source_egg_path)
        raise EnstallerException(msg)

    data = {"build": build_number, "packages": dependencies,
            "name": egg_basename, "version": version}

    if os.path.exists(ENDIST_DAT):
        data.update(_parse_endist_for_spec_depend(ENDIST_DAT))

    return data, metadata
 def test(self):
     EggMetadata.from_egg(path, strict=strict)