Skip to content

Commit

Permalink
Merge pull request #252 from sot/ruff
Browse files Browse the repository at this point in the history
Ruff format and lint and tidy top-level
  • Loading branch information
taldcroft authored Nov 29, 2023
2 parents 9fb8d25 + e6e346d commit 1daa325
Show file tree
Hide file tree
Showing 71 changed files with 218 additions and 145 deletions.
21 changes: 0 additions & 21 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
19 changes: 8 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
language_version: python3.8

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions cheta/add_derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import optparse
import os
import pickle
import re
from pathlib import Path

Expand All @@ -12,11 +13,8 @@
import Ska.DBI
import tables
from Chandra.Time import DateTime
from six.moves import cPickle as pickle

import cheta.derived as derived
import cheta.fetch as fetch
import cheta.file_defs as file_defs
from cheta import derived, fetch, file_defs


def get_options():
Expand Down
4 changes: 2 additions & 2 deletions cheta/check_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import optparse
import os
import pickle
import re

import pyyaks.context
import pyyaks.logger
import Ska.DBI
import tables
from six.moves import cPickle as pickle

import cheta.fetch as fetch
from cheta import fetch

opt = None
ft = fetch.ft
Expand Down
2 changes: 1 addition & 1 deletion cheta/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def acisdeahk(dat):
dat = pyfits_to_recarray(dat)
rows = dat[dat["CCD_ID"] >= 10]
if len(rows) == 0:
raise NoValidDataError()
raise NoValidDataError

# Go through input data one row (query) at a time and assemble contemporaneous
# queries into a single row with a column for each query value.
Expand Down
2 changes: 1 addition & 1 deletion cheta/derived/comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def get_stats_attrs(self, tstart, tstop, msid, match_args, interval):
rows = np.searchsorted(msid_obj.times, times)
vals_stats = calc_stats_vals(msid_obj, rows, indexes, interval)
else:
raise ValueError()
raise ValueError

# Replicate the name munging that fetch does going from the HDF5 columns
# to what is seen in a stats fetch query.
Expand Down
2 changes: 0 additions & 2 deletions cheta/derived/mups_valve.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

"""
Fetch clean MUPS valve temperature telemetry
Expand Down
12 changes: 7 additions & 5 deletions cheta/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
from Chandra.Time import DateTime
from ska_helpers.utils import lru_cache_timed

from . import __version__ # noqa
from . import cache, file_defs, remote_access
from . import (
__version__, # noqa
cache,
file_defs,
remote_access,
)
from .derived.comps import ComputedMsid
from .lazy import LazyDict
from .remote_access import ENG_ARCHIVE
Expand Down Expand Up @@ -504,7 +508,6 @@ def _get_table_intervals_as_list(table, check_overlaps=True):

# Got an intervals list, now sort
if check_overlaps and intervals is not None:

intervals = sorted(intervals, key=lambda x: x[0])

# Check for overlaps
Expand Down Expand Up @@ -2067,7 +2070,6 @@ def get_interval(content, tstart, tstop):
"Getting interval data from " + "DB on Ska eng archive server..."
)
def get_interval_from_db(tstart, tstop, server):

import Ska.DBI

db = Ska.DBI.DBI(dbi="sqlite", server=os.path.join(*server))
Expand Down Expand Up @@ -2192,7 +2194,7 @@ def _plural(x):
"""Return English plural of ``x``. Super-simple and only valid for the
known small set of cases within fetch where it will get applied.
"""
return x + "es" if (x.endswith("x") or x.endswith("s")) else x + "s"
return x + "es" if (x.endswith(("x", "s"))) else x + "s"


def get_data_gap_spec_parser():
Expand Down
6 changes: 4 additions & 2 deletions cheta/fetch_eng.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import sys

from . import __version__ # noqa
from . import fetch
from . import (
__version__, # noqa
fetch,
)
from .fetch import * # noqa

# Module-level units, defaults to CXC units (e.g. Kelvins etc)
Expand Down
6 changes: 4 additions & 2 deletions cheta/fetch_sci.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import sys

from . import __version__ # noqa
from . import fetch
from . import (
__version__, # noqa
fetch,
)
from .fetch import * # noqa

# Module-level units, defaults to CXC units (e.g. Kelvins etc)
Expand Down
3 changes: 1 addition & 2 deletions cheta/fix_bad_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
import tables
from Chandra.Time import DateTime

import cheta.file_defs as file_defs
from cheta import fetch
from cheta import fetch, file_defs

ft = fetch.ft
opt = None
Expand Down
2 changes: 1 addition & 1 deletion cheta/get_telem.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def sanitize_event_expression(expr):
ast.literal_eval(word)
tokens.append("LITERAL")
except Exception:
raise ValueError("Cannot identify word {!r}".format(word))
raise ValueError("Cannot identify word {!r}".format(word)) from None

# Now check syntax and do substitutions where needed
in_arg_list = False
Expand Down
2 changes: 1 addition & 1 deletion cheta/tests/test_comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_quat_comp(msid, maude, offset):
tstart = tstart0 + offset * 8.0
tstop = tstart + 60.0

data_source = ("maude allow_subset=False" if maude else "cxc")
data_source = "maude allow_subset=False" if maude else "cxc"
with fetch_eng.data_source(data_source):
datq = fetch_eng.MSID(f"quat_{msid}", tstart, tstop)
dats = fetch_eng.MSIDset([f"{msid}*"], tstart - 40, tstop + 40)
Expand Down
3 changes: 1 addition & 2 deletions cheta/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import numpy as np

from .. import fetch as fetch_cxc
from .. import fetch_eng as fetch_eng
from .. import fetch_sci as fetch_sci
from .. import fetch_eng, fetch_sci
from ..units import Units

start = "2011:001:00:00:00"
Expand Down
2 changes: 1 addition & 1 deletion cheta/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"""
import logging
import os
import pickle
import warnings

