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

Implement #127 and #96 #129

Merged
merged 28 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4804851
model refactored and imp #127, #96
davidlatwe Nov 11, 2020
a6db0f4
block/unblock app selecting on version picking
davidlatwe Nov 11, 2020
0e4b652
cosmetic
davidlatwe Nov 11, 2020
0a85955
add todo notes
davidlatwe Nov 11, 2020
eab9aca
Fix iter NoneType
davidlatwe Nov 11, 2020
b422611
reduce package finding call
davidlatwe Nov 12, 2020
626cdf8
implement showAllVersions
davidlatwe Nov 12, 2020
24d40fe
distinguish version changeable package
davidlatwe Nov 12, 2020
3d2e5c4
implement preference protection
davidlatwe Nov 12, 2020
bb23c22
block context graphing only on package missing
davidlatwe Nov 12, 2020
cac27ba
revert model merge
davidlatwe Nov 13, 2020
81d3ff7
fix bad revert
davidlatwe Nov 13, 2020
7b810dd
fix package versions picking condition
davidlatwe Nov 13, 2020
b0f3224
add tests
davidlatwe Nov 13, 2020
feed9c3
ensure widgets can be garbage collected
davidlatwe Nov 14, 2020
912918e
add back time wait
davidlatwe Nov 14, 2020
b2af224
no need to reset on showAllVersions
davidlatwe Nov 14, 2020
cff65cf
store startup app on version change
davidlatwe Nov 14, 2020
2437eab
add app version changing test
davidlatwe Nov 14, 2020
d6f1fa1
delete qobject on test teardown
davidlatwe Nov 14, 2020
84e7d58
devop ubuntu pip install pyside2
davidlatwe Nov 14, 2020
eb39f5d
avoid saving non-app package as startup
davidlatwe Nov 14, 2020
1b085ee
polish a bit
davidlatwe Nov 14, 2020
3641606
add back app version range in Packages
davidlatwe Nov 15, 2020
983f4fa
fix startup app updating on patch
davidlatwe Nov 15, 2020
7186dc0
fix startup app updating on default
davidlatwe Nov 15, 2020
7f31314
only update app_request on success resolve
davidlatwe Nov 15, 2020
b078215
add test
davidlatwe Nov 15, 2020
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
23 changes: 23 additions & 0 deletions allzpark/allzparkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ def metadata_from_package(variant):
})


def protected_preferences():
"""Protect preference settings

Prevent clueless one from touching danger settings.

Following is a list of preference names that you may lock:
* showAllApps (bool)
* showHiddenApps (bool)
* showAllVersions (bool)
* patchWithFilter (bool)
* clearCacheTimeout (int)
* exclusionFilter (str)

This should return a preference name and default value paired
dict. For example: {"showAllVersions": False}

Returns:
dict

"""
return dict()


def themes():
"""Allzpark GUI theme list provider

Expand Down
96 changes: 86 additions & 10 deletions allzpark/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Controller(QtCore.QObject):
_State("resolving", help="Rez is busy resolving a context"),
_State("loading", help="Something is taking a moment"),
_State("errored", help="Something has gone wrong"),
_State("console", help="Something need you to read"),
_State("launching", help="An application is launching"),
_State("ready", help="Awaiting user input"),
_State("noprofiles", help="Allzpark did not find any profiles at all"),
Expand Down Expand Up @@ -232,7 +233,7 @@ def __init__(self,

# Docks
"profiles": model.ProfileModel(),
"packages": model.PackagesModel(self),
"packages": model.PackagesModel(),
"context": model.ContextModel(),
"environment": model.EnvironmentModel(),
"parentenv": model.EnvironmentModel(),
Expand Down Expand Up @@ -355,7 +356,40 @@ def environ(self, app_request):
return environ

def resolved_packages(self, app_request):
return self._state["rezContexts"][app_request].resolved_packages
"""Return context resolved packages and versions

If preference 'showAllVersions' is enabled, all packages' versions
will be collected, except profile. Profile version should not be
changed from Packages view, should be changed from Profile view.

