{"action":"created","comment":{"url":"https://api.github.com/repos/getavalon/core/pulls/comments/150751718","pull_request_review_id":76346428,"id":150751718,"diff_hunk":"@@ -720,6 +720,84 @@ def get_representation_context(representation):\n     return context\n \n \n+def update_current_context(context):\n+    \"\"\"Update active Session to new context.\n+\n+    The context can hold `asset`, `task` and `app`, other keys are ignored.\n+\n+    Args:\n+        context (dict): The context to apply.\n+\n+    Returns:\n+        dict: The changed key, values in the current Session.\n+\n+    \"\"\"\n+\n+    mapping = {\n+        \"AVALON_ASSET\": context.get(\"asset\", None),\n+        \"AVALON_TASK\": context.get(\"task\", None),\n+        \"AVALON_APP\": context.get(\"app\", None),\n+    }\n+    changed = {key: value for key, value in mapping.items() if\n+               value and Session[key] != value}\n+    if not changed:\n+        return\n+\n+    # Update silo when asset changed\n+    if \"AVALON_ASSET\" in changed:\n+        asset_document = io.find_one({\"name\": changed['AVALON_ASSET'],\n+                                      \"type\": \"asset\"},\n+                                     projection={\"silo\": True})\n+        assert asset_document, \"Asset must exist\"\n+        changed[\"AVALON_SILO\"] = asset_document['silo']\n+\n+    # Compute work directory (with the temporary changed session so far)\n+    project = io.find_one({\"type\": \"project\"},\n+                          projection={\"config.template.work\": True})\n+    template = project['config']['template']['work']\n+    _session = Session.copy()\n+    _session.update(changed)\n+    changed['AVALON_WORKDIR'] = format_template(template, _session)\n+\n+    # Update the full session in one go to avoid half updates\n+    Session.update(changed)\n+\n+    # Emit session change\n+    emit(\"currentContextUpdated\", changed.copy())","path":"avalon/pipeline.py","position":55,"original_position":47,"commit_id":"9ced452390b311f66d64cf14c1d6233e527c2632","original_commit_id":"1182c06a0d7c483aeddb35ee60e7e037646ea872","user":{"login":"mottosso","id":2152766,"avatar_url":"https://avatars1.githubusercontent.com/u/2152766?v=4","gravatar_id":"","url":"https://api.github.com/users/mottosso","html_url":"https://github.com/mottosso","followers_url":"https://api.github.com/users/mottosso/followers","following_url":"https://api.github.com/users/mottosso/following{/other_user}","gists_url":"https://api.github.com/users/mottosso/gists{/gist_id}","starred_url":"https://api.github.com/users/mottosso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mottosso/subscriptions","organizations_url":"https://api.github.com/users/mottosso/orgs","repos_url":"https://api.github.com/users/mottosso/repos","events_url":"https://api.github.com/users/mottosso/events{/privacy}","received_events_url":"https://api.github.com/users/mottosso/received_events","type":"User","site_admin":false},"body":"That's a good idea.\r\n\r\nBut first, there's one thing that's miscommunicated I think. `context` is a dictionary with a fixed membership, like specified in its schema. It should be passed whole to the function, and returned whole. No partials.\r\n\r\n```python\r\ndef Context():\r\n\treturn {\r\n\t    \"project\": api.Session[\"AVALON_PROJECT\"],\r\n\t    \"asset\": api.Session[\"AVALON_ASSET\"],\r\n\t    \"silo\": api.Session[\"AVALON_SILO\"],\r\n\t    \"subset\": api.Session[\"AVALON_SUBSET\"],\r\n\t    \"version\": api.Session[\"AVALON_VERSION\"],\r\n\t    \"representation\": api.Session[\"AVALON_REPRESENTATION\"]\"\r\n\t}\r\n\r\ncontext = Context()\r\ncontext[\"project\"] = \"hulk\"\r\ncontext[\"asset\"] = \"Bruce\"\r\napi.update_current_context(context)\r\n```\r\n\r\nHowever now that I type that out, I realise not all members are in Session, and not all members can or should be changed this way, like Version and Representation..\r\n\r\nThat's a flaw in this design; we can't call it Context if it isn't going to be a Context else we'd confuse it with the use of Context elsewhere.. I'm not sure how to deal with this one.\r\n\r\nMy problem with passing `project=` and `asset=` directly is that it's not discoverable enough. Which members should be part of this function? Subset too? Silo? There's no way to tell without reading the docs or by trail and error. The thing about Context is that it's known and used in more than one place. It's worth learning about and doesn't come with surprises.\r\n\r\nAny ideas?","created_at":"2017-11-14T07:09:08Z","updated_at":"2017-11-14T07:09:08Z","html_url":"https://github.com/getavalon/core/pull/300#discussion_r150751718","pull_request_url":"https://api.github.com/repos/getavalon/core/pulls/300","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/getavalon/core/pulls/comments/150751718"},"html":{"href":"https://github.com/getavalon/core/pull/300#discussion_r150751718"},"pull_request":{"href":"https://api.github.com/repos/getavalon/core/pulls/300"}},"in_reply_to_id":150602062},"pull_request":{"url":"https://api.github.com/repos/getavalon/core/pulls/300","id":152062452,"html_url":"https://github.com/getavalon/core/pull/300","diff_url":"https://github.com/getavalon/core/pull/300.diff","patch_url":"https://github.com/getavalon/core/pull/300.patch","issue_url":"https://api.github.com/repos/getavalon/core/issues/300","number":300,"state":"open","locked":false,"title":"Use Session instead of `os.environ`","user":{"login":"BigRoy","id":2439881,"avatar_url":"https://avatars0.githubusercontent.com/u/2439881?v=4","gravatar_id":"","url":"https://api.github.com/users/BigRoy","html_url":"https://github.com/BigRoy","followers_url":"https://api.github.com/users/BigRoy/followers","following_url":"https://api.github.com/users/BigRoy/following{/other_user}","gists_url":"https://api.github.com/users/BigRoy/gists{/gist_id}","starred_url":"https://api.github.com/users/BigRoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BigRoy/subscriptions","organizations_url":"https://api.github.com/users/BigRoy/orgs","repos_url":"https://api.github.com/users/BigRoy/repos","events_url":"https://api.github.com/users/BigRoy/events{/privacy}","received_events_url":"https://api.github.com/users/BigRoy/received_events","type":"User","site_admin":false},"body":"I've started work on refactoring all tools and code to rely more on the Session and avoid falling back to `os.environ`.\r\n\r\nThis way we can start introducing \"live context switching\" by changing the active session.\r\n\r\n- Refactored `os.environ` calls to `api.Session`\r\n- Removed `AVALON_WORKDIR` in favor of `api.get_work_directory` so it's easier to remain in sync with the current session. This could be added back in but seems like a (possibly redundant?) optimization\r\n\r\nI want to discuss what else will be needed to make it manageable to easily switch a context.","created_at":"2017-11-11T15:53:47Z","updated_at":"2017-11-14T07:09:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cb0c62ce87d268d5db6497c763b3ae6dc12dd820","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/getavalon/core/pulls/300/commits","review_comments_url":"https://api.github.com/repos/getavalon/core/pulls/300/comments","review_comment_url":"https://api.github.com/repos/getavalon/core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getavalon/core/issues/300/comments","statuses_url":"https://api.github.com/repos/getavalon/core/statuses/9ced452390b311f66d64cf14c1d6233e527c2632","head":{"label":"Colorbleed:use_session","ref":"use_session","sha":"9ced452390b311f66d64cf14c1d6233e527c2632","user":{"login":"Colorbleed","id":26379769,"avatar_url":"https://avatars3.githubusercontent.com/u/26379769?v=4","gravatar_id":"","url":"https://api.github.com/users/Colorbleed","html_url":"https://github.com/Colorbleed","followers_url":"https://api.github.com/users/Colorbleed/followers","following_url":"https://api.github.com/users/Colorbleed/following{/other_user}","gists_url":"https://api.github.com/users/Colorbleed/gists{/gist_id}","starred_url":"https://api.github.com/users/Colorbleed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colorbleed/subscriptions","organizations_url":"https://api.github.com/users/Colorbleed/orgs","repos_url":"https://api.github.com/users/Colorbleed/repos","events_url":"https://api.github.com/users/Colorbleed/events{/privacy}","received_events_url":"https://api.github.com/users/Colorbleed/received_events","type":"Organization","site_admin":false},"repo":{"id":93861791,"name":"core","full_name":"Colorbleed/core","owner":{"login":"Colorbleed","id":26379769,"avatar_url":"https://avatars3.githubusercontent.com/u/26379769?v=4","gravatar_id":"","url":"https://api.github.com/users/Colorbleed","html_url":"https://github.com/Colorbleed","followers_url":"https://api.github.com/users/Colorbleed/followers","following_url":"https://api.github.com/users/Colorbleed/following{/other_user}","gists_url":"https://api.github.com/users/Colorbleed/gists{/gist_id}","starred_url":"https://api.github.com/users/Colorbleed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colorbleed/subscriptions","organizations_url":"https://api.github.com/users/Colorbleed/orgs","repos_url":"https://api.github.com/users/Colorbleed/repos","events_url":"https://api.github.com/users/Colorbleed/events{/privacy}","received_events_url":"https://api.github.com/users/Colorbleed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Colorbleed/core","description":"The safe post-production pipeline","fork":true,"url":"https://api.github.com/repos/Colorbleed/core","forks_url":"https://api.github.com/repos/Colorbleed/core/forks","keys_url":"https://api.github.com/repos/Colorbleed/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Colorbleed/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Colorbleed/core/teams","hooks_url":"https://api.github.com/repos/Colorbleed/core/hooks","issue_events_url":"https://api.github.com/repos/Colorbleed/core/issues/events{/number}","events_url":"https://api.github.com/repos/Colorbleed/core/events","assignees_url":"https://api.github.com/repos/Colorbleed/core/assignees{/user}","branches_url":"https://api.github.com/repos/Colorbleed/core/branches{/branch}","tags_url":"https://api.github.com/repos/Colorbleed/core/tags","blobs_url":"https://api.github.com/repos/Colorbleed/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Colorbleed/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Colorbleed/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/Colorbleed/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Colorbleed/core/statuses/{sha}","languages_url":"https://api.github.com/repos/Colorbleed/core/languages","stargazers_url":"https://api.github.com/repos/Colorbleed/core/stargazers","contributors_url":"https://api.github.com/repos/Colorbleed/core/contributors","subscribers_url":"https://api.github.com/repos/Colorbleed/core/subscribers","subscription_url":"https://api.github.com/repos/Colorbleed/core/subscription","commits_url":"https://api.github.com/repos/Colorbleed/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/Colorbleed/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/Colorbleed/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/Colorbleed/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/Colorbleed/core/contents/{+path}","compare_url":"https://api.github.com/repos/Colorbleed/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Colorbleed/core/merges","archive_url":"https://api.github.com/repos/Colorbleed/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Colorbleed/core/downloads","issues_url":"https://api.github.com/repos/Colorbleed/core/issues{/number}","pulls_url":"https://api.github.com/repos/Colorbleed/core/pulls{/number}","milestones_url":"https://api.github.com/repos/Colorbleed/core/milestones{/number}","notifications_url":"https://api.github.com/repos/Colorbleed/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Colorbleed/core/labels{/name}","releases_url":"https://api.github.com/repos/Colorbleed/core/releases{/id}","deployments_url":"https://api.github.com/repos/Colorbleed/core/deployments","created_at":"2017-06-09T13:32:10Z","updated_at":"2017-06-23T12:03:54Z","pushed_at":"2017-11-13T20:25:04Z","git_url":"git://github.com/Colorbleed/core.git","ssh_url":"git@github.com:Colorbleed/core.git","clone_url":"https://github.com/Colorbleed/core.git","svn_url":"https://github.com/Colorbleed/core","homepage":"https://getavalon.github.io","size":3129,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"getavalon:master","ref":"master","sha":"357b26e249d9cfb3f0f7d13bedc9062b3c0e856c","user":{"login":"getavalon","id":29395942,"avatar_url":"https://avatars3.githubusercontent.com/u/29395942?v=4","gravatar_id":"","url":"https://api.github.com/users/getavalon","html_url":"https://github.com/getavalon","followers_url":"https://api.github.com/users/getavalon/followers","following_url":"https://api.github.com/users/getavalon/following{/other_user}","gists_url":"https://api.github.com/users/getavalon/gists{/gist_id}","starred_url":"https://api.github.com/users/getavalon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getavalon/subscriptions","organizations_url":"https://api.github.com/users/getavalon/orgs","repos_url":"https://api.github.com/users/getavalon/repos","events_url":"https://api.github.com/users/getavalon/events{/privacy}","received_events_url":"https://api.github.com/users/getavalon/received_events","type":"Organization","site_admin":false},"repo":{"id":79323064,"name":"core","full_name":"getavalon/core","owner":{"login":"getavalon","id":29395942,"avatar_url":"https://avatars3.githubusercontent.com/u/29395942?v=4","gravatar_id":"","url":"https://api.github.com/users/getavalon","html_url":"https://github.com/getavalon","followers_url":"https://api.github.com/users/getavalon/followers","following_url":"https://api.github.com/users/getavalon/following{/other_user}","gists_url":"https://api.github.com/users/getavalon/gists{/gist_id}","starred_url":"https://api.github.com/users/getavalon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getavalon/subscriptions","organizations_url":"https://api.github.com/users/getavalon/orgs","repos_url":"https://api.github.com/users/getavalon/repos","events_url":"https://api.github.com/users/getavalon/events{/privacy}","received_events_url":"https://api.github.com/users/getavalon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getavalon/core","description":"The safe post-production pipeline - https://getavalon.github.io/2.0","fork":false,"url":"https://api.github.com/repos/getavalon/core","forks_url":"https://api.github.com/repos/getavalon/core/forks","keys_url":"https://api.github.com/repos/getavalon/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getavalon/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getavalon/core/teams","hooks_url":"https://api.github.com/repos/getavalon/core/hooks","issue_events_url":"https://api.github.com/repos/getavalon/core/issues/events{/number}","events_url":"https://api.github.com/repos/getavalon/core/events","assignees_url":"https://api.github.com/repos/getavalon/core/assignees{/user}","branches_url":"https://api.github.com/repos/getavalon/core/branches{/branch}","tags_url":"https://api.github.com/repos/getavalon/core/tags","blobs_url":"https://api.github.com/repos/getavalon/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getavalon/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getavalon/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/getavalon/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getavalon/core/statuses/{sha}","languages_url":"https://api.github.com/repos/getavalon/core/languages","stargazers_url":"https://api.github.com/repos/getavalon/core/stargazers","contributors_url":"https://api.github.com/repos/getavalon/core/contributors","subscribers_url":"https://api.github.com/repos/getavalon/core/subscribers","subscription_url":"https://api.github.com/repos/getavalon/core/subscription","commits_url":"https://api.github.com/repos/getavalon/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/getavalon/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/getavalon/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/getavalon/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/getavalon/core/contents/{+path}","compare_url":"https://api.github.com/repos/getavalon/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getavalon/core/merges","archive_url":"https://api.github.com/repos/getavalon/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getavalon/core/downloads","issues_url":"https://api.github.com/repos/getavalon/core/issues{/number}","pulls_url":"https://api.github.com/repos/getavalon/core/pulls{/number}","milestones_url":"https://api.github.com/repos/getavalon/core/milestones{/number}","notifications_url":"https://api.github.com/repos/getavalon/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getavalon/core/labels{/name}","releases_url":"https://api.github.com/repos/getavalon/core/releases{/id}","deployments_url":"https://api.github.com/repos/getavalon/core/deployments","created_at":"2017-01-18T09:14:47Z","updated_at":"2017-11-13T02:56:44Z","pushed_at":"2017-11-13T20:25:05Z","git_url":"git://github.com/getavalon/core.git","ssh_url":"git@github.com:getavalon/core.git","clone_url":"https://github.com/getavalon/core.git","svn_url":"https://github.com/getavalon/core","homepage":"","size":3324,"stargazers_count":34,"watchers_count":34,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":97,"forks":10,"open_issues":97,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getavalon/core/pulls/300"},"html":{"href":"https://github.com/getavalon/core/pull/300"},"issue":{"href":"https://api.github.com/repos/getavalon/core/issues/300"},"comments":{"href":"https://api.github.com/repos/getavalon/core/issues/300/comments"},"review_comments":{"href":"https://api.github.com/repos/getavalon/core/pulls/300/comments"},"review_comment":{"href":"https://api.github.com/repos/getavalon/core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getavalon/core/pulls/300/commits"},"statuses":{"href":"https://api.github.com/repos/getavalon/core/statuses/9ced452390b311f66d64cf14c1d6233e527c2632"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"mottosso"}}