Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jasperges opened this issue Mar 9, 2021 · 1 comment
Closed

Comments

@jasperges
Copy link
Contributor

jasperges commented Mar 9, 2021

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

@jasperges jasperges changed the title An exception is raise when combining filters with - and without -. An exception is raised when combining filters with - and without -. Mar 11, 2021
@nerdvegas
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants