def test_select_config_works_env_vars(self, cfg_file, varname="TEST"): os.environ[varname] = cfg_file assert isinstance(yacman.select_config(config_env_vars=varname), str) assert yacman.select_config( config_env_vars=varname) == yacman.select_config( config_filepath=cfg_file) del os.environ[varname]
def select_bulker_config(filepath): bulkercfg = yacman.select_config( filepath, "BULKERCFG", default_config_filepath=DEFAULT_CONFIG_FILEPATH, check_exist=True) _LOGGER.debug("Selected bulker config: {}".format(bulkercfg)) return bulkercfg
def select_genome_config(filename=None, conf_env_vars=CFG_ENV_VARS, **kwargs): """ Get path to genome configuration file. :param str filename: name/path of genome configuration file :param Iterable[str] conf_env_vars: names of environment variables to consider; basically, a prioritized search list :return str: path to genome configuration file """ return select_config(filename, conf_env_vars, **kwargs)
def get_bedbase_cfg(cfg=None): """ Determine path to the bedbase configuration file The path can be either explicitly provided or read from a $BEDBASE environment variable :param str cfg: path to the config file. Optional, the $BEDBASE config env var will be used if not provided :return str: configuration file path """ selected_cfg = select_config(config_filepath=cfg, config_env_vars=CFG_ENV_VARS) if not selected_cfg: raise BedBaseConnectionError( f"You must provide a config file or set the " f"{'or '.join(CFG_ENV_VARS)} environment variable") return selected_cfg
def select_divvy_config(filepath): """ Selects the divvy config file path to load. This uses a priority ordering to first choose a config file path if it's given, but if not, then look in a priority list of environment variables and choose the first available file path to return. If none of these options succeed, the default config path will be returned. :param str | NoneType filepath: direct file path specification :return str: path to the config file to read """ divcfg = yacman.select_config( config_filepath=filepath, config_env_vars=COMPUTE_SETTINGS_VARNAME, default_config_filepath=DEFAULT_CONFIG_FILEPATH, check_exist=True, ) _LOGGER.debug("Selected divvy config: {}".format(divcfg)) return divcfg
def main(): """ Primary workflow """ parser = logmuse.add_logging_options(build_argparser()) args, remaining_args = parser.parse_known_args() global _LOGGER _LOGGER = logmuse.logger_via_cli(args) logmuse.logger_via_cli(args, name=refgenconf.__name__) _LOGGER.debug("Args: {}".format(args)) if not args.command: parser.print_help() _LOGGER.error("No command given") sys.exit(1) gencfg = yacman.select_config(args.genome_config, CFG_ENV_VARS, check_exist=not args.command == INIT_CMD, on_missing=lambda fp: fp) if gencfg is None: raise MissingGenomeConfigError(args.genome_config) _LOGGER.debug("Determined genome config: {}".format(gencfg)) if args.command == INIT_CMD: _LOGGER.info("Initializing refgenie genome configuration") _writeable(os.path.dirname(gencfg), strict_exists=True) refgenie_init(gencfg, args.genome_server) sys.exit(0) rgc = RefGenConf(gencfg) if args.command == BUILD_CMD: refgenie_build(rgc, args) elif args.command == GET_ASSET_CMD: _LOGGER.debug("getting asset: '{}/{}'".format(args.genome, args.asset)) print(" ".join( [rgc.get_asset(args.genome, asset) for asset in args.asset])) return elif args.command == INSERT_CMD: if len(args.asset) > 1: raise NotImplementedError("Can only add 1 asset at a time") else: # recast from list to str args.asset = args.asset[0] refgenie_add(rgc, args) elif args.command == PULL_CMD: outdir = rgc[CFG_FOLDER_KEY] if not os.path.exists(outdir): raise MissingFolderError(outdir) target = _key_to_name(CFG_FOLDER_KEY) if not perm_check_x(outdir, target): return if not _single_folder_writeable(outdir): _LOGGER.error("Insufficient permissions to write to {}: " "{}".format(target, outdir)) return rgc.pull_asset(args.genome, args.asset, gencfg, unpack=not args.no_untar) elif args.command in [LIST_LOCAL_CMD, LIST_REMOTE_CMD]: pfx, genomes, assets = _exec_list(rgc, args.command == LIST_REMOTE_CMD) _LOGGER.info("{} genomes: {}".format(pfx, genomes)) _LOGGER.info("{} assets:\n{}".format(pfx, assets))
def test_select_config_errors_if_no_cfg_found_and_strict_checks_requested( self, varname="TEST"): os.environ[varname] = "bogus/path.yaml" with pytest.raises(Exception): yacman.select_config(config_env_vars=varname, strict_env=True) del os.environ[varname]
def test_select_config_returns_none_if_no_cfg_found(self, varname="TEST"): os.environ[varname] = "bogus/path.yaml" assert yacman.select_config(config_env_vars=varname) is None del os.environ[varname]
def test_select_config_returns_default_cfg(self, path="path.yaml"): assert yacman.select_config(default_config_filepath=path) == path
def test_select_config_works_with_filepath(self, cfg_file): assert isinstance(yacman.select_config(config_filepath=cfg_file), str)