Skip to content

Commit

Permalink
Merge pull request #41 from sot/ruff-redux
Browse files Browse the repository at this point in the history
Ruff format and linting
  • Loading branch information
taldcroft authored Nov 29, 2023
2 parents 9a1f951 + feddafb commit cfcc413
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 146 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/black.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/flake8.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/workflows/python-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: check format using ruff
on: [push]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
args: format --check
8 changes: 8 additions & 0 deletions .github/workflows/python-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: lint code using ruff
on: [push]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
20 changes: 8 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
language_version: python3.10
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
8 changes: 4 additions & 4 deletions cxotime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import ska_helpers
from astropy import units # noqa
from astropy.time import TimeDelta # noqa
from astropy import units
from astropy.time import TimeDelta

from .convert import * # noqa
from .cxotime import CxoTime, CxoTimeLike # noqa: F401
from .convert import *
from .cxotime import CxoTime, CxoTimeLike

__version__ = ska_helpers.get_version(__package__)

Expand Down
9 changes: 6 additions & 3 deletions cxotime/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ def make_docstring(fmt_in, fmt_out):
doc_in = fmt_in_cls.convert_doc
fmt_out_cls = TIME_FORMATS[fmt_out]
doc_out = fmt_out_cls.convert_doc
equiv = f"CxoTime({doc_in['input_name']}, format='{fmt_in_cls.name}').{fmt_out_cls.name}"
equiv = (
f"CxoTime({doc_in['input_name']},"
f" format='{fmt_in_cls.name}').{fmt_out_cls.name}"
)
out = f"""\
Convert {doc_in['descr_short']} to {doc_out['descr_short']}.
Expand Down Expand Up @@ -329,6 +332,6 @@ def make_docstring(fmt_in, fmt_out):
f"lambda {input_name}: "
f"convert_time_format({input_name}, fmt_in='{fmt1}', fmt_out='{fmt2}')"
)
func = globals()[name] = eval(func_str)
func = globals()[name] = eval(func_str) # noqa: PGH001
func.__doc__ = make_docstring(fmt1, fmt2)
__all__.append(name)
__all__.append(name) # noqa: PYI056
137 changes: 68 additions & 69 deletions cxotime/cxotime.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,33 +246,33 @@ def get_conversions(self):
return out


TimeJD.convert_doc = dict(
input_name="jd",
descr_short="Julian Date",
input_format="Julian Date (numeric)",
output_format="Julian Date (numeric)",
input_type="float, int, list, ndarray",
output_type="float, ndarray[float]",
)
TimeJD.convert_doc = {
"input_name": "jd",
"descr_short": "Julian Date",
"input_format": "Julian Date (numeric)",
"output_format": "Julian Date (numeric)",
"input_type": "float, int, list, ndarray",
"output_type": "float, ndarray[float]",
}


class TimeSecs(TimeCxcSec):
"""
Chandra X-ray Center seconds from 1998-01-01 00:00:00 TT.
"""Chandra X-ray Center seconds from 1998-01-01 00:00:00 TT.
For example, 63072064.184 is midnight on January 1, 2000.
"""

name = "secs"

# Documentation inputs for convert functions
convert_doc = dict(
input_name="time",
descr_short="CXC seconds",
input_format="CXC seconds (numeric)",
output_format="CXC seconds (numeric)",
input_type="float, int, list, ndarray",
output_type="float, ndarray[float]",
)
convert_doc = {
"input_name": "time",
"descr_short": "CXC seconds",
"input_format": "CXC seconds (numeric)",
"output_format": "CXC seconds (numeric)",
"input_type": "float, int, list, ndarray",
"output_type": "float, ndarray[float]",
}


class TimeDate(TimeYearDayTime):
Expand Down Expand Up @@ -301,18 +301,18 @@ class TimeDate(TimeYearDayTime):
name = "date"

