Skip to content

Commit

Permalink
Merge pull request #136 from dstansby/resolve-paths
Browse files Browse the repository at this point in the history
Make sure paths are resolved properley
  • Loading branch information
dstansby committed Feb 18, 2022
2 parents 31f95d4 + ded48c5 commit d1e9b6e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
10 changes: 5 additions & 5 deletions cdflib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pathlib import Path

from . import cdfread, cdfwrite
from .epochs import CDFepoch as cdfepoch # noqa: F401

from pathlib import Path

# This function determines if we are reading or writing a file


def CDF(path, cdf_spec=None, delete=False, validate=None, string_encoding='ascii'):
path = Path(path).expanduser()
path = Path(path).resolve().expanduser()

if path.is_file():
if delete:
Expand All @@ -19,8 +19,8 @@ def CDF(path, cdf_spec=None, delete=False, validate=None, string_encoding='ascii
return cdfwrite.CDF(path, cdf_spec=cdf_spec, delete=delete)

try:
from .epochs_astropy import CDFAstropy as cdfastropy
from .cdf_to_xarray import cdf_to_xarray
from .epochs_astropy import CDFAstropy as cdfastropy
from .xarray_to_cdf import xarray_to_cdf
except Exception:
pass
pass
2 changes: 1 addition & 1 deletion cdflib/cdfread.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CDF:

def __init__(self, path, validate=False, string_encoding='ascii'):

path = Path(path).expanduser()
path = Path(path).resolve().expanduser()
if not path.is_file():
path = path.with_suffix('.cdf')
if not path.is_file():
Expand Down
11 changes: 3 additions & 8 deletions tests/test_cdfread.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import os
import urllib.request
import pathlib

import cdflib


def test_read():
fname = 'helios.cdf'
url = ("http://helios-data.ssl.berkeley.edu/data/"
"E1_experiment/New_proton_corefit_data_2017/"
"cdf/helios1/1974/h1_1974_346_corefit.cdf")
if not os.path.exists(fname):
urllib.request.urlretrieve(url, fname)
fname = (pathlib.Path(__file__) / '..' / 'testfiles' /
'psp_fld_l2_mag_rtn_1min_20200104_v02.cdf')
cdflib.CDF(fname)
Binary file not shown.

0 comments on commit d1e9b6e

Please sign in to comment.