def test_check_and_expand_path(self, mock_is_dir, mock_expanduser): mock_expanduser.side_effect = lambda x: re.sub('~', 'Users/lb', x) mock_is_dir.side_effect = lambda x: x == 'Users/lb/cache' misc.check_and_expand_path('~/cache') misc.check_and_expand_path('Users/lb/cache') with self.assertRaises(ex_classes.PrerequisiteError): misc.check_and_expand_path('~/~/cache') with self.assertRaises(ex_classes.PrerequisiteError): misc.check_and_expand_path('lb/cache') with self.assertRaises(ex_classes.PrerequisiteError): misc.check_and_expand_path(3)
def configuration(ARGUMENTS, paper = False, config_user_yaml = 'config_user.yaml', config_global_yaml = 'config_global.yaml'): # Determines whether to print traceback messages debug = ARGUMENTS.get('debug', False) if not debug: # Hide traceback for configuration test only # http://stackoverflow.com/questions/27674602/hide-traceback-unless-a-debug-flag-is-set sys.tracebacklimit = 100 # Copies config_user template if no such file exists if not os.path.isfile(config_user_yaml): shutil.copy('../config/config_user_template.yaml', config_user_yaml) # Loads arguments and configurations mode = ARGUMENTS.get('mode', 'develop') # Gets mode; defaults to 'develop' # Checks mode if not (mode in ['develop', 'cache']): message = 'Error: %s is not a defined mode' % mode raise _exception_classes.PrerequisiteError(message) # Checks for cache directory if mode == 'cache': cache_dir = misc.load_yaml_value(config_user_yaml, 'cache_directory') cache_dir = misc.check_and_expand_path(cache_dir) else: cache_dir = None # Loads config yaml files CONFIG = {'user': config_user_yaml, 'global': config_global_yaml} for key, val in CONFIG.items(): CONFIG[key] = yaml.load(open(val, 'rU')) if not CONFIG[key]: del CONFIG[key] # Stores executable names and prerequisite checks. Prefer user to global. executable_names = misc.add_two_dict_keys(d = CONFIG, common_key = 'executable_names') prereq_checks = misc.add_two_dict_keys(d = CONFIG, common_key = 'prereq_checks') # Checks prerequisite applications and record known prereqs prereqs = [] for prereq, should_check_prereq in prereq_checks.items(): if str(should_check_prereq).lower().strip() in ['y', 'yes', 't', 'true']: check_prereq(prereq, manual_execs = executable_names, gslab_vers = CONFIG['global']['gslab_version']) prereqs.append(prereq) # Stores PYTHONPATH try: pythonpath = os.environ['PYTHONPATH'] except KeyError: pythonpath = '' # Gets return list return_list = [mode, cache_dir, CONFIG, executable_names, prereqs, pythonpath] # Restores default tracebacklimit and return values sys.tracebacklimit = 1000 return return_list
def configuration_test(ARGUMENTS, gslab_python_version): # Determines whether to print traceback messages debug = ARGUMENTS.get('debug', False) if not debug: # Hide traceback for configuration test only # http://stackoverflow.com/questions/27674602/hide-traceback-unless-a-debug-flag-is-set sys.tracebacklimit = 0 # Checks initial prerequisites try: from gslab_scons import configuration_tests as config except ImportError: message = 'Your gslab_tools Python modules installation is outdated' raise Exception(message) config.check_python(gslab_python_version=gslab_python_version, packages=["yaml", "gslab_scons", "gslab_fill"]) config.check_lyx() config.check_lfs() stata_executable = config.check_stata(["yaml"]) # Uncomment if using # config.check_r(packages = ["yaml"]) # Loads arguments and configurations mode = ARGUMENTS.get('mode', 'develop') # Gets mode; defaults to 'develop' # Checks mode/version if not (mode in ['develop', 'cache']): message = "Error: %s is not a defined mode" % mode raise _exception_classes.PrerequisiteError(message) # Get return list if mode == 'cache': cache_dir = misc.load_yaml_value("user-config.yaml", "cache_directory") cache_dir = misc.check_and_expand_path(cache_dir) return_list = [mode, stata_executable, cache_dir] else: return_list = [mode, stata_executable, None] # Restore default tracebacklimit and return values sys.tracebacklimit = 1000 return return_list