rez.package_filter

class rez.package_filter.PackageFilterBase

Bases: object

Base class for package filters.

excludes(package: Package) Rule | None

Determine if the filter excludes the given package.

Parameters:

package (Package) – Package to filter.

Returns:

Rule object that excludes the package, or None if the package was not excluded.

Return type:

Optional[Rule]

add_exclusion(rule: Rule) None

Add an exclusion rule.

Parameters:

rule (Rule) – Rule to exclude on.

add_inclusion(rule: Rule) None

Add an inclusion rule.

Parameters:

rule (Rule) – Rule to include on.

classmethod from_pod(data: Any) Self

Convert from POD types to equivalent package filter.

to_pod() Any

Convert to POD type, suitable for storing in an rxt file.

Return type depends on subclass implementation

dict[str, list[str]]:

iter_packages(name: str, range_: VersionRange | str | None = None, paths: list[str] | None = None) Iterator[Package]

Same as iter_packages(), but also applies this filter.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • range (VersionRange or str) – If provided, limits the versions returned to those in range_.

  • paths (Optional[list[str]]) – paths to search for packages, defaults to packages_path.

Returns:

iterator

Return type:

Iterator[Package]

property sha1: str

SHA1 representation

Return type:

str

class rez.package_filter.PackageFilter

Bases: PackageFilterBase

A package filter is a set of rules that hides some packages but leaves others visible. For example, a package filter might be used to hide all packages whos version ends in the string .beta. A package filter might also be used simply to act as a blacklist, hiding some specific packages that are known to be problematic.

Rules can be added as ‘exclusion’ or ‘inclusion’ rules. A package is only excluded if it matches one or more exclusion rules, and does not match any inclusion rules.

__init__() None
excludes(package: Package) Rule | None

Determine if the filter excludes the given package.

Parameters:

package (Package) – Package to filter.

Returns:

Rule object that excludes the package, or None if the package was not excluded.

Return type:

Optional[Rule]

add_exclusion(rule: Rule) None

Add an exclusion rule.

Parameters:

rule (Rule) – Rule to exclude on.

add_inclusion(rule: Rule) None

Add an inclusion rule.

Parameters:

rule (Rule) – Rule to include on.

copy() PackageFilter

Return a shallow copy of the filter.

Adding rules to the copy will not alter the source.

cost() float

Get the approximate cost of this filter.

Cost is the total cost of the exclusion rules in this filter. The cost of family-specific filters is divided by 10.

Returns:

The approximate cost of the filter.

Return type:

float

classmethod from_pod(data: dict) PackageFilter

Convert from POD types to equivalent package filter.

Return type:

PackageFilter

to_pod() dict[str, list[str]]

Convert to POD type, suitable for storing in an rxt file.

Return type depends on subclass implementation

dict[str, list[str]]:

iter_packages(name: str, range_: VersionRange | str | None = None, paths: list[str] | None = None) Iterator[Package]

Same as iter_packages(), but also applies this filter.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • range (VersionRange or str) – If provided, limits the versions returned to those in range_.

  • paths (Optional[list[str]]) – paths to search for packages, defaults to packages_path.

Returns:

iterator

Return type:

Iterator[Package]

property sha1: str

SHA1 representation

Return type:

str

class rez.package_filter.PackageFilterList

Bases: PackageFilterBase

A list of package filters.

A package is excluded by a filter list iff any filter within the list excludes it.

__init__() None
filters: list[PackageFilter]
add_filter(package_filter: PackageFilter) None

Add a filter to the list.

Parameters:

package_filter (PackageFilter) – Filter to add.

add_exclusion(rule: Rule) None

Add an exclusion rule.

Parameters:

rule (Rule) – Rule to exclude on.

add_inclusion(rule: Rule) None

See also: PackageFilterBase.add_inclusion()

Note

Adding an inclusion to a filter list applies that inclusion across all filters.

excludes(package: Package) Rule | None

Returns the first rule that excludes package, if any.

Return type:

Rule

copy() PackageFilterList

Return a copy of the filter list.

Adding rules to the copy will not alter the source.

classmethod from_pod(data: list[dict]) PackageFilterList

Convert from POD types to equivalent package filter.

Return type:

PackageFilterList

to_pod() list[dict]

Convert to POD type, suitable for storing in an rxt file.

