Skip to content

Commit

Permalink
Merge pull request #217 from Unidata/import_error
Browse files Browse the repository at this point in the history
print more informative error msg when importing from install dir
  • Loading branch information
jswhit committed Dec 27, 2020
2 parents e8d921b + c2992b4 commit fa34366
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -3,6 +3,7 @@
#

[run]
relative_files = True
branch = True
plugins = Cython.Coverage
include =
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/miniconda.yml
Expand Up @@ -51,11 +51,13 @@ jobs:
py.test -vv test
find ./ -name "*cov*" -print # check for coverage output
# - name: Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# path-to-lcov: ${{ github.workspace }}/coverage/lcov.info
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(matrix.os,'ubuntu')
run: |
source activate TEST
coveralls
- name: Tarball
if: startsWith(matrix.os,'ubuntu')
Expand Down
9 changes: 7 additions & 2 deletions Changelog
@@ -1,7 +1,12 @@
version 1.3.1 (not yet released)
================================
* fix for issue #211 (bug in masked array handling in date2num)
* switch from travis/appveyor to github actions for CI/CD.
* fix for issue #211 (PR #212) bug in masked array handling in date2num)
* switch from travis/appveyor to github actions for CI/CD (PR #215).
* PR #217:
- print more informative error message if trying to import from install dir.
- switch to cython language_level=3 (no more support for python 2)
- add __init__.py to test dir so pytest coverage works again. Add Coveralls
step to github actions workflow to upload coverage data to coveralls.io.

version 1.3.0 (release tag v1.3.0rel)
=====================================
Expand Down
21 changes: 17 additions & 4 deletions cftime/__init__.py
@@ -1,9 +1,22 @@
# When importing from the root of the unpacked tarball or git checkout,
# Python sees the "cftime" source directory and tries to load it, which fails.
# (unless the package was built using "python setup.py build_ext --inplace"
# so that _cftime.so exists in the cftime source dir).
try:
# init for cftime package
from ._cftime import datetime
except ImportError:
import os.path as _op
if _op.exists(_op.join(_op.dirname(__file__), '..', 'setup.py')):
msg="You cannot import cftime from inside the install directory.\nChange to another directory first."
raise ImportError(msg)
else:
raise
from ._cftime import utime, JulianDayFromDate, DateFromJulianDay, UNIT_CONVERSION_FACTORS
from ._cftime import _parse_date, date2index, time2index
from ._cftime import datetime, real_datetime
from ._cftime import _parse_date, date2index, time2index, real_datetime
from ._cftime import DatetimeNoLeap, DatetimeAllLeap, Datetime360Day, DatetimeJulian, \
DatetimeGregorian, DatetimeProlepticGregorian
DatetimeGregorian, DatetimeProlepticGregorian
from ._cftime import microsec_units, millisec_units, \
sec_units, hr_units, day_units, min_units
sec_units, hr_units, day_units, min_units
from ._cftime import num2date, date2num, date2index, num2pydate
from ._cftime import __version__
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -95,7 +95,7 @@ def description():
if cythonize:
ext_modules = cythonize(extension,
compiler_directives=COMPILER_DIRECTIVES,
language_level=2)
language_level=3)

setup(
name=NAME,
Expand Down
Empty file added test/__init__.py
Empty file.

0 comments on commit fa34366

Please sign in to comment.