Beispiel #1
0
def test_requirements():
    assert setupmeta.pkg_req(None) is None
    assert setupmeta.pkg_req("#foo") is None

    assert setupmeta.requirements_from_file("/dev/null/foo") is None

    sample = conftest.resouce("scenarios/disabled/requirements.txt")
    f = setupmeta.RequirementsFile.from_file(sample)
    assert len(f.reqs) == 8
    assert str(
        f.reqs[0]
    ) == "wheel from tests/scenarios/disabled/requirements.txt:2, abstracted by default"
    assert str(
        f.reqs[4]
    ) == "-e git+git://example.com/p1.git#egg=flake8#egg=flake8 from tests/scenarios/disabled/requirements.txt:12"
    assert f.filled_requirements == [
        "wheel", "click; python_version >= '3.6'", "setuptools", "flake8",
        "pytest-cov"
    ]
    assert f.dependency_links == [
        "git+git://example.com/p1.git#egg=flake8",
        "https://example.com/a.git@u/pp",
        "file:///tmp/bar1",
        "file:///tmp/bar2",
    ]
    assert len(f.abstracted) == 2
    assert len(f.ignored) == 1
    assert len(f.untouched) == 1

    sample = conftest.resouce("scenarios/complex-reqs/requirements.txt")
    f = setupmeta.RequirementsFile.from_file(sample)
    assert len(f.reqs) == 5

    fr = setupmeta.requirements_from_file(sample)
    assert fr == f.filled_requirements

    sample = "a==1.0\nb; python_version >= '3.6'"
    f = setupmeta.RequirementsFile()
    f.scan(sample.splitlines())
    f.finalize()
    assert len(f.reqs) == 2
    assert f.filled_requirements == ["a", "b; python_version >= '3.6'"]
    assert not f.dependency_links
    assert len(f.abstracted) == 1
    assert len(f.ignored) == 0
    assert len(f.untouched) == 1

    fr = setupmeta.requirements_from_text(sample)
    assert fr == f.filled_requirements

    f = setupmeta.RequirementsFile()
    f.scan([])
    f.finalize()
    assert f.reqs == []
    assert f.filled_requirements == []
    assert f.dependency_links == []
    assert f.abstracted == []
Beispiel #2
0
    def get_packages(self, dependencies):
        result = []
        for dep in dependencies:
            p = self.get_package(setupmeta.pkg_req(dep))
            if p:
                result.append(p)

        return result
Beispiel #3
0
 def from_string(self, specs):
     result = []
     for spec in specs.split():
         name, _, req = spec.partition(":")
         if req:
             req = [setupmeta.pkg_req(r) for r in req.split("+")]
         else:
             req = []
         result.append(FakeDist(name, req))
     return result
Beispiel #4
0
 def __init__(self, obj, package):
     """
     :param pkg_resources.Requirement obj:
     :param PipPackage package: Associated package
     """
     self._obj = obj
     self.package = package
     self.key = obj.key
     self.version = package.version
     self.version_spec = ",".join(["".join(sp) for sp in sorted(obj.specs, reverse=True)])
     self.version_rec = setupmeta.pkg_req("%s%s" % (self.key, self.version_spec or ""))
     self.is_conflicting = not self.package.version or self.package.version not in self.version_rec
Beispiel #5
0
 def __init__(self, spec, requires):
     req = setupmeta.pkg_req(spec)
     self.key = req.key
     self.version = req.specs[0][1] if req.specs else "1.0"
     self._requires = requires