Skip to content

Commit

Permalink
ruff more (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis authored Feb 7, 2024
1 parent 9985d2d commit c983d48
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 255 deletions.
34 changes: 14 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: CI
on:
push:
branches:
- 'main'
- '*.*'
- '!*backport*'
- "main"
- "*.*"
- "!*backport*"
tags:
- 'v*'
- '!*dev*'
- '!*pre*'
- '!*post*'
- "v*"
- "!*dev*"
- "!*pre*"
- "!*post*"
pull_request:
workflow_dispatch:

Expand All @@ -29,7 +29,7 @@ jobs:
apt:
- ffmpeg
envs: |
- linux: py311
- linux: py312
test:
needs: [core]
Expand All @@ -44,8 +44,8 @@ jobs:
brew:
- ffmpeg
envs: |
- windows: py310
- macos: py39
- windows: py311
- macos: py310
docs:
needs: [core]
Expand Down Expand Up @@ -76,11 +76,7 @@ jobs:
- linux: py311-online
cron:
if: |
github.event_name == 'workflow_dispatch' || (
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'Run cron CI')
)
needs: [core]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main
with:
submodules: false
Expand All @@ -90,9 +86,7 @@ jobs:
apt:
- ffmpeg
envs: |
- linux: py311-devdeps
- linux: py39-conda
libraries: ''
- linux: py312-devdeps
publish:
# Build wheels when pushing to any branch except main
Expand All @@ -110,8 +104,8 @@ jobs:
needs: [test]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@main
with:
libraries: 'ffmpeg'
test_extras: 'dev'
libraries: "ffmpeg"
test_extras: "dev"
test_command: 'pytest -p no:warnings --doctest-rst -m "not mpl_image_compare" --pyargs irispy'
submodules: false
secrets:
Expand Down
34 changes: 17 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@ repos:
rev: v1.7.5
hooks:
- id: docformatter
args: [--in-place, --pre-summary-newline, --make-summary-multi]
args: ["--in-place", "--pre-summary-newline", "--make-summary-multi"]
- repo: https://github.com/myint/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variable",
]
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|docs/conf.py)$"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.9'
rev: "v0.2.1"
hooks:
- id: ruff
args: ['--fix', '--unsafe-fixes']
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
args: ["--fix", "--unsafe-fixes"]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
Expand All @@ -44,3 +40,7 @@ repos:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
8 changes: 4 additions & 4 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ sphinx:
configuration: docs/conf.py
fail_on_warning: false
python:
install:
- method: pip
extra_requirements:
install:
- method: pip
extra_requirements:
- all
- docs
path: .
path: .
26 changes: 5 additions & 21 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""
Configuration file for the Sphinx documentation builder.
"""
import os

import datetime
import os
from pathlib import Path

from sphinx_gallery.sorting import ExampleTitleSortKey
from sunpy_sphinx_theme.conf import * # NOQA: F403
from sunpy_sphinx_theme import PNG_ICON

from irispy import __version__

# -- Project information -----------------------------------------------------
project = "irispy-lmsal"
author = "IRIS Instrument Team"
copyright = f"{datetime.datetime.now().year}, {author}" # NOQA: A001

# The full version, including alpha/beta/rc tags
copyright = f"{datetime.datetime.now(datetime.timezone.utc).year}, {author}" # NOQA: A001
release = __version__
is_development = ".dev" in __version__

Expand All @@ -38,27 +37,15 @@
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]

# Set automodapi to generate files inside the generated directory
automodapi_toctreedirnm = "generated/api"
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = ".rst"
# The master toctree document.
master_doc = "index"
# The reST default role (used for this markup: `text`) to use for all
# documents. Set to the "smart" one.
default_role = "obj"

# -- Options for hoverxref -----------------------------------------------------
if os.environ.get("READTHEDOCS"):
# Building on Read the Docs
hoverxref_api_host = "https://readthedocs.org"

if os.environ.get("PROXIED_API_ENDPOINT"):
# Use the proxied API endpoint
# - A RTD thing to avoid a CSRF block when docs are using a
Expand All @@ -68,10 +55,8 @@
hoverxref_tooltip_maxwidth = 600 # RTD main window is 696px
hoverxref_auto_ref = True
hoverxref_mathjax = True

# hoverxref has to be applied to these
hoverxref_domains = ["py"]

hoverxref_role_types = {
# roles with py domain
"attr": "tooltip",
Expand Down Expand Up @@ -131,15 +116,14 @@
}

# -- Options for HTML output -------------------------------------------------
# Render inheritance diagrams in SVG
graphviz_output_format = "svg"
sphinx_gallery_conf = {
"backreferences_dir": Path("generated") / "modules",
"filename_pattern": "^((?!skip_).)*$",
"examples_dirs": Path("..") / "examples",
"within_subsection_order": ExampleTitleSortKey,
"gallery_dirs": Path("generated") / "gallery",
"default_thumb_file": Path(html_static_path[0]) / "img" / "sunpy_icon_128x128.png", # NOQA: F405
"default_thumb_file": PNG_ICON,
"abort_on_example_error": False,
"plot_gallery": "True",
"remove_config_comments": True,
Expand Down
1 change: 0 additions & 1 deletion examples/align_iris_aia_rolled.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
You can get IRIS data with co-aligned SDO data (and more) from https://iris.lmsal.com/search/
"""


