Ejemplo n.º 1
0
    def test_sort_packages(self):
        """Test sorting direct dependencies based on semver."""
        tf_1_9_0 = PackageVersion(
            name="tensorflow",
            version="==1.9.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )
        tf_2_0_0 = PackageVersion(
            name="tensorflow",
            version="==2.0.0",
            index=Source(
                "https://tensorflow.pypi.thoth-station.ninja/index/manylinux2010/jemalloc/simple/"
            ),
            develop=False,
        )
        tf_1_1_0 = PackageVersion(
            name="tensorflow",
            version="==1.1.0",
            index=Source(
                "https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"
            ),
            develop=False,
        )
        package_versions = [tf_1_9_0, tf_2_0_0, tf_1_1_0]
        sieve_context = SieveContext.from_package_versions(package_versions)

        sieve = SemverSortSieve(graph=None, project=None)
        sieve.run(sieve_context)

        result = sieve_context.iter_direct_dependencies()
        assert list(result) == [tf_1_1_0, tf_1_9_0, tf_2_0_0]
Ejemplo n.º 2
0
    def test_remove_latest_versions(self):
        """Test removing direct dependencies based on latest version limitation."""
        tf_1_1_0 = PackageVersion(
            name="tensorflow",
            version="==1.1.0",
            index=Source(
                "https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"
            ),
            develop=False,
        )
        tf_1_9_0 = PackageVersion(
            name="tensorflow",
            version="==1.9.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )
        tf_2_0_0 = PackageVersion(
            name="tensorflow",
            version="==2.0.0",
            index=Source(
                "https://tensorflow.pypi.thoth-station.ninja/index/manylinux2010/jemalloc/simple/"
            ),
            develop=False,
        )

        sieve = LimitLatestVersionsSieve(graph=None, project=None)
        sieve.update_parameters(dict([("limit_latest_versions", 1)]))

        sieve_context = SieveContext.from_package_versions(
            [tf_1_1_0, tf_1_9_0, tf_2_0_0])

        sieve.run(sieve_context)

        result = list(sieve_context.iter_direct_dependencies())
        assert result == [tf_2_0_0]
Ejemplo n.º 3
0
    def test_os_sieve_no_error(self):
        """Test no error raised if no packages satisfy OS specific requirements."""
        package_versions = [
            PackageVersion(
                name="tensorflow",
                version="==1.9.0",
                index=Source(
                    "https://tensorflow.pypi.thoth-station.ninja/index/fedora/30/jemalloc/simple/"
                ),
                develop=False,
            )
        ]

        sieve_context = SieveContext.from_package_versions(package_versions)
        project = Project.from_strings(
            pipfile_str=self._PIPFILE_CONTENT_AICOE,
            runtime_environment=RuntimeEnvironment.from_dict(
                {"operating_system": {
                    "name": "ubi",
                    "version": "9"
                }}))
        os_sieve = OperatingSystemSieve(graph=None, project=project)
        os_sieve.run(sieve_context)

        assert set(sieve_context.iter_direct_dependencies_tuple()) == {
            ("tensorflow", "1.9.0",
             "https://tensorflow.pypi.thoth-station.ninja/index/fedora/30/jemalloc/simple/"
             ),
        }
Ejemplo n.º 4
0
    def test_os_sieve(self):
        """Test removal of packages based on AICoE package source index configuration.

        We keep only TensorFlow release which is from PyPI and manylinux2010 build as there is no match on OS release.
        """
        package_versions = self._get_packages_aicoe()
        sieve_context = SieveContext.from_package_versions(package_versions)

        # Do not assign runtime environment intentionally - it will default to no environment.
        project = Project.from_strings(
            pipfile_str=self._PIPFILE_CONTENT_AICOE,
            runtime_environment=RuntimeEnvironment.from_dict(
                {"operating_system": {
                    "name": "rhel",
                    "version": "7.5"
                }}))
        os_sieve = OperatingSystemSieve(graph=None, project=project)
        os_sieve.run(sieve_context)

        expected = {
            ("pytest", "3.0.0", "https://pypi.org/simple"),
            ("tensorflow", "1.9.0", "https://pypi.org/simple"),
            # Filtering out this entry is left on another sieve which ensures runtime environment compatibility.
            ("tensorflow", "1.9.0",
             "https://tensorflow.pypi.thoth-station.ninja/index/manylinux2010/jemalloc/simple/"
             ),
            # These are filtered out:
            # ("tensorflow", "1.9.0", "https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"),
            # ("tensorflow", "1.9.0", "https://tensorflow.pypi.thoth-station.ninja/index/os/rhel/7.6/jemalloc/simple/")
        }

        assert set(sieve_context.iter_direct_dependencies_tuple()) == expected
Ejemplo n.º 5
0
 def test_noop(self):
     """Test no operation performed on top of sieve context."""
     package_versions = self._get_package_versions()
     sieve_context = SieveContext.from_package_versions(package_versions)
     assert set(dep.to_tuple() for dep in package_versions) == set(
         dep.to_tuple() for dep in sieve_context.iter_direct_dependencies())
     assert set(dep.to_tuple() for dep in package_versions) == set(
         sieve_context.iter_direct_dependencies_tuple())
Ejemplo n.º 6
0
    def test_remove_error(self):
        """Test removal of a package which has no other candidate - an exception should be raised."""
        package_versions = self._get_package_versions()

        sieve_context = SieveContext.from_package_versions(package_versions)

        to_remove = package_versions.pop(0)
        with pytest.raises(CannotRemovePackage):
            sieve_context.remove_package(to_remove)
Ejemplo n.º 7
0
    def test_remove_single(self):
        """Test removal of a single dependency."""
        package_versions = self._get_package_versions()

        sieve_context = SieveContext.from_package_versions(package_versions)

        to_remove = package_versions.pop(-1)
        sieve_context.remove_package(to_remove)
        assert set(dep.to_tuple() for dep in package_versions) == set(
            sieve_context.iter_direct_dependencies_tuple())
Ejemplo n.º 8
0
    def test_remove_multiple_error(self):
        """Test removal of multiple packages which causes error."""
        package_versions = self._get_package_versions()

        sieve_context = SieveContext.from_package_versions(package_versions)

        to_remove = package_versions.pop(-1)
        sieve_context.remove_package(to_remove)
        to_remove = package_versions.pop(-1)
        with pytest.raises(CannotRemovePackage):
            sieve_context.remove_package(to_remove)
Ejemplo n.º 9
0
    def test_sort_packages(self):
        a_pkg = PackageVersion(
            name="a",
            version="==1.0.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )
        b_pkg = PackageVersion(
            name="b",
            version="==2.0.0",
            index=Source("https://tensorflow.pypi.thoth-station.ninja/simple"),
            develop=False,
        )
        c_pkg = PackageVersion(
            name="c",
            version="==1.0.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )
        packages = [a_pkg, c_pkg, b_pkg]

        sieve_context = SieveContext.from_package_versions(packages)
        # (a.name > b.name) - (a.name < b.name) is idiom for C-style like strcmp()
        sieve_context.sort_packages(lambda a, b: (a.name > b.name) -
                                    (a.name < b.name),
                                    reverse=True)
        assert list(
            sieve_context.iter_direct_dependencies()) == [c_pkg, b_pkg, a_pkg]

        sieve_context.sort_packages(lambda a, b: (a.name > b.name) -
                                    (a.name < b.name),
                                    reverse=False)
        result = list(sieve_context.iter_direct_dependencies())
        assert result == [a_pkg, b_pkg, c_pkg]

        # Now we sort based on version - as sorting is stable, we should preserve relative order of a and c.
        sieve_context.sort_packages(
            lambda a, b: (a.semantic_version > b.semantic_version) -
            (a.semantic_version < b.semantic_version),
            reverse=False,
        )
        result = list(sieve_context.iter_direct_dependencies())
        assert result == [a_pkg, c_pkg,
                          b_pkg], "Sorting of packages is not stable"

        sieve_context.sort_packages(
            lambda a, b: (a.semantic_version > b.semantic_version) -
            (a.semantic_version < b.semantic_version),
            reverse=True,
        )
        result = list(sieve_context.iter_direct_dependencies())
        assert result == [b_pkg, a_pkg,
                          c_pkg], "Sorting of packages is not stable"
Ejemplo n.º 10
0
    def test_noop_no_aicoe(self):
        """Test no changes are made if no AICoE releases are found."""
        package_versions = self._get_packages_no_aicoe()
        sieve_context = SieveContext.from_package_versions(package_versions)

        # Do not assign runtime environment intentionally - it will default to no environment.
        project = Project.from_strings(
            pipfile_str=self._PIPFILE_CONTENT_NO_AICOE)
        os_sieve = OperatingSystemSieve(graph=None, project=project)
        os_sieve.run(sieve_context)

        assert {pv.to_tuple()
                for pv in package_versions
                } == set(sieve_context.iter_direct_dependencies_tuple())
Ejemplo n.º 11
0
    def test_remove_multiple(self):
        """Test removal of multiple packages."""
        package_versions = self._get_package_versions()

        sieve_context = SieveContext.from_package_versions(package_versions)

        # Remove b==1.0.0 and c==2.0.0 which have alternatives.
        to_remove = package_versions.pop(1)
        sieve_context.remove_package(to_remove)
        to_remove = package_versions.pop(-1)
        sieve_context.remove_package(to_remove)

        assert set(dep.to_tuple() for dep in package_versions) == set(
            sieve_context.iter_direct_dependencies_tuple())
Ejemplo n.º 12
0
    def test_remove_not_listed(self):
        """Test removal of a not listed package."""
        package_versions = self._get_package_versions()

        sieve_context = SieveContext.from_package_versions(package_versions)

        to_remove = PackageVersion(
            name="thispackageisnotlistedinthepackageversionslisting",
            version="==2.0.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        with pytest.raises(PackageNotFound):
            sieve_context.remove_package(to_remove)
Ejemplo n.º 13
0
    def test_pre_releases_allowed(self):
        """Test no removals if pre-releases are allowed."""
        tf_2_0_0rc0 = PackageVersion(
            name="tensorflow",
            version="==2.0.0rc0",
            index=Source("https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"),
            develop=False,
        )
        tf_2_0_0rc1 = PackageVersion(
            name="tensorflow",
            version="==2.0.0rc1",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        sieve = CutPreReleasesSieve(graph=None, project=Project.from_strings(self._CASE_ALLOWED_PIPFILE))
        sieve_context = SieveContext.from_package_versions([tf_2_0_0rc0, tf_2_0_0rc1])
        result = list(sieve_context.iter_direct_dependencies())
        assert result == [tf_2_0_0rc0, tf_2_0_0rc1]
Ejemplo n.º 14
0
    def test_remove_pre_releases_error(self):
        """Test error when removing all packages of a type which are pre-releases from software stack."""
        tf_2_0_0rc0 = PackageVersion(
            name="tensorflow",
            version="==2.0.0rc0",
            index=Source("https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"),
            develop=False,
        )
        tf_2_0_0rc1 = PackageVersion(
            name="tensorflow",
            version="==2.0.0rc1",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        sieve = CutPreReleasesSieve(graph=None, project=Project.from_strings(self._CASE_PIPFILE))
        sieve_context = SieveContext.from_package_versions([tf_2_0_0rc0, tf_2_0_0rc1])

        with pytest.raises(CannotRemovePackage):
            sieve.run(sieve_context)
Ejemplo n.º 15
0
    def test_remove_pre_releases(self):
        """Test removing direct dependencies not hitting limit causes a noop."""
        tf_1_1_0 = PackageVersion(
            name="tensorflow",
            version="==1.1.0",
            index=Source("https://tensorflow.pypi.thoth-station.ninja/index/os/fedora/30/jemalloc/simple/"),
            develop=False,
        )
        tf_2_0_0rc = PackageVersion(
            name="tensorflow",
            version="==2.0.0rc0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        sieve = CutPreReleasesSieve(graph=None, project=Project.from_strings(self._CASE_PIPFILE))
        sieve_context = SieveContext.from_package_versions([tf_1_1_0, tf_2_0_0rc])
        sieve.run(sieve_context)
        result = list(sieve_context.iter_direct_dependencies())
        assert result == [tf_1_1_0]
Ejemplo n.º 16
0
    def test_os_sieve_no_remove(self):
        """Test the TensorFlow package is not removed as it has no other candidate."""
        package_versions = [
            PackageVersion(
                name="tensorflow",
                version="==1.9.0",
                index=Source(
                    "https://tensorflow.pypi.thoth-station.ninja/index/fedora/30/jemalloc/simple/"
                ),
                develop=False,
            ),
            PackageVersion(
                name="pytest",
                version="==3.0.0",
                index=Source("https://pypi.org/simple"),
                develop=True,
            ),
        ]
        sieve_context = SieveContext.from_package_versions(package_versions)

        # Do not assign runtime environment intentionally - it will default to no environment.
        project = Project.from_strings(
            pipfile_str=self._PIPFILE_CONTENT_AICOE,
            runtime_environment=RuntimeEnvironment.from_dict(
                {"operating_system": {
                    "name": "rhel",
                    "version": "7.5"
                }}))
        os_sieve = OperatingSystemSieve(graph=None, project=project)
        os_sieve.run(sieve_context)

        expected = {
            ("pytest", "3.0.0", "https://pypi.org/simple"),
            ("tensorflow", "1.9.0",
             "https://tensorflow.pypi.thoth-station.ninja/index/fedora/30/jemalloc/simple/"
             ),
        }

        assert set(sieve_context.iter_direct_dependencies_tuple()) == expected