Esempio n. 1
0
def _remove_existing_entries(old, new):
    """Remove any entries of `old` that also exist in `new`.

    Args:
        old (list[:class:`parso.python.tree.String`]):
            The Rez requirements that may be removed.
        new (list[:class:`parso.python.tree.String`]):
            Any Rez requirements that should be removed from `old`.

    Returns:
        list[:class:`parso.python.tree.String`]:
            A modified version of `old` that doesn't contain anything from `new`.

    """
    old = copy.deepcopy(old)

    # Since `requires` doesn't really play nice with duplicate entries,
    # we will remove any existing requirements that match any entries in `new`.
    #
    for entry in reversed(new):
        new_requirement = rez_requirement.Requirement(_escape(entry.value))
        package_family = new_requirement.name

        for requirement in reversed(old):
            old_requirement = rez_requirement.Requirement(
                _escape(requirement.value))

            if old_requirement.name == package_family:
                index = old.index(requirement)

                del old[index]

    return old
Esempio n. 2
0
def _merge_list_entries(old, new):
    """Apply `new` onto `old`.

    Args:
        old (list[:class:`parso.python.tree.String`]):
            The Rez requirements that will be modified.
        new (list[:class:`parso.python.tree.String`]):
            New (or existing) Rez requirements to add on top of `old`.

    Returns:
        list[:class:`parso.python.tree.String`]: The merge of `old` and `new`.

    """
    def _find_index(nodes, text):
        for index, node in enumerate(nodes):
            requirement = _escape(node.value)
            requirement = rez_requirement.Requirement(requirement)

            if requirement.name > text:
                return index

        return len(nodes)

    old = _remove_existing_entries(old, new)

    for entry in new:
        requirement = rez_requirement.Requirement(_escape(entry.value))
        index = _find_index(old, requirement.name)
        old.insert(index, entry)

    return old
Esempio n. 3
0
def _expand(items):
    """Group every Rez and Python dot-separated Python namespaces.

    Args:
        items (iter[str]):
            Each Rez package definition + the Python
            dot-separated import namespaces.
            e.g. ["some_package-2,some_package.import_namespace.here,another.one"].

    Returns:
        list[tuple[:class:`rez.vendor.version.requirement.Requirement`, set[str]]]:
            Each user-provided Rez package and Python dot-separated
            import namespaces that the user wants ``rez_move_imports``
            to remember during the execution of the CLI.

    """
    output = collections.defaultdict(set)

    for package_and_namespaces in items:
        parts = _split_package_and_namespaces(package_and_namespaces)
        package = parts[0]
        namespaces = parts[1:]

        if not namespaces:
            raise exception.InvalidInput(
                'Text "{package_and_namespaces}" '
                "must be a list of Rez package + at least one Python namespace."
                "".format(package_and_namespaces=package_and_namespaces)
            )

        package = requirement.Requirement(package)
        output[package].update(namespaces)

    return list(output.items())
Esempio n. 4
0
def _get_platform():
    """str: Get the required platform name, if any."""
    for text in os.environ["REZ_USED_REQUEST"].split(" "):
        request = requirement.Requirement(text)

        if request.name == "platform" and not request.weak:
            return str(request.range)

    return ""
Esempio n. 5
0
    def _find_index(nodes, text):
        for index, node in enumerate(nodes):
            requirement = _escape(node.value)
            requirement = rez_requirement.Requirement(requirement)

            if requirement.name > text:
                return index

        return len(nodes)
Esempio n. 6
0
def _get_python_requires():
    """str: Get the required Python version, if any."""
    for text in os.environ["REZ_USED_REQUEST"].split(" "):
        request = requirement.Requirement(text)

        if request.name == "python" and not request.weak:
            # rez/utils/py_dist.py has convert_version, which apparently
            # shows that any Rez version syntax will work with dist. So
            # we'll do the same.
            #
            return str(request.range)

    return ""
Esempio n. 7
0
def _resolve_data_conflicts(new, existing):
    """Change the upper / lower bounds of each requirement in `new`, if needed.

    The logic goes like this:

    - Compare each requirement by-name in `new` and `existing`
        - Apply whichever requirement's lower bound is highest.
            - Because we probably need to apply a new requirement minimum.
        - Apply whichever requirement's upper bound is highest.
            - We assume that the user has taken into account the higher upper bound.

    Args:
        new (iter[str]):
            Each Rez package requirement to compare / change.
            e.g. ["foo-1+<2"].
        existing (iter[:class:`rez.vendor.version.requirement.Requirement`]):
            Each Rez requirement to compare against.

    Returns:
        list[str]: The newly generated requirements for `new`.

    """
    new = (rez_requirement.Requirement(requirement) for requirement in new)
    new = collections.OrderedDict([(requirement.name, requirement)
                                   for requirement in new])
    existing = {requirement.name: requirement for requirement in existing}

    for name, requirement in new.items():
        if name not in existing:
            continue

        range_ = existing[name].range
        lower = max([
            bound.lower for bound in itertools.chain(range_.bounds,
                                                     requirement.range.bounds)
            if bound.lower_bounded()
        ])
        upper = max([
            bound.upper for bound in itertools.chain(range_.bounds,
                                                     requirement.range.bounds)
            if bound.upper_bounded()
        ])
        temporary_range = rez_version.VersionRange.as_span(
            lower_version=lower.version,
            upper_version=upper.version,
            lower_inclusive=lower.inclusive,
            upper_inclusive=upper.inclusive,
        )
        requirement.range_ = temporary_range

    return [str(requirement) for requirement in new.values()]
Esempio n. 8
0
def _node_to_requirement(node):
    """:class:`rez.vendor.version.requirement.Requirement`: Convert an AST node to a Rez."""
    requirement_text = _escape(node.value)

    return rez_requirement.Requirement(requirement_text)