Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include README.rst
include LICENSE.txt
include *jdcal.py
include src/jdcal/*.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be included automatically by setuptools. We only need to mention the test files:

Suggested change
include src/jdcal/*.py
include tests/*.py

include src/jdcal/py.typed
16 changes: 10 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -35,5 +35,9 @@
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
py_modules=["jdcal"]
# py_modules=["jdcal"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to keep this.

Suggested change
# py_modules=["jdcal"],

packages=find_packages("src"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the package has no subpackages, find_packages is overkill, IMO:

Suggested change
packages=find_packages("src"),
packages=["jdcal"],

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't some of these suggestions change since we have decided to go with the latest recommendation
of using setup.cfg to specify such information and keeping setup.py to the minimum?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adjusting setup.cfg there will be a choice of using find_packages or listing the packages. IMO, listing them is better as the layout is relatively simple. So I think the comment still applies, but just to the new declarative syntax.

package_dir={"": "src"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also mention the package_data here:

Suggested change
package_dir={"": "src"},
package_data={"jdcal": ["py.typed"]},
package_dir={"": "src"},

install_requires=["typing;python_version<'3.5'"],
include_package_data=True,
)
14 changes: 14 additions & 0 deletions src/jdcal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is a package and has no external side effects, it should not be executable as is.

Suggested change
#!/usr/bin/env python

# -*- coding: utf-8 -*-

# see https://mypy.readthedocs.io/en/latest/config_file.html#confval-implicit_reexport
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it is more conventional to express exports using __all__

__all__ = ["__version__", "MJD_0", ...]

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,
)
16 changes: 8 additions & 8 deletions jdcal.py → src/jdcal/jdcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Empty file added src/jdcal/py.typed
Empty file.
4 changes: 4 additions & 0 deletions src/jdcal/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#!/usr/bin/env python

# -*- coding: utf-8 -*-

__version__ = "1.4.1"
File renamed without changes.
10 changes: 7 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run on entire directory.


[testenv:docstyle]
deps = pydocstyle
commands = pydocstyle jdcal.py test_jdcal.py
commands = pydocstyle src/jdcal/jdcal.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, run on full package.


[testenv:mypy]
deps = mypy
commands = mypy --strict src/jdcal/jdcal.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should type check the entire package, not just one file.

Suggested change
commands = mypy --strict src/jdcal/jdcal.py
commands = mypy --strict src/