rez.package_filter

class rez.package_filter.GlobRule(s)[source]

Bases: rez.package_filter.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'

Relative cost of rule - cheaper rules are checked first.

class rez.package_filter.PackageFilter[source]

Bases: rez.package_filter.PackageFilterBase

A package filter.

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 iff it matches one or more exclusion rules, and does not match any inclusion rules.

add_exclusion(rule)[source]

Add an exclusion rule.

Parameters

rule (Rule) – Rule to exclude on.

add_inclusion(rule)[source]

Add an inclusion rule.

Parameters

rule (Rule) – Rule to include on.

copy()[source]

Return a shallow copy of the filter.

Adding rules to the copy will not alter the source.

cost

Simple property caching descriptor.

Example

>>> class Foo(object):
>>>     @cached_property
>>>     def bah(self):
>>>         print('bah')
>>>         return 1
>>>
>>> f = Foo()
>>> f.bah
bah
1
>>> f.bah
1
excludes(package)[source]

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.

classmethod from_pod(data)[source]

Convert from POD types to equivalent package filter.

to_pod()[source]

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

class rez.package_filter.PackageFilterBase[source]

Bases: object

add_exclusion(rule)[source]

Add an exclusion rule.

Parameters

rule (Rule) – Rule to exclude on.

add_inclusion(rule)[source]

Add an inclusion rule.

Parameters

rule (Rule) – Rule to include on.

excludes(package)[source]

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.

classmethod from_pod(data)[source]

Convert from POD types to equivalent package filter.

iter_packages(name, range_=None, paths=None)[source]

Same as iter_packages in packages.py, 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 (list of str, optional) – paths to search for packages, defaults to config.packages_path.

Returns

Package iterator.

property sha1
to_pod()[source]

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

class rez.package_filter.PackageFilterList[source]

Bases: rez.package_filter.PackageFilterBase

A list of package filters.

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

add_exclusion(rule)[source]

Add an exclusion rule.

Parameters

rule (Rule) – Rule to exclude on.

add_filter(package_filter)[source]

Add a filter to the list.

Parameters

package_filter (PackageFilter) – Filter to add.

add_inclusion(rule)[source]

Note

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

copy()[source]

Return a copy of the filter list.

Adding rules to the copy will not alter the source.

excludes(package)[source]

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.

classmethod from_pod(data)[source]

Convert from POD types to equivalent package filter.

singleton = PackageFilterList(())[source]
to_pod()[source]

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

class rez.package_filter.RangeRule(requirement)[source]

Bases: rez.package_filter.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’.

cost()[source]

Relative cost of filter. Cheaper filters are applied first.

match(package)[source]

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

name = 'range'

Relative cost of rule - cheaper rules are checked first.

class rez.package_filter.RegexRule(s)[source]

Bases: rez.package_filter.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'

Relative cost of rule - cheaper rules are checked first.

class rez.package_filter.RegexRuleBase[source]

Bases: rez.package_filter.Rule

cost()[source]

Relative cost of filter. Cheaper filters are applied first.

match(package)[source]

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

class rez.package_filter.Rule[source]

Bases: object

cost()[source]

Relative cost of filter. Cheaper filters are applied first.

family()[source]

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

family_re = re.compile('[^*?]+[-@#]')
label_re = re.compile('^([^(]+)\\(([^\\(\\)]+)\\)$')
match(package)[source]

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

name = None

Relative cost of rule - cheaper rules are checked first.

classmethod parse_rule(txt)[source]

Parse a rule from a string.

See rezconfig.package_filter for an overview of valid strings.

Parameters

txt (str) – String to parse.

Returns

Rule instance.

class rez.package_filter.TimestampRule(timestamp, family=None, reverse=False, match_untimestamped=False)[source]

Bases: rez.package_filter.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’.

Note

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.

classmethod after(timestamp, family=None)[source]
classmethod before(timestamp, family=None)[source]
cost()[source]

Relative cost of filter. Cheaper filters are applied first.

match(package)[source]

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

name = 'timestamp'

Relative cost of rule - cheaper rules are checked first.