Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dvc/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def _open(
fs_path = path
else:
fs = DVCFileSystem(repo=_repo, subrepos=True)
fs_path = fs.from_os_path(path)
rel_path = fs.from_os_path(path)
fs_path = fs.join(fs.root_marker, rel_path)

try:
with fs.open(fs_path, mode=mode, encoding=encoding) as fobj:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ def test_open_rev_raises_error_on_wrong_mode(tmp_dir, dvc):
):
with api.open("foo", mode="w"):
pass


def test_api_read_from_subdir_with_repo_arg(tmp_dir, dvc):
"""Ensure relative paths are resolved from repo root, not cwd."""

tmp_dir.dvc_gen({"data": {"data.xml": "contents"}})
subdir = tmp_dir / "src"
subdir.mkdir()

with subdir.chdir():
assert api.read("data/data.xml", repo=str(tmp_dir)) == "contents"