Skip to content

An exception is raised when combining filters with - and without -. #1037

Closed
@jasperges

Description

Rez version: 2.75.0
Platform and OS: Linux - Fedora 33

Problem

When doing a Rez resolve with inclusion or exclusion filters an exception is raised if one or more filters contain a - and others don't. For example:

rez-env os --exclude "*.beta" "os-windows*"

Traceback (most recent call last):
  File "/opt/rez/bin/rez/rez-env", line 8, in <module>
    sys.exit(run_rez_env())
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_entry_points.py", line 143, in run_rez_env
    return run("env")
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_main.py", line 170, in run
    returncode = run_cmd()
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_main.py", line 162, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/env.py", line 198, in command
    context = ResolvedContext(
  File "/opt/rez/lib64/python3.9/site-packages/rez/resolved_context.py", line 293, in __init__
    resolver = Resolver(context=self,
  File "/opt/rez/lib64/python3.9/site-packages/rez/resolver.py", line 80, in __init__
    self.package_filter_hash = package_filter.sha1
  File "/opt/rez/lib64/python3.9/site-packages/rez/package_filter.py", line 72, in sha1
    return sha1(str(self).encode("utf-8")).hexdigest()
  File "/opt/rez/lib64/python3.9/site-packages/rez/package_filter.py", line 279, in __str__
    filters = sorted(self.filters, key=lambda x: (x.cost, str(x)))
  File "/opt/rez/lib64/python3.9/site-packages/rez/package_filter.py", line 279, in <lambda>
    filters = sorted(self.filters, key=lambda x: (x.cost, str(x)))
  File "/opt/rez/lib64/python3.9/site-packages/rez/package_filter.py", line 203, in __str__
    return str((sorted(self._excludes.items()),
TypeError: '<' not supported between instances of 'str' and 'NoneType'

If you change the second filter to os*windows* it works.

When looking at the source code the problem is because the filters get grouped by family. "os-windows*" would be grouped by "os" while "*.beta" would be grouped under None. Then Rez tries to sort the filters by family, but you of course can't sort None and "os". (Printing the excludes makes it more clear: {None: [glob(*.beta)], 'os': [glob(os-windows*)]}).

Proposed solution

Add a function that can be passed to the key argument of sorted(). That function would convert everything to strings, so the sorting works properly. That would mean None would be turned into "None". Probably it would be nicer to convert None into an empty string.

If the proposed solution seems okay, I can make a merge request if needed. Merge request: #1038

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions