{"action":"created","comment":{"url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/comments/45716417","id":45716417,"diff_hunk":"@@ -664,43 +724,37 @@ def setup_sys_path(self):\n         if os.path.isdir(REPO_SCRIPTS_DIR):\n             sys.path.insert(0, REPO_SCRIPTS_DIR)\n \n-        # insert lib dir\n+        # insert lib dir before newly inserted test/base/scripts\n         sys.path.insert(0, REPO_LIB_DIR)\n \n-        # force __path__ of packages in the repo\n-        packages = files_in_packages()['packages']\n-        for package in packages.keys():\n+        # force __path__ of packages in the repo (to deal with namespace extensions)\n+\n+        packages = FILES_IN_PACKAGES['packages']\n+        # sort them, parents first\n+        pkg_names = sorted(packages.keys())\n+        # cleanup children first\n+        reloaded_modules = []\n+        for package in pkg_names[::-1]:\n+            reloaded_modules.extend(self.reload_modules(package, remove_only=True, own_modules=True))\n+\n+        # insert in order, parents first\n+        for package in pkg_names:\n             try:\n                 __import__(package)\n+                log.debug('Imported package %s' % package)\n             except ImportError as e:\n                 raise ImportError(\"Failed to import package %s from current repository: %s\" % (package, e))\n             sys.modules[package].__path__.insert(0, os.path.dirname(packages[package][0]))\n \n-        return cleanup\n-\n-    def reload_modules(self, package):\n-        \"\"\"\n-        Cleanup and restore package because we use\n-        vsc package tools very early.\n-        So we need to make sure they are picked up from the paths as specified\n-        in setup_sys_path, not to mix with installed and already loaded modules\n-        \"\"\"\n-\n-        def candidate(modulename):\n-            \"\"\"Select candidate modules to reload\"\"\"\n-            return modulename in (package,) or modulename.startswith(package+'.')\n-\n-        loaded_modules = filter(candidate, sys.modules.keys())\n-        reload_modules = []\n-        for name in loaded_modules:\n-            if hasattr(sys.modules[name], '__file__'):\n-                # only actual modules\n-                reload_modules.append(name)\n-            del(sys.modules[name])\n+        # reload the loaded modules with new __path__\n+        for module in reloaded_modules:\n+            try:\n+                __import__(module)\n+                log.debug('Imported module %s' % module)\n+            except ImportError as e:\n+                raise ImportError(\"Failed to reload module %s: %s\" % (module, e))","path":"lib/vsc/install/shared_setup.py","position":202,"original_position":202,"commit_id":"c3147d46dffc7d30010a4cb3c15bbf9b8c22ac58","original_commit_id":"c3147d46dffc7d30010a4cb3c15bbf9b8c22ac58","user":{"login":"ehiggs","id":28823,"avatar_url":"https://avatars.githubusercontent.com/u/28823?v=3","gravatar_id":"","url":"https://api.github.com/users/ehiggs","html_url":"https://github.com/ehiggs","followers_url":"https://api.github.com/users/ehiggs/followers","following_url":"https://api.github.com/users/ehiggs/following{/other_user}","gists_url":"https://api.github.com/users/ehiggs/gists{/gist_id}","starred_url":"https://api.github.com/users/ehiggs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehiggs/subscriptions","organizations_url":"https://api.github.com/users/ehiggs/orgs","repos_url":"https://api.github.com/users/ehiggs/repos","events_url":"https://api.github.com/users/ehiggs/events{/privacy}","received_events_url":"https://api.github.com/users/ehiggs/received_events","type":"User","site_admin":false},"body":"Given how `__import__('does_not_exist')` will raise `ImportError(`No module named %s' e)` do we really need to try, except and reraise with a new message? At this point, I think we can elide the noise and just call import and let the underlying machinery handle the error.","created_at":"2015-11-24T10:09:52Z","updated_at":"2015-11-24T10:09:52Z","html_url":"https://github.com/hpcugent/vsc-install/pull/14#discussion_r45716417","pull_request_url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/comments/45716417"},"html":{"href":"https://github.com/hpcugent/vsc-install/pull/14#discussion_r45716417"},"pull_request":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14","id":51537918,"html_url":"https://github.com/hpcugent/vsc-install/pull/14","diff_url":"https://github.com/hpcugent/vsc-install/pull/14.diff","patch_url":"https://github.com/hpcugent/vsc-install/pull/14.patch","issue_url":"https://api.github.com/repos/hpcugent/vsc-install/issues/14","number":14,"state":"open","locked":false,"title":"Add more python prefix handling options","user":{"login":"stdweird","id":1517606,"avatar_url":"https://avatars.githubusercontent.com/u/1517606?v=3","gravatar_id":"","url":"https://api.github.com/users/stdweird","html_url":"https://github.com/stdweird","followers_url":"https://api.github.com/users/stdweird/followers","following_url":"https://api.github.com/users/stdweird/following{/other_user}","gists_url":"https://api.github.com/users/stdweird/gists{/gist_id}","starred_url":"https://api.github.com/users/stdweird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stdweird/subscriptions","organizations_url":"https://api.github.com/users/stdweird/orgs","repos_url":"https://api.github.com/users/stdweird/repos","events_url":"https://api.github.com/users/stdweird/events{/privacy}","received_events_url":"https://api.github.com/users/stdweird/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-23T15:34:35Z","updated_at":"2015-11-24T10:09:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c4de3fb2f2d3a303f19314a5b46f2ed392206751","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14/commits","review_comments_url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14/comments","review_comment_url":"https://api.github.com/repos/hpcugent/vsc-install/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hpcugent/vsc-install/issues/14/comments","statuses_url":"https://api.github.com/repos/hpcugent/vsc-install/statuses/c3147d46dffc7d30010a4cb3c15bbf9b8c22ac58","head":{"label":"stdweird:rpm_python_renaming","ref":"rpm_python_renaming","sha":"c3147d46dffc7d30010a4cb3c15bbf9b8c22ac58","user":{"login":"stdweird","id":1517606,"avatar_url":"https://avatars.githubusercontent.com/u/1517606?v=3","gravatar_id":"","url":"https://api.github.com/users/stdweird","html_url":"https://github.com/stdweird","followers_url":"https://api.github.com/users/stdweird/followers","following_url":"https://api.github.com/users/stdweird/following{/other_user}","gists_url":"https://api.github.com/users/stdweird/gists{/gist_id}","starred_url":"https://api.github.com/users/stdweird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stdweird/subscriptions","organizations_url":"https://api.github.com/users/stdweird/orgs","repos_url":"https://api.github.com/users/stdweird/repos","events_url":"https://api.github.com/users/stdweird/events{/privacy}","received_events_url":"https://api.github.com/users/stdweird/received_events","type":"User","site_admin":false},"repo":{"id":44304025,"name":"vsc-install","full_name":"stdweird/vsc-install","owner":{"login":"stdweird","id":1517606,"avatar_url":"https://avatars.githubusercontent.com/u/1517606?v=3","gravatar_id":"","url":"https://api.github.com/users/stdweird","html_url":"https://github.com/stdweird","followers_url":"https://api.github.com/users/stdweird/followers","following_url":"https://api.github.com/users/stdweird/following{/other_user}","gists_url":"https://api.github.com/users/stdweird/gists{/gist_id}","starred_url":"https://api.github.com/users/stdweird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stdweird/subscriptions","organizations_url":"https://api.github.com/users/stdweird/orgs","repos_url":"https://api.github.com/users/stdweird/repos","events_url":"https://api.github.com/users/stdweird/events{/privacy}","received_events_url":"https://api.github.com/users/stdweird/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stdweird/vsc-install","description":"Shared setuptools functions and classes for python libraries developed by UGent's HPC group","fork":true,"url":"https://api.github.com/repos/stdweird/vsc-install","forks_url":"https://api.github.com/repos/stdweird/vsc-install/forks","keys_url":"https://api.github.com/repos/stdweird/vsc-install/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stdweird/vsc-install/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stdweird/vsc-install/teams","hooks_url":"https://api.github.com/repos/stdweird/vsc-install/hooks","issue_events_url":"https://api.github.com/repos/stdweird/vsc-install/issues/events{/number}","events_url":"https://api.github.com/repos/stdweird/vsc-install/events","assignees_url":"https://api.github.com/repos/stdweird/vsc-install/assignees{/user}","branches_url":"https://api.github.com/repos/stdweird/vsc-install/branches{/branch}","tags_url":"https://api.github.com/repos/stdweird/vsc-install/tags","blobs_url":"https://api.github.com/repos/stdweird/vsc-install/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stdweird/vsc-install/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stdweird/vsc-install/git/refs{/sha}","trees_url":"https://api.github.com/repos/stdweird/vsc-install/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stdweird/vsc-install/statuses/{sha}","languages_url":"https://api.github.com/repos/stdweird/vsc-install/languages","stargazers_url":"https://api.github.com/repos/stdweird/vsc-install/stargazers","contributors_url":"https://api.github.com/repos/stdweird/vsc-install/contributors","subscribers_url":"https://api.github.com/repos/stdweird/vsc-install/subscribers","subscription_url":"https://api.github.com/repos/stdweird/vsc-install/subscription","commits_url":"https://api.github.com/repos/stdweird/vsc-install/commits{/sha}","git_commits_url":"https://api.github.com/repos/stdweird/vsc-install/git/commits{/sha}","comments_url":"https://api.github.com/repos/stdweird/vsc-install/comments{/number}","issue_comment_url":"https://api.github.com/repos/stdweird/vsc-install/issues/comments{/number}","contents_url":"https://api.github.com/repos/stdweird/vsc-install/contents/{+path}","compare_url":"https://api.github.com/repos/stdweird/vsc-install/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stdweird/vsc-install/merges","archive_url":"https://api.github.com/repos/stdweird/vsc-install/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stdweird/vsc-install/downloads","issues_url":"https://api.github.com/repos/stdweird/vsc-install/issues{/number}","pulls_url":"https://api.github.com/repos/stdweird/vsc-install/pulls{/number}","milestones_url":"https://api.github.com/repos/stdweird/vsc-install/milestones{/number}","notifications_url":"https://api.github.com/repos/stdweird/vsc-install/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stdweird/vsc-install/labels{/name}","releases_url":"https://api.github.com/repos/stdweird/vsc-install/releases{/id}","created_at":"2015-10-15T08:31:08Z","updated_at":"2015-10-28T13:48:51Z","pushed_at":"2015-11-24T10:04:54Z","git_url":"git://github.com/stdweird/vsc-install.git","ssh_url":"git@github.com:stdweird/vsc-install.git","clone_url":"https://github.com/stdweird/vsc-install.git","svn_url":"https://github.com/stdweird/vsc-install","homepage":null,"size":96,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hpcugent:master","ref":"master","sha":"45b3fbf3f115ed8cb6be73b6667fe902ed4ee456","user":{"login":"hpcugent","id":1515263,"avatar_url":"https://avatars.githubusercontent.com/u/1515263?v=3","gravatar_id":"","url":"https://api.github.com/users/hpcugent","html_url":"https://github.com/hpcugent","followers_url":"https://api.github.com/users/hpcugent/followers","following_url":"https://api.github.com/users/hpcugent/following{/other_user}","gists_url":"https://api.github.com/users/hpcugent/gists{/gist_id}","starred_url":"https://api.github.com/users/hpcugent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hpcugent/subscriptions","organizations_url":"https://api.github.com/users/hpcugent/orgs","repos_url":"https://api.github.com/users/hpcugent/repos","events_url":"https://api.github.com/users/hpcugent/events{/privacy}","received_events_url":"https://api.github.com/users/hpcugent/received_events","type":"Organization","site_admin":false},"repo":{"id":44304014,"name":"vsc-install","full_name":"hpcugent/vsc-install","owner":{"login":"hpcugent","id":1515263,"avatar_url":"https://avatars.githubusercontent.com/u/1515263?v=3","gravatar_id":"","url":"https://api.github.com/users/hpcugent","html_url":"https://github.com/hpcugent","followers_url":"https://api.github.com/users/hpcugent/followers","following_url":"https://api.github.com/users/hpcugent/following{/other_user}","gists_url":"https://api.github.com/users/hpcugent/gists{/gist_id}","starred_url":"https://api.github.com/users/hpcugent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hpcugent/subscriptions","organizations_url":"https://api.github.com/users/hpcugent/orgs","repos_url":"https://api.github.com/users/hpcugent/repos","events_url":"https://api.github.com/users/hpcugent/events{/privacy}","received_events_url":"https://api.github.com/users/hpcugent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hpcugent/vsc-install","description":"Shared setuptools functions and classes for python libraries developed by UGent's HPC group","fork":false,"url":"https://api.github.com/repos/hpcugent/vsc-install","forks_url":"https://api.github.com/repos/hpcugent/vsc-install/forks","keys_url":"https://api.github.com/repos/hpcugent/vsc-install/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hpcugent/vsc-install/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hpcugent/vsc-install/teams","hooks_url":"https://api.github.com/repos/hpcugent/vsc-install/hooks","issue_events_url":"https://api.github.com/repos/hpcugent/vsc-install/issues/events{/number}","events_url":"https://api.github.com/repos/hpcugent/vsc-install/events","assignees_url":"https://api.github.com/repos/hpcugent/vsc-install/assignees{/user}","branches_url":"https://api.github.com/repos/hpcugent/vsc-install/branches{/branch}","tags_url":"https://api.github.com/repos/hpcugent/vsc-install/tags","blobs_url":"https://api.github.com/repos/hpcugent/vsc-install/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hpcugent/vsc-install/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hpcugent/vsc-install/git/refs{/sha}","trees_url":"https://api.github.com/repos/hpcugent/vsc-install/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hpcugent/vsc-install/statuses/{sha}","languages_url":"https://api.github.com/repos/hpcugent/vsc-install/languages","stargazers_url":"https://api.github.com/repos/hpcugent/vsc-install/stargazers","contributors_url":"https://api.github.com/repos/hpcugent/vsc-install/contributors","subscribers_url":"https://api.github.com/repos/hpcugent/vsc-install/subscribers","subscription_url":"https://api.github.com/repos/hpcugent/vsc-install/subscription","commits_url":"https://api.github.com/repos/hpcugent/vsc-install/commits{/sha}","git_commits_url":"https://api.github.com/repos/hpcugent/vsc-install/git/commits{/sha}","comments_url":"https://api.github.com/repos/hpcugent/vsc-install/comments{/number}","issue_comment_url":"https://api.github.com/repos/hpcugent/vsc-install/issues/comments{/number}","contents_url":"https://api.github.com/repos/hpcugent/vsc-install/contents/{+path}","compare_url":"https://api.github.com/repos/hpcugent/vsc-install/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hpcugent/vsc-install/merges","archive_url":"https://api.github.com/repos/hpcugent/vsc-install/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hpcugent/vsc-install/downloads","issues_url":"https://api.github.com/repos/hpcugent/vsc-install/issues{/number}","pulls_url":"https://api.github.com/repos/hpcugent/vsc-install/pulls{/number}","milestones_url":"https://api.github.com/repos/hpcugent/vsc-install/milestones{/number}","notifications_url":"https://api.github.com/repos/hpcugent/vsc-install/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hpcugent/vsc-install/labels{/name}","releases_url":"https://api.github.com/repos/hpcugent/vsc-install/releases{/id}","created_at":"2015-10-15T08:30:59Z","updated_at":"2015-10-19T12:48:45Z","pushed_at":"2015-11-24T10:04:55Z","git_url":"git://github.com/hpcugent/vsc-install.git","ssh_url":"git@github.com:hpcugent/vsc-install.git","clone_url":"https://github.com/hpcugent/vsc-install.git","svn_url":"https://github.com/hpcugent/vsc-install","homepage":null,"size":89,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14"},"html":{"href":"https://github.com/hpcugent/vsc-install/pull/14"},"issue":{"href":"https://api.github.com/repos/hpcugent/vsc-install/issues/14"},"comments":{"href":"https://api.github.com/repos/hpcugent/vsc-install/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hpcugent/vsc-install/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/hpcugent/vsc-install/statuses/c3147d46dffc7d30010a4cb3c15bbf9b8c22ac58"}}}}