Skip to content

Commit

Permalink
update linter to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
yymao committed Jan 18, 2024
1 parent 06349c5 commit 1f92566
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 29 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/python-ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install wheel
- name: Lint with flake8
uses: py-actions/flake8@v2
with:
args: "--extend-ignore=F401,F403,B023"
max-line-length: "149"
plugins: "flake8-bugbear"
- name: Lint with ruff
- uses: chartboost/ruff-action@v1
- name: Install SAGA
run: |
pip install .[full]
Expand Down
6 changes: 0 additions & 6 deletions SAGA/database/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
from ..utils import makedirs_if_needed
from ..version import __version__

try:
FileExistsError
except NameError:
FileExistsError = OSError


# Hot fix on ECSV_DATATYPES for newer astropy versions
if hasattr(ecsv, "ECSV_DATATYPES") and "object" not in ecsv.ECSV_DATATYPES:
ecsv.ECSV_DATATYPES = ecsv.ECSV_DATATYPES + ("object",)
Expand Down
8 changes: 3 additions & 5 deletions SAGA/database/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@

# fix astropy six
try:
import astropy.extern.six
import astropy.extern.six # noqa: F401
except ImportError:
import sys

import six

sys.modules["astropy.extern.six"] = six

_HAS_DATALAB_ = True
Expand Down Expand Up @@ -624,8 +622,8 @@ def __init__(
except ValueError:
try:
dr_number = int(decals_dr[2])
except ValueError:
raise ValueError("Cannot recognize `decals_dr` specification:", decals_dr)
except ValueError as e:
raise ValueError("Cannot recognize `decals_dr` specification:", decals_dr) from e

if dr_number not in (6, 7, 8, 9):
raise ValueError("{} not supported".format(decals_dr))
Expand Down
4 changes: 2 additions & 2 deletions SAGA/objects/build2.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def prepare_des_catalog_for_merging(catalog, to_remove=None, to_recover=None, co
catalog.rename_column("ra", "RA")
catalog.rename_column("dec", "DEC")
catalog.rename_column("objid", "OBJID")
except KeyError:
except KeyError as e:
if not all((col in catalog.colnames for col in ("RA", "DEC", "OBJID"))):
raise RuntimeError("Cannot rename `RA`, `DEC`, and/or `OBJID` in DES catalog")
raise RuntimeError("Cannot rename `RA`, `DEC`, and/or `OBJID` in DES catalog") from e

if convert_to_sdss_filters:
gi = catalog["g_mag"] - catalog["i_mag"]
Expand Down
2 changes: 1 addition & 1 deletion SAGA/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
SAGA package version
"""
__version__ = "0.71.0"
__version__ = "0.71.1"
4 changes: 0 additions & 4 deletions formatter.sh

This file was deleted.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.ruff]
line-length = 159

[tool.ruff.lint]
# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
select = ["E4", "E7", "E9", "F", "B"]

# 2. Avoid enforcing
ignore = ["B023", "B905"]

# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in select subdirectories.
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403", "E402"]
"**/{tests,docs,tools}/*" = ["E402"]

5 changes: 0 additions & 5 deletions test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import numpy as np
from SAGA.database import Database, DataObject, CsvTable, FitsTable

try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError


def safe_array_equal(a1, a2):
return np.array_equal(a1, a2) or np.array_equal(a1, a2, equal_nan=True)
Expand Down

0 comments on commit 1f92566

Please sign in to comment.