Return type depends on subclass implementation

dict[str, list[str]]:

singleton = PackageFilterList(())
iter_packages(name: str, range_: VersionRange | str | None = None, paths: list[str] | None = None) Iterator[Package]

Same as iter_packages(), but also applies this filter.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • range (VersionRange or str) – If provided, limits the versions returned to those in range_.

  • paths (Optional[list[str]]) – paths to search for packages, defaults to packages_path.

Returns:

iterator

Return type:

Iterator[Package]

property sha1: str

SHA1 representation

Return type:

str

rez.package_filter.no_filter = PackageFilterList(())

filter that does not exclude any packages

class rez.package_filter.Rule

Bases: object

Base package filter rule

name = None

Rule name

match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

cost() int

Relative cost of filter. Cheaper filters are applied first.

classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
class rez.package_filter.RegexRuleBase

Bases: Rule

regex: Pattern[str]
txt: str
match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

cost() int

Relative cost of filter. Cheaper filters are applied first.

family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
name = None

Rule name

classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule

class rez.package_filter.RegexRule

Bases: RegexRuleBase

A rule that matches a package if its qualified name matches a regex string.

For example, the package foo-1.beta would match the regex rule .*\.beta$.

name = 'regex'

Rule name

__init__(s: str) None

Create a regex rule.

Parameters:

s (str) – Regex pattern. Eg .*\.beta$.

txt: str
regex: Pattern[str]
cost() int

Relative cost of filter. Cheaper filters are applied first.

family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule

class rez.package_filter.GlobRule

Bases: RegexRuleBase

A rule that matches a package if its qualified name matches a glob string.

For example, the package foo-1.2 would match the glob rule foo-*.

name = 'glob'

Rule name

__init__(s: str) None

Create a glob rule.

Parameters:

s (str) – Glob pattern. Eg foo.*, *.beta.

txt: str
regex: Pattern[str]
cost() int

Relative cost of filter. Cheaper filters are applied first.

family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule

class rez.package_filter.RangeRule

Bases: Rule

A rule that matches a package if that package does not conflict with a given requirement.

For example, the package foo-1.2 would match the requirement rule foo<10.

name = 'range'

Rule name

__init__(requirement: Requirement) None
match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

cost() int

Relative cost of filter. Cheaper filters are applied first.

family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule

class rez.package_filter.TimestampRule

Bases: Rule

A rule that matches a package if that package was released before the given timestamp.

Note

The timestamp argument used for resolves is ANDed with any package filters. Providing a filter containing timestamp rules does not override the value of timestamp.

Warning

Do NOT use a timestamp rule to mimic what the timestamp resolve argument does. timestamp is treated differently - the memcache caching system is aware of it, so timestamped resolves get cached. Non-timestamped resolves also get cached, but their cache entries are invalidated more often (when new packages are released).

There is still a legitimate case to use a global timestamp rule though. You might want to ignore all packages released after time X, except for some specific packages that you want to let through. To do this you would create a package filter containing a timestamp rule with family=None, and other family-specific timestamp rules to override that.

name = 'timestamp'

Rule name

__init__(timestamp: int, family: str | None = None, reverse: bool = False, match_untimestamped: bool = False) None

Create a timestamp rule.

Parameters:
  • timestamp (int) – Epoch time.

  • family (str) – Package family to apply the rule to.

  • reverse (bool) – If True, reverse the logic so that packages released after the timestamp are matched.

  • match_untimestamped (bool) – Defines behaviour on non-timestamped packages.

match(package: Package) bool

Apply the rule to the package.

Parameters:

package (Package) – Package to filter.

Returns:

True if the package matches the filter, False otherwise.

Return type:

bool

cost() int

Relative cost of filter. Cheaper filters are applied first.

classmethod after(timestamp: int, family: str | None = None) Self
classmethod before(timestamp: int, family: str | None = None) Self
family() str | None

Returns a package family string if this rule only applies to a given package family, otherwise None.

Return type:

str | None

family_re: ClassVar[Pattern[str]] = re.compile('[^*?]+[-@#]')
label_re: ClassVar[Pattern[str]] = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
classmethod parse_rule(txt: str) Rule

Parse a rule from a string.

See package_filter for an overview of valid strings.

Parameters:

txt (str) – String to parse.

Return type:

Rule