Skip to content

Commit

Permalink
Support use of pathlib.Path for asdf.open and write_to
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Nov 21, 2018
1 parent e89a27a commit af67f0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

- Deprecate the ``asdf.asdftypes`` module in favor of ``asdf.types``. [#611]

- Support use of ``pathlib.Path`` with ``asdf.open`` and ``AsdfFile.write_to``.
[#617]

2.2.1 (2018-11-15)
------------------

Expand Down
9 changes: 5 additions & 4 deletions asdf/generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"""

import io
import math
import os
import platform
import re
import sys
import math
import pathlib
import tempfile
import platform
from distutils.version import LooseVersion

from os import SEEK_SET, SEEK_CUR, SEEK_END
Expand Down Expand Up @@ -1171,8 +1172,8 @@ def get_file(init, mode='r', uri=None, close=False):
init.mode, mode))
return GenericWrapper(init)

elif isinstance(init, str):
parsed = urlparse.urlparse(init)
elif isinstance(init, (str, pathlib.Path)):
parsed = urlparse.urlparse(str(init))
if parsed.scheme in ['http', 'https']:
if 'w' in mode:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions asdf/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def test_open_pathlib_path(tmpdir):
with asdf.AsdfFile(tree) as af:
af.write_to(path)

with asdf.open(tree) as af:
assert af['data'] == tree['data']
with asdf.open(path) as af:
assert (af['data'] == tree['data']).all()


@pytest.mark.skip(reason='Until inline_threshold is added as a write option')
Expand Down

0 comments on commit af67f0f

Please sign in to comment.