import numpy as np
import pickle


class NullHandler(logging.Handler):
Expand Down
8 changes: 3 additions & 5 deletions cheta/update_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
from Chandra.Time import DateTime
from ska_helpers.retry import tables_open_file

import cheta.converters as converters
import cheta.derived
import cheta.fetch as fetch
import cheta.file_defs as file_defs
from cheta import converters, fetch, file_defs


def get_options(args=None):
Expand Down Expand Up @@ -299,7 +297,7 @@ def main_loop():
try:
Ska.tdb.msids[colname].Tsc["STATE_CODE"]
except Exception:
if not colname.upper() in fetch.STATE_CODES:
if colname.upper() not in fetch.STATE_CODES:
continue

msid = update_stats(colname, "daily")
Expand Down Expand Up @@ -864,7 +862,7 @@ def truncate_archive(filetype, date):
"SELECT rowstart FROM archfiles WHERE year>={0} AND doy>={1}".format(year, doy)
)
if len(out) == 0:
logger.verbose(f"No rows to delete - skipping")
logger.verbose("No rows to delete - skipping")
db.conn.close()
return

Expand Down
9 changes: 3 additions & 6 deletions cheta/update_client_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ def get_options(args=None):
class RowMismatchError(ValueError):
"""Exception for row mismatch between existing archive and available sync update"""

pass


@contextlib.contextmanager
def timing_logger(logger, text, level_pre="info", level_post="info"):
Expand Down Expand Up @@ -344,7 +342,7 @@ def get_copy_files(logger, msids, msids_content):
f"Found {len(copy_files)} local archive files that are "
"missing and need to be copied"
)
logger.debug(f"Copy_files:")
logger.debug("Copy_files:")
for copy_file in sorted(copy_files):
logger.debug(copy_file)

Expand Down Expand Up @@ -540,7 +538,6 @@ def get_full_data_sets(ft, index_tbl, logger, opt):
# Iterate over sync files that contain new data
dats = []
for row in index_tbl:

# Limit processed archfiles by date
if row["filetime0"] > DateTime(opt.date_stop).secs:
break
Expand Down Expand Up @@ -587,7 +584,7 @@ def sync_stat_archive(opt, msid_files, logger, content, stat, index_tbl):
)
logger.warn(msg)
logger.warn(
f"Attempting to fix by removing that file and trying to sync again."
"Attempting to fix by removing that file and trying to sync again."
)
pth.unlink()
_sync_stat_archive(opt, msid_files, logger, content, stat, index_tbl)
Expand Down Expand Up @@ -814,7 +811,7 @@ def get_last_date_id(msid_files, msids, stat, logger):
with open(last_date_id_file, "r") as fh:
last_date_id = fh.read()
else:
logger.verbose(f"Reading stat h5 files to get last update time")
logger.verbose("Reading stat h5 files to get last update time")
times = []
for msid in msids:
fetch.ft["msid"] = msid
Expand Down
2 changes: 1 addition & 1 deletion cheta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def get_telem_table(
:returns: Table of requested telemetry values from fetch
"""
from cheta import fetch_eng, fetch_sci, fetch
from cheta import fetch, fetch_eng, fetch_sci

start = CxoTime(start)
stop = CxoTime(stop)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1daa325

Please sign in to comment.