def expand_and_make_dir(x): """Expands a variable that represents a directory, and ensures that the directory actually exists. """ x = os.path.abspath(expand_path(x)) os.makedirs(x, exist_ok=True) return x
def expand_file_and_mkdirs(x): """Expands a variable that represents a file, and ensures that the directory it lives in actually exists. """ x = os.path.abspath(expand_path(x)) d = os.path.dirname(x) os.makedirs(d, exist_ok=True) return x
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xession): if os.sep != "/": inp = inp.replace("/", os.sep) exp_end = exp_end.replace("/", os.sep) xession.env.update({"foo": "bar", "a_bool": True, "an_int": 42, "none": None}) xession.env["EXPAND_ENV_VARS"] = expand_env_vars path = expand_path(inp, expand_user=expand_user) if expand_user: home_path = os.path.expanduser("~") assert path == home_path + exp_end else: assert path == "~" + exp_end
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins): if os.sep != "/": inp = inp.replace("/", os.sep) exp_end = exp_end.replace("/", os.sep) env = Env({"foo": "bar", "a_bool": True, "an_int": 42, "none": None}) env["EXPAND_ENV_VARS"] = expand_env_vars xonsh_builtins.__xonsh__.env = env path = expand_path(inp, expand_user=expand_user) if expand_user: home_path = os.path.expanduser("~") assert path == home_path + exp_end else: assert path == "~" + exp_end
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins): if os.sep != "/": inp = inp.replace("/", os.sep) exp_end = exp_end.replace("/", os.sep) env = Env({"foo": "bar", "a_bool": True, "an_int": 42, "none": None}) env["EXPAND_ENV_VARS"] = expand_env_vars xonsh_builtins.__xonsh__.env = env path = expand_path(inp, expand_user=expand_user) if expand_user: home_path = os.path.expanduser("~") assert path == home_path + exp_end else: assert path == "~" + exp_end
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins): if os.sep != '/': inp = inp.replace('/', os.sep) exp_end = exp_end.replace('/', os.sep) env = Env({'foo':'bar', 'a_bool': True, 'an_int': 42, 'none': None}) env['EXPAND_ENV_VARS'] = expand_env_vars xonsh_builtins.__xonsh_env__ = env path = expand_path(inp, expand_user=expand_user) if expand_user: home_path = os.path.expanduser('~') assert path == home_path + exp_end else: assert path == '~' + exp_end
def regexsearch(s): s = expand_path(s) return reglob(s)
def path_literal(s): s = expand_path(s) return pathlib.Path(s)
def regexsearch(s): s = expand_path(s) return reglob(s)
def path_literal(s): s = expand_path(s) return pathlib.Path(s)