"""
all_vers = self._state.retrieve("showAllVersions", False)
app_vers = self._models["apps"].find(app_request)["versions"]
app_names = {app.name for app in self._state["rezApps"].values()}
profile_name = self._state["profileName"]
resolved = self._state["rezContexts"][app_request].resolved_packages

packages = odict() # keep resolved order
for pkg in resolved or []:
is_profile = pkg.name == profile_name
is_app = False if is_profile else pkg.name in app_names

if is_profile:
versions = [str(pkg.version)]
elif is_app:
versions = app_vers[:]
else:
versions = [
str(p.version)
for p in (self.find(pkg.name) if all_vers else [pkg])
]

packages[pkg.name] = {
"package": pkg,
"versions": versions,
}

return packages

# ----------------
# Events
Expand Down Expand Up @@ -924,6 +958,7 @@ def on_apps_not_found(error, trace):
active_profile = profile_versions[version_name]

if profile_name:
# (TODO): this warning pops-up even profile actually exists
self.warning("%s was not found" % profile_name)
else:
self.error("select_profile was passed an empty string")
Expand Down Expand Up @@ -1088,14 +1123,26 @@ def _list_apps(self, profile):
patch_with_filter = self._state.retrieve("patchWithFilter", False)
package_filter = self._package_filter()

app_ranges = dict()

def _try_finding_latest_app(req_str):
req_str = req_str.strip("~")
req = rez.PackageRequest(req_str)
try:
return rez.find_latest(req.name, range_=req.range)
app_vers = list(self.find(req.name, range_=req.range))
latest = app_vers[-1]
except IndexError:
self.error("No package matched for request '%s', may have"
"been excluded by package filter.")
latest = model.BrokenPackage(req_str)
app_vers = [latest]
except _missing as e_:
self.error(str(e_))
return model.BrokenPackage(req_str)
latest = model.BrokenPackage(req_str)
app_vers = [latest]

app_ranges[req.name] = app_vers
return latest

def _try_resolve_context(req, pkg_name, mode):
kwargs = dict()
Expand All @@ -1112,6 +1159,9 @@ def _try_resolve_context(req, pkg_name, mode):
contexts = odict()
with util.timing() as t:

current_app = self._state["appRequest"] or ""
current_app = current_app.split("==", 1)[0]

for app_request in apps:

app_package = _try_finding_latest_app(app_request)
Expand All @@ -1134,6 +1184,19 @@ def _try_resolve_context(req, pkg_name, mode):
app_package.name,
mode="Patch")

# To avoid application selection change on patched or
# set back to default:
# 1. update context key `app_request`, and
# 2. update startup app
if context.success:
for pkg in context.resolved_packages or []:
if pkg.name == app_package.name:
app_request = "%s==%s" % (pkg.name, pkg.version)
if pkg.name == current_app:
self._state.store("startupApplication",
app_request)
break

contexts[app_request] = context

# Associate a Rez package with an app
Expand Down Expand Up @@ -1181,25 +1244,38 @@ def _try_resolve_context(req, pkg_name, mode):

self._state["rezApps"][app_request] = rez_pkg

self._state["rezContexts"] = contexts

self.debug("Resolved all contexts in %.2f seconds" % t.duration)

# Hide hidden
visible_apps = []
visible_apps = dict()

# * Opt-out hidden application
# * Find application versions
show_hidden = self._state.retrieve("showHiddenApps")
for request, package in self._state["rezApps"].items():
data = allzparkconfig.metadata_from_package(package)
for request, app_pkg in self._state["rezApps"].items():
data = allzparkconfig.metadata_from_package(app_pkg)
hidden = data.get("hidden", False)

if hidden and not show_hidden:
continue

visible_apps += [package]
app_versions = [str(v.version) for v in app_ranges[app_pkg.name]]
visible_apps[request] = {
"package": app_pkg,
"versions": app_versions,
}

self._state["rezContexts"] = contexts
return visible_apps

def graph(self):
context = self._state["rezContexts"][self._state["appRequest"]]
if isinstance(context, model.BrokenContext):
self._state.to_console()
self._state.to_ready()
self.error("Can not graph a broken context.")
return

graph_str = context.graph(as_dot=True)

tempdir = tempfile.mkdtemp()
Expand Down
25 changes: 23 additions & 2 deletions allzpark/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,50 @@


class Package(QtWidgets.QStyledItemDelegate):

editor_created = QtCore.Signal()
editor_closed = QtCore.Signal(bool)

def __init__(self, ctrl, parent=None):
super(Package, self).__init__(parent)

def on_close_editor(*args):
self.editor_closed.emit(self._changed)
self.closeEditor.connect(on_close_editor)

self._changed = None
self._default = None
self._ctrl = ctrl

def createEditor(self, parent, option, index):
if index.column() != 1:
model = index.model()
if index.column() != 1 or not model.data(index, "_hasVersions"):
return

editor = QtWidgets.QComboBox(parent)

def on_text_activated(text):
self._changed = text != self._default
editor.textActivated.connect(on_text_activated)

return editor

def setEditorData(self, editor, index):
model = index.model()
options = model.data(index, "versions")
default = index.data(QtCore.Qt.DisplayRole)

self._changed = False
self._default = default

editor.addItems(options)
editor.setCurrentIndex(options.index(default))

self.editor_created.emit()

def setModelData(self, editor, model, index):
model = index.model()
package = model.data(index, "name")
package = model.data(index, "family")
options = model.data(index, "versions")
default = model.data(index, "default")
version = options[editor.currentIndex()]
Expand Down
Loading