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

Fixes #131 #132

Merged
merged 12 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions allzpark/_rezapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,45 @@ def clear_caches():
repo.clear_caches()


def find_one(name, range_=None, paths=None):
return next(find(name, range_, paths))
def find_one(name, range_=None, paths=None, package_filter=None):
"""
Find next package version

Args:
name (str): Name of the rez package
range_ (VersionRange or str, optional): Limits versions to range
paths (list of str, optional): Paths to search for packages
package_filter (PackageFilter, optional): Limits versions to those
that match package filter

Returns:
rez.packages_.Package
"""
if package_filter:
return next(package_filter.iter_packages(name, range_, paths))
else:
return next(find(name, range_, paths))


def find_latest(name, range_=None, paths=None, package_filter=None):
"""
Find latest package version

Args:
name (str): Name of the rez package
range_ (VersionRange or str, optional): Limits versions to range
paths (list of str, optional): Paths to search for packages
package_filter (PackageFilter, optional): Limits versions to those
that match package filter

Returns:
rez.packages_.Package
"""
if package_filter:
it = package_filter.iter_packages(name, range_, paths)
else:
it = find(name, range_, paths)


def find_latest(name, range_=None, paths=None):
it = find(name, range_)
it = sorted(it, key=lambda pkg: pkg.version)

try:
Expand Down
3 changes: 0 additions & 3 deletions allzpark/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,6 @@ def _list_apps(self, profile):
# Optional patch
patch = self._state.retrieve("patch", "").split()
patch_with_filter = self._state.retrieve("patchWithFilter", False)
package_filter = self._package_filter()

app_ranges = dict()

Expand Down Expand Up @@ -1165,8 +1164,6 @@ def _try_resolve_context(req, pkg_name, mode):
for app_request in apps:

app_package = _try_finding_latest_app(app_request)
if package_filter.excludes(app_package):
continue
Comment on lines -1168 to -1169
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving notes:

While I was resolving merge conflict, I found #129 actually also accidentally fixed the issue that this PR is aiming to. In #129, instead of using _rez_api.find_latest, it has changed to use contorller's find method which already filtering packages with filter.

Still, removing this line here is good, it's redundant anyway.


app_request = "%s==%s" % (app_package.name,
app_package.version)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,42 @@ def get_version_editor(app_request):
editor, delegate = get_version_editor("app_A==2")
self.assertIsNone(
editor, "No version editing if versions are flattened.")

def test_app_exclusion_filter(self):
"""Test app is available when latest version excluded by filter"""
util.memory_repository({
"foo": {
"1.0.0": {
"name": "foo",
"version": "1.0.0",
"requires": [
"~app_A-1"
]
}
},
"app_A": {
"1.0.0": {
"name": "app_A",
"version": "1.0.0"
},
"1.0.0.beta": {
"name": "app_A",
"version": "1.0.0.beta"
# latest app_A version matches exclusion filter
}
}
})
self.ctrl_reset(["foo"])

self.set_preference("exclusionFilter", "*.beta")
self.wait(200) # wait for reset

# App was added
self.assertIn("app_A==1.0.0", self.ctrl.state["rezContexts"])
context_a = self.ctrl.state["rezContexts"]["app_A==1.0.0"]
self.assertTrue(context_a.success)

# Latest non-beta version was chosen
resolved_pkgs = [p for p in context_a.resolved_packages
if "app_A" == p.name and "1.0.0" == str(p.version)]
self.assertEqual(1, len(resolved_pkgs))