Skip to content

Commit c50c28b

Browse files
committed
refactor(cli[utils]): Remove _get_abs_path
1 parent 67f4d96 commit c50c28b

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

src/tmuxp/cli/import_config.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
from tmuxp.config_reader import ConfigReader
88

99
from .. import config
10-
from .utils import (
11-
get_abs_path,
12-
prompt,
13-
prompt_choices,
14-
prompt_yes_no,
15-
scan_config,
16-
tmuxp_echo,
17-
)
10+
from .utils import prompt, prompt_choices, prompt_yes_no, scan_config, tmuxp_echo
1811

1912

2013
def get_tmuxinator_dir() -> str:
@@ -55,10 +48,10 @@ def get_teamocil_dir() -> str:
5548

5649

5750
def _resolve_path_no_overwrite(config: str) -> str:
58-
path = get_abs_path(config)
59-
if os.path.exists(path):
51+
path = pathlib.Path(config).resolve()
52+
if path.exists():
6053
raise ValueError("%s exists. Pick a new filename." % path)
61-
return path
54+
return str(path)
6255

6356

6457
def command_import(

src/tmuxp/cli/utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,6 @@ def get_config_dir() -> str:
6363
return path
6464

6565

66-
def get_abs_path(config: str) -> str:
67-
path = os.path
68-
join, isabs = path.join, path.isabs
69-
dirname, normpath = path.dirname, path.normpath
70-
cwd = os.getcwd()
71-
72-
config = os.path.expanduser(config)
73-
if not isabs(config) or len(dirname(config)) > 1:
74-
config = normpath(join(cwd, config))
75-
76-
return config
77-
78-
7966
def scan_config(
8067
config: t.Union[pathlib.Path, str],
8168
config_dir: t.Optional[t.Union[pathlib.Path, str]] = None,

tests/test_cli.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
load_plugins,
2424
load_workspace,
2525
)
26-
from tmuxp.cli.utils import (
27-
get_abs_path,
28-
get_config_dir,
29-
is_pure_name,
30-
scan_config,
31-
tmuxp_echo,
32-
)
26+
from tmuxp.cli.utils import get_config_dir, is_pure_name, scan_config, tmuxp_echo
3327
from tmuxp.config_reader import ConfigReader
3428
from tmuxp.workspacebuilder import WorkspaceBuilder
3529

@@ -1126,13 +1120,15 @@ def test_freeze_overwrite(
11261120
assert yaml_config_path.exists()
11271121

11281122

1129-
def test_get_abs_path(tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch) -> None:
1123+
def test_resolve_behavior(
1124+
tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
1125+
) -> None:
11301126
expect = str(tmp_path)
11311127
monkeypatch.chdir(tmp_path)
1132-
get_abs_path("../") == os.path.dirname(expect)
1133-
get_abs_path(".") == expect
1134-
get_abs_path("./") == expect
1135-
get_abs_path(expect) == expect
1128+
pathlib.Path("../").resolve() == os.path.dirname(expect)
1129+
pathlib.Path(".").resolve() == expect
1130+
pathlib.Path("./").resolve() == expect
1131+
pathlib.Path(expect).resolve() == expect
11361132

11371133

11381134
def test_get_tmuxinator_dir(monkeypatch: pytest.MonkeyPatch) -> None:

0 commit comments

Comments
 (0)