How to use the rez.vendor.version.requirement.Requirement function in rez

To help you get started, we’ve selected a few rez examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nerdvegas / rez / src / rezgui / dialogs / ResolveDialog.py View on Github external
def resolve(self):
        # validate the request before opening dialog
        for req_str in self.context_model.request:
            try:
                Requirement(req_str)
            except Exception as e:
                title = "Invalid package request - %r" % req_str
                QtWidgets.QMessageBox.critical(self, title, str(e))
                return

        self._reset()
        self.timer.start()
        self.exec_()

        if self.started:
            self.resolver.stop()

            if self.thread:
                self.thread.quit()
                self.thread.wait()
            return self.resolver.success()
github nerdvegas / rez / src / rezgui / widgets / PackageLineEdit.py View on Github external
def _update_status(self):
        def _ok():
            self._set_style()
            self.setToolTip("")

        def _err(msg, color="red"):
            self._set_style("QLineEdit { border : 2px solid %s;}" % color)
            self.setToolTip(msg)

        txt = str(self.text())
        if not txt:
            _ok()
            return

        try:
            req = Requirement(str(txt))
        except Exception as e:
            _err(str(e))
            return

        _ok()
        if not req.conflict:
            try:
                it = iter_packages(name=req.name,
                                   range_=req.range,
                                   paths=self._paths)
                pkg = sorted(it, key=lambda x: x.version)[-1]
            except Exception:
                _err("cannot find package: %r" % txt, "orange")
                return

            if pkg.description:
github nerdvegas / rez / src / rez / package_search.py View on Github external
def _parse_request(cls, resources_request):
        name_pattern = resources_request or '*'
        version_range = None

        try:
            req = Requirement(name_pattern)
            name_pattern = req.name
            if not req.range.is_any():
                version_range = req.range
        except:
            pass

        return name_pattern, version_range
github nerdvegas / rez / src / rez / utils / patching.py View on Github external
requires (list of str or `version.Requirement`): Request.
        patchlist (list of str): List of patch requests.

    Returns:
        List of `version.Requirement`: Patched request.
    """

    # rules from table in docstring above
    rules = {
        '':  (True,  True,  True ),
        '!': (False, False, False),
        '~': (False, False, True ),
        '^': (True,  True,  True )
    }

    requires = [Requirement(x) if not isinstance(x, Requirement) else x
                for x in requires]
    appended = []

    for patch in patchlist:
        if patch and patch[0] in ('!', '~', '^'):
            ch = patch[0]
            name = Requirement(patch[1:]).name
        else:
            ch = ''
            name = Requirement(patch).name

        rule = rules[ch]
        replaced = (ch == '^')

        for i, req in enumerate(requires):
            if req is None or req.name != name:
github nerdvegas / rez / src / rezgui / widgets / ContextTableWidget.py View on Github external
def _apply_resolve(self, context_model, column, reference_column,
                       hide_locks=False, read_only=False,
                       reference_column_is_variants=False):
        context = context_model.context()
        resolved = context.resolved_packages[:]
        consumed_rows = set()

        # match variants up with matching request/variant in source column
        for row, widget in self._iter_column_widgets(
                reference_column, (PackageSelectWidget, VariantCellWidget)):
            request_str = str(widget.text())
            if not request_str:
                continue

            package_name = Requirement(request_str).name
            matches = [x for x in resolved if x.name == package_name]
            if matches:
                variant = matches[0]
                resolved = [x for x in resolved if x.name != package_name]
                reference_variant = None
                if reference_column_is_variants and isinstance(widget, VariantCellWidget):
                    reference_variant = widget.variant
                self._set_variant_cell(row, column, context_model, variant,
                                       reference_variant=reference_variant,
                                       hide_locks=hide_locks, read_only=read_only)
            consumed_rows.add(row)

        # append variants that don't match reference requests/variants
        if reference_column_is_variants:
            hide_locks = True
        row = 0
github nerdvegas / rez / src / rezgui / widgets / BrowsePackageWidget.py View on Github external
def set_package_text(self, txt):
        try:
            req = Requirement(str(txt))
            package_name = req.name
            version_range = req.range
        except:
            package_name = str(txt)
            version_range = None

        self.edit.setText(package_name)
        self._set_package_name(package_name)

        if version_range is not None:
            self.versions_table.select_version(version_range)
github nerdvegas / rez / src / rez / utils / patching.py View on Github external
for i, req in enumerate(requires):
            if req is None or req.name != name:
                continue

            if not req.conflict:
                replace = rule[0]  # foo
            elif not req.weak:
                replace = rule[1]  # !foo
            else:
                replace = rule[2]  # ~foo

            if replace:
                if replaced:
                    requires[i] = None
                else:
                    requires[i] = Requirement(patch)
                    replaced = True

        if not replaced:
            appended.append(Requirement(patch))

    result = [x for x in requires if x is not None] + appended
    return result
github nerdvegas / rez / src / soma / profile.py View on Github external
def _add_override(key, value, level):
            entry = requires_.setdefault(key, (len(requires_), []))
            entry[1].append((value, level))

        overrides = self._get_overrides("requires")

        for level, requires_list in overrides:
            for request_str in requires_list:
                if request_str.startswith('^'):  # removal operator
                    key = request_str[1:]
                    _add_override(key, request_str, level)
                    _add_override('!' + key, request_str, level)
                else:
                    try:
                        request = Requirement(request_str)
                    except VersionError as e:
                        raise SomaDataError("Invalid request string %r in %r"
                                            % (request_str, self._filepath(level)))

                    key = request.name
                    if request.conflict:
                        key = '!' + key

                    _add_override(key, request, level)

        # remove removal operations that don't remove anything
        requires_list_ = []
        for index, overrides in requires_.itervalues():
            if any(isinstance(x[0], Requirement) for x in overrides):
                requires_list_.append((index, overrides))