Skip to content

Commit adc2ead

Browse files
committed
util(cleanup): Remove deprecated contract_user_home
1 parent 49b250e commit adc2ead

File tree

3 files changed

+12
-83
lines changed

3 files changed

+12
-83
lines changed

src/vcspull/util.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import typing as t
88
from collections.abc import Mapping
99

10-
from vcspull._internal.private_path import PrivatePath
11-
1210
LEGACY_CONFIG_DIR = pathlib.Path("~/.vcspull/").expanduser() # remove dupes of this
1311

1412

@@ -44,47 +42,6 @@ def get_config_dir() -> pathlib.Path:
4442
return path
4543

4644

47-
def contract_user_home(path: str | pathlib.Path) -> str:
48-
"""Contract user home directory to ~ for display purposes.
49-
50-
Parameters
51-
----------
52-
path : str | pathlib.Path
53-
Path to contract
54-
55-
Returns
56-
-------
57-
str
58-
Path with $HOME contracted to ~
59-
60-
Examples
61-
--------
62-
>>> contract_user_home("/home/user/code/repo")
63-
'~/code/repo'
64-
>>> contract_user_home("/opt/project")
65-
'/opt/project'
66-
"""
67-
path_str = str(path)
68-
if path_str == "":
69-
return path_str
70-
71-
if path_str.startswith("~"):
72-
return path_str
73-
74-
home_str = str(pathlib.Path.home())
75-
if path_str.startswith(home_str):
76-
collapsed = str(PrivatePath(pathlib.Path(path_str)))
77-
if (
78-
path_str.endswith(os.sep)
79-
and not collapsed.endswith(os.sep)
80-
and path_str.rstrip(os.sep) != home_str
81-
):
82-
collapsed += os.sep
83-
return collapsed
84-
85-
return path_str
86-
87-
8845
T = t.TypeVar("T", bound=dict[str, t.Any])
8946

9047

tests/_internal/test_private_path.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ def test_absolute_paths_outside_home_are_unmodified() -> None:
2929
def test_existing_tilde_prefix_is_preserved() -> None:
3030
path = PrivatePath("~/.config/vcspull")
3131
assert str(path) == "~/.config/vcspull"
32+
33+
34+
def test_trailing_slash_collapses_to_directory_label() -> None:
35+
home = Path.home()
36+
path = PrivatePath(home / "projects/")
37+
assert str(path) == f"~{os.sep}projects"
38+
39+
40+
def test_relative_path_unmodified() -> None:
41+
path = PrivatePath("relative/path")
42+
assert str(path) == "relative/path"

tests/test_utils.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pathlib
66
import typing as t
77

8-
from vcspull.util import contract_user_home, get_config_dir
8+
from vcspull.util import get_config_dir
99

1010
if t.TYPE_CHECKING:
1111
import pytest
@@ -37,42 +37,3 @@ def test_vcspull_configdir_no_xdg(monkeypatch: pytest.MonkeyPatch) -> None:
3737
"""Test retrieving config directory without XDG_CONFIG_HOME set."""
3838
monkeypatch.delenv("XDG_CONFIG_HOME")
3939
assert get_config_dir()
40-
41-
42-
def test_contract_user_home_contracts_home_path() -> None:
43-
"""Test contracting home directory to ~."""
44-
home = str(pathlib.Path.home())
45-
46-
# Test full path
47-
assert contract_user_home(f"{home}/code/repo") == "~/code/repo"
48-
49-
# Test home directory itself
50-
assert contract_user_home(home) == "~"
51-
52-
# Test with pathlib.Path
53-
assert contract_user_home(pathlib.Path(home) / "code" / "repo") == "~/code/repo"
54-
55-
56-
def test_contract_user_home_preserves_non_home_paths() -> None:
57-
"""Test that non-home paths are not contracted."""
58-
# Test absolute paths outside home
59-
assert contract_user_home("/opt/project") == "/opt/project"
60-
assert contract_user_home("/usr/local/bin") == "/usr/local/bin"
61-
62-
# Test relative paths
63-
assert contract_user_home("./relative/path") == "./relative/path"
64-
assert contract_user_home("relative/path") == "relative/path"
65-
66-
67-
def test_contract_user_home_handles_edge_cases() -> None:
68-
"""Test edge cases in path contraction."""
69-
home = str(pathlib.Path.home())
70-
71-
# Test trailing slashes
72-
assert contract_user_home(f"{home}/code/") == "~/code/"
73-
74-
# Test empty path
75-
assert contract_user_home("") == ""
76-
77-
# Test path with ~ already in it (should pass through)
78-
assert contract_user_home("~/code/repo") == "~/code/repo"

0 commit comments

Comments
 (0)