Skip to content

Commit

Permalink
try fixing config test
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Jan 10, 2025
1 parent 1aed9c4 commit 5c71eee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""DVC config objects."""

import ntpath
import os
import posixpath
import re
from contextlib import contextmanager
from functools import partial
Expand Down Expand Up @@ -268,12 +270,17 @@ def _resolve(conf_dir, path):
if re.match(r"\w+://", path):
return path

if os.name == "nt" and posixpath.isabs(path) and ntpath.sep not in path:
return path

if os.path.isabs(path):
return path

# on windows convert slashes to backslashes
# to have path compatible with abs_conf_dir
if os.path.sep == "\\" and "/" in path:
if path.startswith("/"):
path = path.replace("/", "\\\\", 1)
path = path.replace("/", "\\")

expanded = os.path.expanduser(path)
Expand Down Expand Up @@ -305,6 +312,9 @@ def _to_relpath(conf_dir, path):
if os.path.expanduser(path) != path:
return localfs.as_posix(path)

if os.name == "nt" and posixpath.isabs(path) and ntpath.sep not in path:
return path

if isinstance(path, RelPath) or not os.path.isabs(path):
path = relpath(path, conf_dir)
return localfs.as_posix(path)
Expand Down
5 changes: 3 additions & 2 deletions dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,10 @@ def repo_url(self) -> str:
return self.fs.repo_url

def from_os_path(self, path: str) -> str:
if os.path.isabs(path):
if os.path.isabs(path) or (
os.name == "nt" and posixpath.isabs(path) and ntpath.sep not in path
):
path = os.path.relpath(path, self.repo.root_dir)

return as_posix(path)

def close(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_match_ignore_from_file(
):
from dvc.fs import localfs

root = os.path.sep * (2 if os.name == "nt" else 1)
root = r"\\" if os.name == "nt" else "/"
dvcignore_path = os.path.join(
root, "full", "path", "to", "ignore", "file", ".dvcignore"
)
Expand Down

0 comments on commit 5c71eee

Please sign in to comment.