Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
pip install flake8 pytest pytest-astropy pytest-cov sphinx-astropy codecov
# install package and requirements
pip install ".[all]"
- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
ruff check astrodbkit2 --select=E9,F63,F7,F82 --statistics
# exit-zero treats all errors as warnings.
ruff check astrodbkit2 --config=pyproject.toml --exit-zero
- name: Test with pytest
run: |
pytest --cov --cov-config=setup.cfg --cov-report=term --cov-report=xml:coverage.xml
Expand Down
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ repos:
- repo: https://github.com/akaihola/darker
rev: 1.7.2
hooks:
- id: darker
- id: darker
args:
- --lint
- ruff check
additional_dependencies:
- ruff==0.3.7
19 changes: 10 additions & 9 deletions astrodbkit2/astrodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

__all__ = ["__version__", "Database", "or_", "and_", "create_database"]

import os
import json
import os
import sqlite3

import numpy as np
import pandas as pd
import sqlalchemy.types as sqlalchemy_types
from astropy.coordinates import SkyCoord
from astropy.table import Table as AstropyTable
from astropy.units.quantity import Quantity
from astropy.coordinates import SkyCoord
from sqlalchemy.orm import sessionmaker, declarative_base
from sqlalchemy.orm.query import Query
from sqlalchemy import Table, and_, create_engine, event, or_, text
from sqlalchemy.engine import Engine
import sqlalchemy.types as sqlalchemy_types
from sqlalchemy import event, create_engine, Table
from sqlalchemy import or_, and_, text
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.orm.query import Query
from tqdm import tqdm
from . import REFERENCE_TABLES, PRIMARY_TABLE, PRIMARY_TABLE_KEY, FOREIGN_KEY
from .utils import json_serializer, get_simbad_names, deprecated_alias, datetime_json_parser

from . import FOREIGN_KEY, PRIMARY_TABLE, PRIMARY_TABLE_KEY, REFERENCE_TABLES
from .spectra import load_spectrum
from .utils import datetime_json_parser, deprecated_alias, get_simbad_names, json_serializer

try:
from .version import version as __version__
Expand Down
4 changes: 3 additions & 1 deletion astrodbkit2/schema_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# pylint: disable=unused-argument, unused-import

import enum

import sqlalchemy as sa
from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, BigInteger, Enum, Date, DateTime
from sqlalchemy import Boolean, Column, Enum, Float, ForeignKey, String
from sqlalchemy.orm import validates

from astrodbkit2.astrodb import Base
from astrodbkit2.views import view

Expand Down
7 changes: 4 additions & 3 deletions astrodbkit2/spectra.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Functions to handle loading of spectrum objects"""

import os
import numpy as np

import astropy.units as u
from astropy.wcs import WCS
import numpy as np
from astropy.io import fits
from astropy.nddata import StdDevUncertainty
from astropy.units import Unit
from astropy.wcs import WCS
from specutils import Spectrum1D
from specutils.io.registers import data_loader
from specutils.io.parsing_utils import read_fileobj_or_hdulist
from specutils.io.registers import data_loader

# pylint: disable=no-member, unused-argument

Expand Down
25 changes: 14 additions & 11 deletions astrodbkit2/tests/test_astrodb.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Testing for astrodb

import os
import json
import pytest
import io
import json
import os

import pandas as pd
import pytest
import sqlalchemy as sa
from sqlalchemy.exc import IntegrityError
from astropy.table import Table
from astropy.coordinates import SkyCoord
from astropy.units.quantity import Quantity
from astropy.io import ascii
from astrodbkit2.astrodb import Database, create_database, Base, copy_database_schema
from astrodbkit2.views import view
from astropy.table import Table
from astropy.units.quantity import Quantity
from sqlalchemy.exc import IntegrityError

from astrodbkit2.astrodb import Database, copy_database_schema, create_database
from astrodbkit2.schema_example import *
from astrodbkit2.views import view

try:
import mock
except ImportError:
Expand All @@ -26,7 +29,7 @@
def test_nodatabase():
connection_string = 'sqlite:///:memory:'
with pytest.raises(RuntimeError, match='Create database'):
db = Database(connection_string)
_ = Database(connection_string)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -144,9 +147,9 @@ def test_orm_use(db):

# Adding a source with problematic ra/dec to test validation
with pytest.raises(ValueError):
s2 = Sources(source="V4046 Sgr", ra=9999, dec=-32.79, reference="Schm10")
_ = Sources(source="V4046 Sgr", ra=9999, dec=-32.79, reference="Schm10")
with pytest.raises(ValueError):
s2 = Sources(source="V4046 Sgr", ra=273.54, dec=-9999, reference="Schm10")
_ = Sources(source="V4046 Sgr", ra=273.54, dec=-9999, reference="Schm10")


def test_add_table_data(db):
Expand Down
7 changes: 4 additions & 3 deletions astrodbkit2/tests/test_spectra.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Tests for spectra functions

import pytest
import numpy as np
import pytest
from astropy.io import fits
from astropy.units import Unit

from astrodbkit2.spectra import (
identify_spex_prism,
_identify_spex,
identify_spex_prism,
identify_wcs1d_multispec,
load_spectrum,
spex_prism_loader,
identify_wcs1d_multispec,
wcs1d_multispec_loader,
)

Expand Down
7 changes: 5 additions & 2 deletions astrodbkit2/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Testing for utils

import pytest
import json
from datetime import datetime
from decimal import Decimal
from io import StringIO

import pytest
from astropy.table import Table
from astrodbkit2.utils import json_serializer, get_simbad_names, _name_formatter, datetime_json_parser

from astrodbkit2.utils import _name_formatter, datetime_json_parser, get_simbad_names, json_serializer

try:
import mock
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions astrodbkit2/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Adapted from https://github.com/sqlalchemy/sqlalchemy/wiki/Views

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, declarative_base

from astrodbkit2.views import *


Expand Down
3 changes: 2 additions & 1 deletion astrodbkit2/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Utility functions for Astrodbkit2"""

import re
import functools
import re
import warnings
from datetime import datetime
from decimal import Decimal

from astroquery.simbad import Simbad

__all__ = ["json_serializer", "get_simbad_names"]
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ requires = ["setuptools",

build-backend = 'setuptools.build_meta'

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
# See https://docs.astral.sh/ruff/rules/
select = ["E4", "E7", "E9", "F", "I", "PL", "C901", "RUF010"]
#select = ["ALL"]
ignore = ["PLR", # pylint refactor
"F403", # star imports used
"F405", # referring to import from star imports
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[tool.ruff]
line-length = 120

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 15.
max-complexity = 15

[tool.darker]
line-length = 120

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test =
darker==1.7.2
black==23.9.1
pre-commit==3.4.0
ruff==0.3.7
docs =
sphinx-astropy

Expand Down