Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff format and linting #395

Merged
merged 3 commits into from
Mar 14, 2024
Merged
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
10 changes: 0 additions & 10 deletions .github/workflows/black.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.3.2
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
12 changes: 4 additions & 8 deletions proseco/acq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
Expand Down Expand Up @@ -674,9 +673,7 @@ def select_best_p_acqs(self, cand_acqs, min_p_acq, acq_indices, box_sizes):
self.log(f"Trying search box size {box_size} arcsec", level=1)

if np.all(p_acqs_for_box < min_p_acq):
self.log(
f"No acceptable candidates (probably small man angle)", level=2
)
self.log("No acceptable candidates (probably small man angle)", level=2)
continue

indices = np.argsort(-p_acqs_for_box, kind="mergesort")
Expand Down Expand Up @@ -755,7 +752,7 @@ def get_initial_catalog(self):

# This should never happen but be careful
if len(acq_indices) != n_include:
raise RuntimeError(f"failure in force-include")
raise RuntimeError("failure in force-include")

# For include stars where the halfw is not going to be optimized
# then then override the box size that was just found with the
Expand Down Expand Up @@ -1352,10 +1349,9 @@ def get_intruders(acq, box_size, name, n_sigma, get_func, kwargs):
intruders = intruders[ok]
acq[name] = intruders

else:
elif box_size > acq[name_box]:
# Ensure cached spoilers cover the current case.
if box_size > acq[name_box]:
raise ValueError(f"box_size is greater than {name_box}")
raise ValueError(f"box_size is greater than {name_box}")

colnames = ["yang", "zang", "mag", "mag_err"]
if len(intruders) == 0:
Expand Down
9 changes: 4 additions & 5 deletions proseco/catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import copy
Expand Down Expand Up @@ -630,8 +629,8 @@ def add(self, value, descending=False):
if self[slot]["type"] is None:
self[slot] = value
return slot
else:
raise IndexError("catalog is full")

raise IndexError("catalog is full")

def as_table(self):
colnames = list(ACA_CATALOG_DTYPES)
Expand Down Expand Up @@ -818,7 +817,7 @@ def merge_cats(fids=None, guides=None, acqs=None, mons=None):
# Fids
for guide in cat_guides:
if guide["type"] == "FID":
rows.append(guide[colnames])
rows.append(guide[colnames]) # noqa: PERF401

# Add BOT stars
for guide, acq in zip(cat_guides, cat_acqs):
Expand All @@ -835,7 +834,7 @@ def merge_cats(fids=None, guides=None, acqs=None, mons=None):
# Monitor stars
for guide in cat_guides:
if guide["type"] in ("MTR", "MFX"):
rows.append(guide[colnames])
rows.append(guide[colnames]) # noqa: PERF401

# Acq only
for guide, acq in zip(cat_guides, cat_acqs):
Expand Down
17 changes: 8 additions & 9 deletions proseco/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import functools
Expand Down Expand Up @@ -669,9 +668,9 @@ def dark(self, value):
# Set pixel regions from ACA.bad_pixels to have acqs.dark=700000 (5.0 mag
# star) per pixel.
for r0, r1, c0, c1 in ACA.bad_pixels:
self._dark[
r0 + 512 : r1 + 513, c0 + 512 : c1 + 513
] = ACA.bad_pixel_dark_current
self._dark[r0 + 512 : r1 + 513, c0 + 512 : c1 + 513] = (
ACA.bad_pixel_dark_current
)

def set_attrs_from_kwargs(self, **kwargs):
for name, val in kwargs.items():
Expand Down Expand Up @@ -825,11 +824,11 @@ def dither(self, value):
@property
def t_ccd(self):
# Subclasses must implement.
raise NotImplementedError()
raise NotImplementedError

@t_ccd.setter
def t_ccd(self, value):
raise NotImplementedError()
raise NotImplementedError

@classmethod
def empty(cls):
Expand Down Expand Up @@ -1137,7 +1136,7 @@ def get_logger(logger):
return logger
else:

def null_logger(*args, **kwargs):
def null_logger(*args, **kwargs): # noqa: ARG001
pass

return null_logger
Expand Down Expand Up @@ -1257,7 +1256,7 @@ def from_stars(cls, att, stars, logger=None, copy=True) -> "StarsTable":
stars = cls(stars, copy=copy)
stars.att = att

logger(f"Updating star columns for attitude and convenience")
logger("Updating star columns for attitude and convenience")

stars.meta["q_att"] = q_att
yag, zag = radec_to_yagzag(stars["RA_PMCORR"], stars["DEC_PMCORR"], q_att)
Expand Down Expand Up @@ -1666,7 +1665,7 @@ def get_image_props(ccd_img, c_row, c_col, bgd=None):
return img, img_sum, mag, row, col