import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/mg_ii_dopplergrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
This very large dense raster took more than three hours to complete the 400 scans (30 s exposures), which means that the spacecraft's orbital velocity changes during the observations.
This means that any precise wavelength calibration will need to correct for those shifts.
"""

import tarfile

import astropy.units as u
Expand Down
1 change: 1 addition & 0 deletions examples/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
In this example, we will showcase how to use ``irispy-lmsal`` to open, crop and plot IRIS spectrograph data.
"""

import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/south_sji.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
You can get IRIS data with co-aligned SDO data (and more) from https://iris.lmsal.com/search/
"""

import matplotlib.pyplot as plt
import pooch

Expand Down
6 changes: 4 additions & 2 deletions irispy/_dev/scm_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

version = get_version(root=Path("..") / "..", relative_to=__file__)
except ImportError as e:
raise ImportError("setuptools_scm not installed") from e
msg = "setuptools_scm not installed"
raise ImportError(msg) from e
except Exception as e: # NOQA: BLE001
raise ValueError(f"setuptools_scm broken with {e}") from e
msg = f"setuptools_scm broken with {e}"
raise ValueError(msg) from e
4 changes: 2 additions & 2 deletions irispy/data/_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _retry_sample_data(results, new_url_base):
# from the previous results object and this retry, and all the errors from
# this retry.
new_results = results + extra_results
new_results._errors = extra_results._errors
new_results._errors = extra_results._errors # NOQA: SLF001
return new_results


Expand Down Expand Up @@ -121,7 +121,7 @@ def _get_sample_files(filename_list, *, no_download=False, force_download=False)
if no_download:
fullpaths = [fp if fp.exists() else None for fp in fullpaths]
else:
to_download = zip(filename_list, fullpaths)
to_download = zip(filename_list, fullpaths, strict=False)
if not force_download:
to_download = [(fn, fp) for fn, fp in to_download if not fp.exists()]
if to_download:
Expand Down
21 changes: 18 additions & 3 deletions irispy/data/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* - Sample shortname
- Name of downloaded file
"""

from ._sample import _SAMPLE_DATA, _get_sample_files

# Add a table row to the module docstring for each sample file
Expand All @@ -32,7 +33,12 @@


# file_dict and file_list are not normal variables; see __getattr__() below
__all__ = [*sorted(_SAMPLE_DATA.keys()), "download_all", "file_dict", "file_list"] # NOQA: F822, PLE0604
__all__ = [ # NOQA: PLE0604, F822
"download_all",
"file_dict",
"file_list",
*sorted(_SAMPLE_DATA.keys()),
]


# See PEP 562 (https://peps.python.org/pep-0562/) for module-level __dir__()
Expand All @@ -45,10 +51,19 @@ def __getattr__(name):
if name in _SAMPLE_DATA:
return _get_sample_files([_SAMPLE_DATA[name]])[0]
if name == "file_dict":
return dict(sorted(zip(_SAMPLE_DATA.keys(), _get_sample_files(_SAMPLE_DATA.values(), no_download=True))))
return dict(
sorted(
zip(
_SAMPLE_DATA.keys(),
_get_sample_files(_SAMPLE_DATA.values(), no_download=True),
strict=False,
)
)
)
if name == "file_list":
return [v for v in __getattr__("file_dict").values() if v]
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
msg = f"module '{__name__}' has no attribute '{name}'"
raise AttributeError(msg)


def download_all(*, force_download=False):
Expand Down
3 changes: 1 addition & 2 deletions irispy/data/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
IRISPy test data files.
"""

from pathlib import Path

from astropy.utils.data import get_pkg_data_filename
Expand Down Expand Up @@ -29,12 +30,10 @@ def get_test_filepath(filename, **kwargs):
See Also
--------
astropy.utils.data.get_pkg_data_filename : Get package data filename
Notes
-----
This is a wrapper around `astropy.utils.data.get_pkg_data_filename` which
sets the ``package`` kwarg to be 'irispy.data.test`.
"""
Expand Down
Loading

0 comments on commit c983d48

Please sign in to comment.