# Documentation inputs for convert functions
convert_doc = dict(
input_name="date",
descr_short="Date (Year, day-of-year, time)",
input_format="""
convert_doc = {
"input_name": "date",
"descr_short": "Date (Year, day-of-year, time)",
"input_format": """
- YYYY:DDD:HH:MM:SS.sss
- YYYY:DDD:HH:MM:SS
- YYYY:DDD:HH:MM
- YYYY:DDD""",
output_format="YYYY:DDD:HH:MM:SS.sss",
input_type="str, bytes, float, list, ndarray",
output_type="str, ndarray[str]",
)
"output_format": "YYYY:DDD:HH:MM:SS.sss",
"input_type": "str, bytes, float, list, ndarray",
"output_type": "str, ndarray[str]",
}

def to_value(self, parent=None, **kwargs):
if self.scale == "utc":
Expand All @@ -330,10 +330,10 @@ def set_jds(self, val1, val2):


class TimeFracYear(TimeDecimalYear):
"""
Time as a decimal year, with integer values corresponding to midnight
of the first day of each year. For example 2000.5 corresponds to the
ISO time '2000-07-02 00:00:00'.
"""Time as a decimal year.
Integer values corresponding to midnight of the first day of each year. For example
2000.5 corresponds to the ISO time '2000-07-02 00:00:00'.
Time value is always in UTC regardless of time object scale.
"""
Expand All @@ -350,27 +350,26 @@ def to_value(self, parent=None, **kwargs):


class TimeGreta(TimeDate):
"""
Date as a string in format 'YYYYDDD.hhmmsssss', where sssss is number of
milliseconds.
"""Date as string in format 'YYYYDDD.hhmmsssss'.
This can be input as a float, integer or string, but the output is always
string.
Here sssss is the number of millisec.
This can be input as a float, integer or string, but the output is always string.
Time value is always in UTC regardless of time object scale.
"""

name = "greta"

# Documentation inputs for convert functions
convert_doc = dict(
input_name="date",
descr_short="GRETA date",
input_format="YYYYDDD.HHMMSSsss (str or float)",
output_format="YYYYDDD.HHMMSSsss (str)",
input_type="str, bytes, float, list, np.ndarray",
output_type="str, np.ndarray[str]",
)
convert_doc = {
"input_name": "date",
"descr_short": "GRETA date",
"input_format": "YYYYDDD.HHMMSSsss (str or float)",
"output_format": "YYYYDDD.HHMMSSsss (str)",
"input_type": "str, bytes, float, list, np.ndarray",
"output_type": "str, np.ndarray[str]",
}

subfmts = (
("date_hms", "%Y%j%H%M%S", "{year:d}{yday:03d}{hour:02d}{min:02d}{sec:02d}"),
Expand All @@ -391,14 +390,14 @@ class TimeGreta(TimeDate):

# Before: yr mon doy hour minute second frac

fast_parser_pars = dict(
delims=(0, 0, 0, ord("."), 0, 0, 0),
starts=(0, -1, 4, 7, 10, 12, 14),
stops=(3, -1, 6, 9, 11, 13, -1),
fast_parser_pars = {
"delims": (0, 0, 0, ord("."), 0, 0, 0),
"starts": (0, -1, 4, 7, 10, 12, 14),
"stops": (3, -1, 6, 9, 11, 13, -1),
# Break before: y m d h m s f
break_allowed=(0, 0, 0, 1, 0, 1, 1),
has_day_of_year=1,
)
"break_allowed": (0, 0, 0, 1, 0, 1, 1),
"has_day_of_year": 1,
}

def _check_val_type(self, val1, val2):
if val2 is not None:
Expand Down Expand Up @@ -427,24 +426,24 @@ def to_value(self, parent=None, **kwargs):


class TimeMaude(TimeDate):
"""
Date as a 64-bit integer in format YYYYDDDHHMMSSsss, where sss is number of
milliseconds.
"""Date as a 64-bit integer in format YYYYDDDHHMMSSsss.
Here sss is number of milliseconds.
This can be input as an integer or string, but the output is always integer.
Time value is always in UTC regardless of time object scale.
"""

name = "maude"
convert_doc = dict(
input_name="date",
descr_short="MAUDE date",
input_format="YYYYDDDHHMMSSsss (str or int)",
output_format="YYYYDDD.HHMMSSsss (int)",
input_type="str, bytes, int, list, ndarray",
output_type="int, ndarray[int]",
)
convert_doc = {
"input_name": "date",
"descr_short": "MAUDE date",
"input_format": "YYYYDDDHHMMSSsss (str or int)",
"output_format": "YYYYDDD.HHMMSSsss (int)",
"input_type": "str, bytes, int, list, ndarray",
"output_type": "int, ndarray[int]",
}

subfmts = (
("date_hms", "%Y%j%H%M%S", "{year:d}{yday:03d}{hour:02d}{min:02d}{sec:02d}"),
Expand All @@ -464,15 +463,15 @@ class TimeMaude(TimeDate):
# stops: position where component ends (-1 => continue to end of string)

# Before: yr mon doy hour minute second frac
fast_parser_pars = dict(
use_fast_parser=True,
delims=(0, 0, 0, 0, 0, 0, 0),
starts=(0, -1, 4, 7, 9, 11, 13),
stops=(3, -1, 6, 8, 10, 12, -1),
fast_parser_pars = {
"use_fast_parser": True,
"delims": (0, 0, 0, 0, 0, 0, 0),
"starts": (0, -1, 4, 7, 9, 11, 13),
"stops": (3, -1, 6, 8, 10, 12, -1),
# Break before: y m d h m s f,
break_allowed=(0, 0, 0, 1, 0, 1, 1),
has_day_of_year=1,
)
"break_allowed": (0, 0, 0, 1, 0, 1, 1),
"has_day_of_year": 1,
}

def _check_val_type(self, val1, val2):
if val2 is not None:
Expand Down
9 changes: 7 additions & 2 deletions cxotime/tests/test_cxotime.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ def test_cxotime_vs_datetime():
np.array(["2000:001", "2015:181:23:59:60.500", "2015:180:01:02:03.456"])
).secs
dts = DateTime(secs)
vals = dict(date=dts.date, secs=dts.secs, greta=dts.greta, frac_year=dts.frac_year)
vals = {
"date": dts.date,
"secs": dts.secs,
"greta": dts.greta,
"frac_year": dts.frac_year,
}

fmts = list(vals.keys())
for in_fmt in fmts:
Expand Down Expand Up @@ -396,7 +401,7 @@ def test_print_time_conversions(date):
("iso", "2001-01-01 02:03:04.123", "U"),
]

test_fmts = set([fmt_name for fmt_name, val, fmt_kind in inputs])
test_fmts = {fmt_name for fmt_name, val, fmt_kind in inputs}


@pytest.mark.parametrize("fmt_val", inputs)
Expand Down
27 changes: 0 additions & 27 deletions pyproject.toml

This file was deleted.

8 changes: 8 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ignore": [
"**/node_modules",
"**/__pycache__",
"**/*.ipynb",
".git"
]
}
Loading

0 comments on commit cfcc413

Please sign in to comment.