Skip to content

Commit 87dbb29

Browse files
committed
Use path more consistent
1 parent 278baa4 commit 87dbb29

7 files changed

Lines changed: 20 additions & 18 deletions

File tree

dfetch/project/superproject.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def __init__(self) -> None:
4141

4242
logger.debug(f"Using manifest {manifest_path}")
4343
self._manifest = parse(manifest_path)
44-
self._root_directory = str(
45-
resolve_absolute_path(os.path.dirname(self._manifest.path))
44+
self._root_directory = resolve_absolute_path(
45+
os.path.dirname(self._manifest.path)
4646
)
4747

4848
@property
49-
def root_directory(self) -> str:
49+
def root_directory(self) -> pathlib.Path:
5050
"""Return the directory that contains the manifest file."""
5151
return self._root_directory
5252

@@ -67,11 +67,10 @@ def get_sub_project(self, project: ProjectEntry) -> SubProject | None:
6767
def ignored_files(self, path: str) -> Sequence[str]:
6868
"""Return a list of files that can be ignored in a given path."""
6969
resolved_path = resolve_absolute_path(path)
70-
root_path = pathlib.Path(self.root_directory)
7170

72-
if not resolved_path.is_relative_to(root_path):
71+
if not resolved_path.is_relative_to(self.root_directory):
7372
raise RuntimeError(
74-
f"{resolved_path} not in superproject {self.root_directory}! "
73+
f"{resolved_path} not in superproject {self.root_directory}!"
7574
)
7675

7776
if GitLocalRepo(self.root_directory).is_git():

dfetch/util/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def safe_rmtree(path: str) -> None:
6363

6464

6565
@contextmanager
66-
def in_directory(path: str) -> Generator[str, None, None]:
66+
def in_directory(path: Union[str, Path]) -> Generator[str, None, None]:
6767
"""Work temporarily in a given directory."""
6868
pwd = os.getcwd()
6969
if not os.path.isdir(path):
7070
path = os.path.dirname(path)
7171
os.chdir(path)
7272
try:
73-
yield path
73+
yield str(path)
7474
finally:
7575
os.chdir(pwd)
7676

dfetch/vcs/git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tempfile
88
from collections.abc import Generator, Sequence
99
from pathlib import Path, PurePath
10-
from typing import NamedTuple, Optional
10+
from typing import NamedTuple, Optional, Union
1111

1212
from dfetch.log import get_logger
1313
from dfetch.util.cmdline import SubprocessCommandError, run_on_cmdline
@@ -234,9 +234,9 @@ class GitLocalRepo:
234234

235235
METADATA_DIR = ".git"
236236

237-
def __init__(self, path: str = ".") -> None:
237+
def __init__(self, path: Union[str, Path] = ".") -> None:
238238
"""Create a local git repo."""
239-
self._path = path
239+
self._path = str(path)
240240

241241
def is_git(self) -> bool:
242242
"""Check if is git."""

dfetch/vcs/svn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pathlib
55
import re
66
from collections.abc import Sequence
7-
from typing import NamedTuple, Optional
7+
from typing import NamedTuple, Optional, Union
88

99
from dfetch.log import get_logger
1010
from dfetch.util.cmdline import SubprocessCommandError, run_on_cmdline
@@ -76,10 +76,10 @@ class SvnRepo:
7676

7777
def __init__(
7878
self,
79-
path: str = ".",
79+
path: Union[str, pathlib.Path] = ".",
8080
) -> None:
8181
"""Create a svn repo."""
82-
self._path = path
82+
self._path = str(path)
8383

8484
def is_svn(self) -> bool:
8585
"""Check if is SVN."""

tests/test_check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# flake8: noqa
55

66
import argparse
7+
from pathlib import Path
78
from unittest.mock import Mock, patch
89

910
import pytest
@@ -30,7 +31,7 @@ def test_check(name, projects):
3031

3132
fake_superproject = Mock()
3233
fake_superproject.manifest = mock_manifest(projects)
33-
fake_superproject.root_directory = "/tmp"
34+
fake_superproject.root_directory = Path("/tmp")
3435

3536
with patch("dfetch.commands.check.SuperProject", return_value=fake_superproject):
3637
with patch(

tests/test_report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# flake8: noqa
55

66
import argparse
7+
from pathlib import Path
78
from unittest.mock import Mock, patch
89

910
import pytest
@@ -30,7 +31,7 @@ def test_report(name, projects):
3031

3132
fake_superproject = Mock()
3233
fake_superproject.manifest = mock_manifest(projects)
33-
fake_superproject.root_directory = "/tmp"
34+
fake_superproject.root_directory = Path("/tmp")
3435

3536
with patch("dfetch.commands.report.SuperProject", return_value=fake_superproject):
3637
with patch("dfetch.log.DLogger.print_info_line") as mocked_print_info_line:

tests/test_update.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# flake8: noqa
55

66
import argparse
7+
from pathlib import Path
78
from unittest.mock import Mock, patch
89

910
import pytest
@@ -30,7 +31,7 @@ def test_update(name, projects):
3031

3132
fake_superproject = Mock()
3233
fake_superproject.manifest = mock_manifest(projects)
33-
fake_superproject.root_directory = "/tmp"
34+
fake_superproject.root_directory = Path("/tmp")
3435

3536
with patch("dfetch.commands.update.SuperProject", return_value=fake_superproject):
3637
with patch(
@@ -53,7 +54,7 @@ def test_forced_update():
5354

5455
fake_superproject = Mock()
5556
fake_superproject.manifest = mock_manifest([{"name": "some_project"}])
56-
fake_superproject.root_directory = "/tmp"
57+
fake_superproject.root_directory = Path("/tmp")
5758
fake_superproject.ignored_files.return_value = []
5859

5960
with patch("dfetch.commands.update.SuperProject", return_value=fake_superproject):

0 commit comments

Comments
 (0)