Skip to content

Commit

Permalink
Add expanduser to pathlib paths
Browse files Browse the repository at this point in the history
Co-authored-by: Zach Burnett <[email protected]>
  • Loading branch information
braingram and zacharyburnett committed May 7, 2024
1 parent 39fde35 commit d4cd81e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion asdf/generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def __init__(self, fd, mode, close=False, uri=None):
super().__init__(fd, mode, close=close, uri=uri)

if uri is None and hasattr(fd, "name") and isinstance(fd.name, str):
self._uri = pathlib.Path(fd.name).absolute().as_uri()
self._uri = pathlib.Path(fd.name).expanduser().absolute().as_uri()

def write_array(self, arr):
if isinstance(arr, np.memmap) and getattr(arr, "fd", None) is self:
Expand Down
6 changes: 4 additions & 2 deletions pytest_asdf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,17 @@ def runtest(self):
buff = helpers.yaml_to_asdf("example: " + self.example.example.strip(), version=self.example.version)

ff = AsdfFile(
uri=pathlib.Path(self.filename).absolute().as_uri(),
uri=pathlib.Path(self.filename).expanduser().absolute().as_uri(),
ignore_unrecognized_tag=self.ignore_unrecognized_tag,
ignore_version_mismatch=self.ignore_version_mismatch,
)

# Fake an external file
ff2 = AsdfFile({"data": np.empty((1024 * 1024 * 8), dtype=np.uint8)})

ff._external_asdf_by_uri[(pathlib.Path(self.filename).absolute().parent / "external.asdf").as_uri()] = ff2
ff._external_asdf_by_uri[
(pathlib.Path(self.filename).expanduser().absolute().parent / "external.asdf").as_uri()
] = ff2

wb = _block.writer.WriteBlock(np.zeros(1024 * 1024 * 8, dtype=np.uint8))
with generic_io.get_file(buff, mode="rw") as f:
Expand Down

0 comments on commit d4cd81e

Please sign in to comment.