diff --git a/.travis.yml b/.travis.yml index 4c34343..9e48e67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ matrix: env: TOXENV=codestyle - python: 3.8 env: TOXENV=docstyle + - python: 3.8 + env: TOXENV=mypy - python: 3.8 env: TOXENV=py38 - python: 3.7 @@ -34,6 +36,9 @@ matrix: - python: 3.8 arch: ppc64le env: TOXENV=docstyle + - python: 3.8 + arch: ppc64le + env: TOXENV=mypy - python: 3.8 arch: ppc64le env: TOXENV=py38 @@ -55,12 +60,6 @@ matrix: - arch: ppc64le python: pypy3 -before_install: - - | - if [[ "$TRAVIS_CPU_ARCH" == "ppc64le" ]]; then - sudo chown -Rv $USER:$GROUP ~/.cache/pip/wheels - fi - install: - pip install tox - if [[ "$TRAVIS_CPU_ARCH" == "ppc64le" ]]; then pip install pytest; pip install astropy; fi diff --git a/MANIFEST.in b/MANIFEST.in index c30aef0..94204e2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include README.rst include LICENSE.txt -include *jdcal.py +include src/jdcal/*.py +include src/jdcal/py.typed diff --git a/setup.py b/setup.py index eade07b..2520dd5 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,16 @@ #!/usr/bin/env python -from setuptools import setup +from setuptools import setup, find_packages -import jdcal - -version = jdcal.__version__ long_description = open("README.rst").read() +with open("src/jdcal/version.py") as f: + exec(f.read()) + setup( name="jdcal", - version=version, + version=__version__, description="Julian dates from proleptic Gregorian and Julian calendars.", long_description=long_description, license='BSD', @@ -35,5 +35,9 @@ 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], - py_modules=["jdcal"] + # py_modules=["jdcal"], + packages=find_packages("src"), + package_dir={"": "src"}, + install_requires=["typing;python_version<'3.5'"], + include_package_data=True, ) diff --git a/src/jdcal/__init__.py b/src/jdcal/__init__.py new file mode 100644 index 0000000..2667a23 --- /dev/null +++ b/src/jdcal/__init__.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# see https://mypy.readthedocs.io/en/latest/config_file.html#confval-implicit_reexport +from .version import __version__ as __version__ +from .jdcal import ( + MJD_0 as MJD_0, + MJD_JD2000 as MJD_JD2000, + is_leap as is_leap, + gcal2jd as gcal2jd, + jd2gcal as jd2gcal, + jcal2jd as jcal2jd, + jd2jcal as jd2jcal, +) diff --git a/jdcal.py b/src/jdcal/jdcal.py similarity index 96% rename from jdcal.py rename to src/jdcal/jdcal.py index cb1661c..4d3ac37 100644 --- a/jdcal.py +++ b/src/jdcal/jdcal.py @@ -41,14 +41,14 @@ from __future__ import division from __future__ import print_function import math +from typing import Tuple -__version__ = "1.4.1" MJD_0 = 2400000.5 MJD_JD2000 = 51544.5 -def is_leap(year): +def is_leap(year): # type: (int) -> int """Leap year or not in the Gregorian calendar.""" x = year % 4 y = year % 100 @@ -59,7 +59,7 @@ def is_leap(year): return not x and (y or not z) -def gcal2jd(year, month, day): +def gcal2jd(year, month, day): # type: (int, int, int) -> Tuple[float, float] """Gregorian calendar date to Julian date. The input and output are for the proleptic Gregorian calendar, @@ -179,7 +179,7 @@ def gcal2jd(year, month, day): day = int(day) a = int((month - 14) / 12.0) - jd = int((1461 * (year + 4800 + a)) / 4.0) + jd = int((1461 * (year + 4800 + a)) / 4.0) # type: float jd += int((367 * (month - 2 - 12 * a)) / 12.0) x = int((year + 4900 + a) / 100.0) jd -= int((3 * x) / 4.0) @@ -190,7 +190,7 @@ def gcal2jd(year, month, day): return MJD_0, jd -def jd2gcal(jd1, jd2): +def jd2gcal(jd1, jd2): # type: (float, float) -> Tuple[int, int, int, float] """Julian date to Gregorian calendar date and time of day. The input and output are for the proleptic Gregorian calendar, @@ -289,7 +289,7 @@ def jd2gcal(jd1, jd2): return int(year), int(month), int(day), f -def jcal2jd(year, month, day): +def jcal2jd(year, month, day): # type: (int, int, int) -> Tuple[float, float] """Julian calendar date to Julian date. The input and output are for the proleptic Julian calendar, @@ -344,7 +344,7 @@ def jcal2jd(year, month, day): month = int(month) day = int(day) - jd = 367 * year + jd = 367 * year # type: float x = int((month - 9) / 7.0) jd -= int((7 * (year + 5001 + x)) / 4.0) jd += int((275 * month) / 9.0) @@ -356,7 +356,7 @@ def jcal2jd(year, month, day): return MJD_0, jd -def jd2jcal(jd1, jd2): +def jd2jcal(jd1, jd2): # type: (float, float) -> Tuple[int, int, int, float] """Julian calendar date for the given Julian date. The input and output are for the proleptic Julian calendar, diff --git a/src/jdcal/py.typed b/src/jdcal/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/jdcal/version.py b/src/jdcal/version.py new file mode 100644 index 0000000..afbd696 --- /dev/null +++ b/src/jdcal/version.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +__version__ = "1.4.1" diff --git a/test_jdcal.py b/tests/test_jdcal.py similarity index 100% rename from test_jdcal.py rename to tests/test_jdcal.py diff --git a/tox.ini b/tox.ini index 9e4d1cf..ab3ab32 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] project = jdcal -envlist = py{27,34,35,36,37,38,py,py3}, codestyle, docstyle +envlist = py{27,34,35,36,37,38,py,py3}, codestyle, docstyle, mypy [testenv] deps = pytest @@ -13,8 +13,12 @@ deps = [testenv:codestyle] deps = pycodestyle -commands = pycodestyle --ignore=E722,E501 jdcal.py test_jdcal.py +commands = pycodestyle --ignore=E722,E501 src/jdcal/jdcal.py tests/test_jdcal.py [testenv:docstyle] deps = pydocstyle -commands = pydocstyle jdcal.py test_jdcal.py +commands = pydocstyle src/jdcal/jdcal.py + +[testenv:mypy] +deps = mypy +commands = mypy --strict src/jdcal/jdcal.py