def pea_reject_image(img):
def pea_reject_image(img): # noqa: ARG001
"""
Check if PEA would reject image (too narrow, too peaky, etc)
"""
Expand Down
3 changes: 1 addition & 2 deletions proseco/diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import difflib
Expand Down Expand Up @@ -134,7 +133,7 @@ def get_catalog_lines(
for name in out.colnames:
col = out[name]
if col.dtype.kind == "O":
col[col == None] = 0 # noqa
col[col == None] = 0 # noqa: E711
out[name] = col.tolist()

# Allow specifying custom formats. For instance starcheck uses 3 digits for
Expand Down
1 change: 0 additions & 1 deletion proseco/fid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
Expand Down
13 changes: 6 additions & 7 deletions proseco/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ def process_monitors_pre(self):
dr = int(4 + np.ceil(self.dither.row if is_track else 0))
dc = int(4 + np.ceil(self.dither.col if is_track else 0))
row, col = int(monitor["row"]) + 512, int(monitor["col"]) + 512
self.dark[
row - dr : row + dr, col - dc : col + dc
] = ACA.bad_pixel_dark_current # noqa
self.dark[row - dr : row + dr, col - dc : col + dc] = (
ACA.bad_pixel_dark_current
)

# Reduce n_guide for each MON. On input the n_guide arg is the
# number of GUI + MON, but for guide selection we need to make the
Expand Down Expand Up @@ -417,10 +417,9 @@ def index_combinations(n, m):
tried_combinations=n_tries,
)
return cands
else:
if n_pass not in select_results:
# Keep a copy of the first cands table with n_pass passing tests
select_results[n_pass] = cands
elif n_pass not in select_results:
# Keep a copy of the first cands table with n_pass passing tests
select_results[n_pass] = cands

# Return the catalog with the maximum n_pass key value
max_n_pass = max(select_results)
Expand Down
5 changes: 2 additions & 3 deletions proseco/report_acq.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from copy import copy, deepcopy
from pathlib import Path

import matplotlib

matplotlib.use("agg") # noqa
matplotlib.use("agg")
import matplotlib.pyplot as plt
import numpy as np
from astropy.table import Column, Table
Expand Down Expand Up @@ -290,7 +289,7 @@ def make_optimize_catalog_report(events, context):
)


def make_obsid_summary(acqs, events, context, obsdir):
def make_obsid_summary(acqs, events, context, obsdir): # noqa: ARG001
acqs_table = acqs[ACQ_COLS]
acqs_table["id"] = [
'<a href="#{0}">{0}</a>'.format(acq["id"]) for acq in acqs_table
Expand Down
5 changes: 2 additions & 3 deletions proseco/report_guide.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: utf-8
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from copy import copy
from pathlib import Path

import matplotlib

matplotlib.use("agg") # noqa
matplotlib.use("agg")

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -144,7 +143,7 @@ def make_cand_report(guides, cand_guides, context, obsdir):
log = reject_info_to_report(guide["id"], guides.reject_info)
if guide["stage"] != -1:
if guide["stage"] == 0:
log.append(f"FORCE Selected in stage 0")
log.append("FORCE Selected in stage 0")
else:
log.append(f"Selected in stage {guide['stage']}")
if guide["id"] not in guides["id"]:
Expand Down
2 changes: 1 addition & 1 deletion proseco/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import agasc
import pytest
from agasc import get_agasc_filename


Expand Down
3 changes: 2 additions & 1 deletion proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ def test_dark_date_warning():
# Fudge date forward, after the 2018:002 dark cal
acap.date = "2018:010"
with pytest.warns(UserWarning) as warns:
acap.dark # Accessing the `dark` property triggers code to read it (and warn)
# Accessing the `dark` property triggers code to read it (and warn)
acap.dark # noqa: B018

assert len(warns) == 1
assert "Unexpected dark_date: dark_id nearest dark_date" in str(warns[0].message)
Expand Down
3 changes: 1 addition & 2 deletions proseco/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import pickle
from pathlib import Path

import agasc
import numpy as np
Expand Down Expand Up @@ -136,7 +135,7 @@ def test_box_greater():
assert box1 > (10, 14.9)

assert not box1 > (10, 15)
assert not box1 > box1
assert not box1 > box1 # noqa:PLR0124
assert not box1 > (11, 16)


Expand Down
6 changes: 3 additions & 3 deletions proseco/tests/test_fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_fids_include_exclude():
dark=DARK40,
**STD_INFO,
include_ids=include_ids,
exclude_ids=exclude_ids
exclude_ids=exclude_ids,
)

assert fids.include_ids == include_ids
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_fids_include_bad():
dark=DARK40,
**STD_INFO,
include_ids=include_ids,
exclude_ids=exclude_ids
exclude_ids=exclude_ids,
)

# Set up a scenario with large offset so only two are on the CCD
Expand All @@ -369,7 +369,7 @@ def test_fids_include_bad():
fids = get_fid_catalog(
**mod_std_info(stars=StarsTable.empty(), sim_offset=80000),
include_ids=include_ids,
exclude_ids=exclude_ids
exclude_ids=exclude_ids,
)

assert np.all(fids["id"] == [1, 2, 4])
Expand Down
20 changes: 0 additions & 20 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