From 36f25cd983f8f465cf2c795701b2576728f2b8af Mon Sep 17 00:00:00 2001 From: Jonathan Bohren Date: Fri, 3 Apr 2015 06:29:58 -0400 Subject: [PATCH 1/2] optimization: caching resultspace environments --- catkin_tools/resultspace.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/catkin_tools/resultspace.py b/catkin_tools/resultspace.py index f020205a..acd633d0 100644 --- a/catkin_tools/resultspace.py +++ b/catkin_tools/resultspace.py @@ -9,6 +9,9 @@ CMAKE_EXEC = which('cmake') SORT_EXEC = which('sort') +# Cache for result-space environments +_resultspace_env_cache = {} + def get_resultspace_environment(result_space_path, quiet=False): """Get the environemt variables which result from sourcing another catkin @@ -22,6 +25,11 @@ def get_resultspace_environment(result_space_path, quiet=False): :returns: a dictionary of environment variables and their values """ + + # Check the cache first + if result_space_path in _resultspace_env_cache: + return _resultspace_env_cache[result_space_path] + # Check to make sure result_space_path is a valid directory if not os.path.isdir(result_space_path): if quiet: @@ -94,6 +102,8 @@ def get_resultspace_environment(result_space_path, quiet=False): print("WARNING: Failed to extract environment from resultspace: %s: %s" % (result_space_path, str(err))) return {} + _resultspace_env_cache[result_space_path] = env_dict + return env_dict From 866e111023767b6ef2216f51030d026d5a7e7ec4 Mon Sep 17 00:00:00 2001 From: Jonathan Bohren Date: Mon, 6 Apr 2015 23:23:29 -0400 Subject: [PATCH 2/2] resultspace: adding option to use or ignore caching --- catkin_tools/resultspace.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/catkin_tools/resultspace.py b/catkin_tools/resultspace.py index acd633d0..57d9ba19 100644 --- a/catkin_tools/resultspace.py +++ b/catkin_tools/resultspace.py @@ -13,7 +13,7 @@ _resultspace_env_cache = {} -def get_resultspace_environment(result_space_path, quiet=False): +def get_resultspace_environment(result_space_path, quiet=False, cached=True): """Get the environemt variables which result from sourcing another catkin workspace's setup files as the string output of `cmake -E environment`. This command is used to be as portable as possible. @@ -22,12 +22,14 @@ def get_resultspace_environment(result_space_path, quiet=False): :type result_space_path: str :param quiet: don't throw exceptions, ``bool`` :type quiet: bool + :param cached: use the cached environment + :type cached: bool :returns: a dictionary of environment variables and their values """ # Check the cache first - if result_space_path in _resultspace_env_cache: + if cached and result_space_path in _resultspace_env_cache: return _resultspace_env_cache[result_space_path] # Check to make sure result_space_path is a valid directory @@ -107,12 +109,14 @@ def get_resultspace_environment(result_space_path, quiet=False): return env_dict -def load_resultspace_environment(result_space_path): +def load_resultspace_environment(result_space_path, cached=True): """Load the environemt variables which result from sourcing another workspace path into this process's environment. :param result_space_path: path to a Catkin result-space whose environment should be loaded, ``str`` :type result_space_path: str + :param cached: use the cached environment + :type cached: bool """ - env_dict = get_resultspace_environment(result_space_path) + env_dict = get_resultspace_environment(result_space_path, cached=cached) os.environ.update(env_dict)