Exemple #1
0
def test_parse_compatible3():
    specifier = "~=2.2.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("2.2")
    v2 = Version.parse("2.3")
    expected = Range(v, v2, True, False)

    assert [expected] == p.parse_specifier(specifier)
Exemple #2
0
    def convert_requirement(self, requirement):
        # convert requirement to the type which mixology recongize
        # requirement -> constraint

        if isinstance(requirement, ExplicitRequirement):
            # may occur problem because of unclean specifier
            #for_constraint = re.split(r'(===|==|~=|!=|>=|>|<=|<)', requirement.candidate.version)
            return Constraint(
                Package(requirement.name),
                Range(Version.parse(requirement.candidate.version),
                      Version.parse(requirement.candidate.version), True,
                      True))

        elif isinstance(requirement, SpecifierRequirement):

            specs = requirement._ireq.req.specifier
            ranges = []
            if len(specs) == 0:
                # print("0")
                ranges = Range()
                ranges = [ranges]
            for spec in specs:
                s = spec.__str__()
                temp_ranges = self.parse_specifier(s)
                ranges = ranges + temp_ranges

            # if there is a range only, error may happen (this problem is from "union and range" )
            if len(ranges) == 1:
                # print("ranges == 1")
                constraint = (Constraint(Package(requirement.name), ranges[0]))
            else:
                constraint = (Constraint(Package(requirement.name),
                                         Union(*ranges)))

        elif isinstance(requirement, RequiresPythonRequirement):

            specs = requirement.specifier
            ranges = []
            if len(specs) == 0:
                # print("0")
                ranges = Range()
                ranges = [ranges]
            for spec in specs:
                s = spec.__str__()
                temp_ranges = self.parse_specifier(s)
                ranges = ranges + temp_ranges

            # if there is a range only, error may happen (this problem is from "union and range" )
            if len(ranges) == 1:
                # print("ranges == 1")
                constraint = (Constraint(Package(requirement.name), ranges[0]))
            else:
                constraint = (Constraint(Package(requirement.name),
                                         Union(*ranges)))
        else:
            print("some error happen")

        return constraint
def test_dependencies_for():
    pkg = Package("mixology")

    v = Version.parse("2.1.0")

    Mock = MockProvider()
    p = PackageSource(Mock, None)
    p.package[pkg] = {}
    p.package[pkg][v] = Candidate("mixology", "2.1.0")

    expected_range1 = Range(Version(1, 1, 0), Version(1, 1, 0), True, True)
    expected_constraint = Constraint(Package('pub'), expected_range1)
    expected_range2 = Range(Version(1, 2, 0), Version(1, 2, 0), True, True)
    expected_constraint2 = Constraint(Package('pub'), expected_range2)
    expected = [expected_constraint, expected_constraint2]

    assert expected == p.dependencies_for(pkg, v)


# def test_package_build():
#     p = PackageSource(MockProvider, None)
#     pkg = Package("mixology")
#     v = Version.parse("2.1.0")

#     p.dependencies_for(pkg, v)

#     # rrr what do package saved
#     assert p.package["pub"]["1.0.0"] ==
Exemple #4
0
def test_parse_equal():
    specifier = "==1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(v, v, True, True)

    assert [expected] == p.parse_specifier(specifier)
Exemple #5
0
def test_parse_not_equal():
    specifier = "!=1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = [Range(v, None, False, False), Range(None, v, False, False)]

    assert expected == p.parse_specifier(specifier)
Exemple #6
0
def test_parse_smaller_include():
    specifier = "<=1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(None, v, False, True)

    assert [expected] == p.parse_specifier(specifier)
Exemple #7
0
def test_parse_bigger():
    specifier = ">1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(v, None, False, False)

    assert [expected] == p.parse_specifier(specifier)
Exemple #8
0
    def __init__(self, provider, root_requirement):
        self._root_version = Version.parse("0.0.0")
        self.provider = provider
        self.package = {
        }  # store candidate {package(class)):{version(class):candidate}}
        # must be list
        self.root_requirements = root_requirement  # list[requirement] must be list

        super(PackageSource, self).__init__()
Exemple #9
0
    def dependencies_for(
        self, package, version
    ):  # type: (Hashable(package(class)), Any(version(version))) -> List[dependency]

        if package == self.root:
            requirements = self.root_requirements
        else:
            candidate = self.package[package][version]
            requirements = self.provider.get_dependencies(candidate)

        # put candidate in requirement to self.package
        # in this way may take a lot of time in provider.find_match()
        # the better way is that chaeck self.package first if what requirement want
        # is already in self.package we would not call provider.find_match
        # if not call provider.find_match

        dependencies = []  # Constraint
        for requirement in requirements:

            if requirement.name not in self.package:
                package = Package(requirement.name)
                self.package[package] = {}

            candidates = self.provider.find_match(requirement)

            for candidate in candidates:
                version = Version.parse(candidate.version)
                package = Package(requirement.name)
                self.package[requirement.name][version] = candidate

            # change requirement to dependency (specifier to constraint)
            # and return dependency
            # requirements
            dependencies.append(self.convert_requirement(requirement))

        return dependencies
Exemple #10
0
    def parse_specifier(self, spec):
        # import pdb
        # pdb.set_trace()
        op_and_version = re.split(r'(===|==|~=|!=|>=|>|<=|<|\*)',
                                  spec)  #list of str
        if op_and_version[1] == '===':
            # I surrender. I think it can't be transformed to range
            return [Range()]

        elif op_and_version[1] == '==' and len(op_and_version) != 4:

            min = Version.parse(op_and_version[2])
            max = Version.parse(op_and_version[2])
            return [Range(min, max, True, True)]

        elif op_and_version[1] == '~=' or (op_and_version[1] == '=='
                                           and len(op_and_version) == 4):

            count = len(op_and_version[2].split('.'))

            min = Version.parse(op_and_version[2])
            max = Version.parse(op_and_version[2])

            if count == 2:
                max = max._increment_major()
            elif count == 3:
                max = max._increment_minor()
            # import pdb
            # pdb.set_trace()
            return [Range(min, max, True, False)]

        elif op_and_version[1] == '!=':
            # separate into two range

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=False,
                      include_max=False),
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=False)
            ]

        elif op_and_version[1] == '>=':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=True,
                      include_max=False)
            ]

        elif op_and_version[1] == '>':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=False,
                      include_max=False)
            ]

        elif op_and_version[1] == '<=':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=True)
            ]

        elif op_and_version[1] == '<':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=False)
            ]

        else:
            print("error")

        return 0
Exemple #11
0
def test_init():
    p = PackageSource(PipProvider, None)
    v = Version.parse("0.0.0")

    assert p.root_version == v