Skip to content

Commit 80dbd6d

Browse files
clementmartinClément Martinssbarnea
authored
Move abspath() to file_utils (#1769)
Co-authored-by: Clément Martin <[email protected]> Co-authored-by: Sorin Sbarnea <[email protected]>
1 parent 3e28f9f commit 80dbd6d

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/ansiblelint/cli.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
DEFAULT_RULESDIR,
1717
INVALID_CONFIG_RC,
1818
)
19-
from ansiblelint.file_utils import expand_path_vars, guess_project_dir, normpath
19+
from ansiblelint.file_utils import (
20+
abspath,
21+
expand_path_vars,
22+
guess_project_dir,
23+
normpath,
24+
)
2025

2126
_logger = logging.getLogger(__name__)
2227
_PATH_VARS = [
@@ -25,22 +30,6 @@
2530
]
2631

2732

28-
def abspath(path: str, base_dir: str) -> str:
29-
"""Make relative path absolute relative to given directory.
30-
31-
Args:
32-
path (str): the path to make absolute
33-
base_dir (str): the directory from which make \
34-
relative paths absolute
35-
"""
36-
if not os.path.isabs(path):
37-
# Don't use abspath as it assumes path is relative to cwd.
38-
# We want it relative to base_dir.
39-
path = os.path.join(base_dir, path)
40-
41-
return os.path.normpath(path)
42-
43-
4433
def expand_to_normalized_paths(
4534
config: Dict[str, Any], base_dir: Optional[str] = None
4635
) -> None:

src/ansiblelint/file_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
_logger = logging.getLogger(__package__)
2929

3030

31+
def abspath(path: str, base_dir: str) -> str:
32+
"""Make relative path absolute relative to given directory.
33+
34+
Args:
35+
path (str): the path to make absolute
36+
base_dir (str): the directory from which make \
37+
relative paths absolute
38+
"""
39+
if not os.path.isabs(path):
40+
# Don't use abspath as it assumes path is relative to cwd.
41+
# We want it relative to base_dir.
42+
path = os.path.join(base_dir, path)
43+
44+
return os.path.normpath(path)
45+
46+
3147
def normpath(path: Union[str, BasePathLike]) -> str:
3248
"""
3349
Normalize a path in order to provide a more consistent output.

test/TestRunner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import pytest
2424

2525
from ansiblelint import formatters
26-
from ansiblelint.cli import abspath
27-
from ansiblelint.file_utils import Lintable
26+
from ansiblelint.file_utils import Lintable, abspath
2827
from ansiblelint.rules import RulesCollection
2928
from ansiblelint.runner import Runner
3029

0 commit comments

Comments
 (0)