From a051f24e0d7ae5b98b0ae588401d07f4a604d993 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 3 May 2017 13:00:13 +0100 Subject: [PATCH 1/3] Don't call sys_info() at import time --- notebook/base/handlers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index 2c48d5cc14..cf3e183f09 100755 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -39,7 +39,12 @@ #----------------------------------------------------------------------------- non_alphanum = re.compile(r'[^A-Za-z0-9]') -sys_info = json.dumps(get_sys_info()) +_sys_info_cache = None +def json_sys_info(): + global _sys_info_cache + if _sys_info_cache is None: + _sys_info_cache = json.dumps(get_sys_info()) + return _sys_info_cache def log(): if Application.initialized(): @@ -357,7 +362,7 @@ def template_namespace(self): login_available=self.login_available, token_available=bool(self.token or self.one_time_token), static_url=self.static_url, - sys_info=sys_info, + sys_info=json_sys_info(), contents_js_source=self.contents_js_source, version_hash=self.version_hash, ignore_minified_js=self.ignore_minified_js, From 7454e8c954e21a9e9bfc667ab9cd2c4d6c510439 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 3 May 2017 13:04:21 +0100 Subject: [PATCH 2/3] Don't use shell when getting git commit ID --- notebook/_sysinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/_sysinfo.py b/notebook/_sysinfo.py index ea237bbd2a..bc976e2824 100644 --- a/notebook/_sysinfo.py +++ b/notebook/_sysinfo.py @@ -46,10 +46,10 @@ def pkg_commit_hash(pkg_path): while cur_path != par_path: cur_path = par_path if p.exists(p.join(cur_path, '.git')): - proc = subprocess.Popen('git rev-parse --short HEAD', + proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=pkg_path, shell=True) + cwd=pkg_path) repo_commit, _ = proc.communicate() if repo_commit: return 'repository', repo_commit.strip().decode('ascii') From 83e1a23ce3d5952f38cee884835f1aa66a2ee0fd Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 3 May 2017 13:06:58 +0100 Subject: [PATCH 3/3] Catch errors calling git for commit ID Closes gh-2468 --- notebook/_sysinfo.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/notebook/_sysinfo.py b/notebook/_sysinfo.py index bc976e2824..4e6a366266 100644 --- a/notebook/_sysinfo.py +++ b/notebook/_sysinfo.py @@ -46,11 +46,15 @@ def pkg_commit_hash(pkg_path): while cur_path != par_path: cur_path = par_path if p.exists(p.join(cur_path, '.git')): - proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - cwd=pkg_path) - repo_commit, _ = proc.communicate() + try: + proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=pkg_path) + repo_commit, _ = proc.communicate() + except OSError: + repo_commit = None + if repo_commit: return 'repository', repo_commit.strip().decode('ascii') else: