Skip to content

Commit

Permalink
Merge pull request #2586 from mraspaud/add-ruff
Browse files Browse the repository at this point in the history
Replace flake8 with ruff in pre-commit and ci linting
  • Loading branch information
mraspaud committed Oct 26, 2023
2 parents bc32c94 + 41759a8 commit 652a236
Show file tree
Hide file tree
Showing 332 changed files with 22,188 additions and 22,317 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,9 @@ env:
CACHE_NUMBER: 0

jobs:
lint:
name: lint and style checks
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 flake8-docstrings flake8-debugger flake8-bugbear pytest
- name: Install Satpy
run: |
pip install -e .
- name: Run linting
run: |
flake8 satpy/
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
needs: [lint]
strategy:
fail-fast: true
matrix:
Expand Down
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
exclude: '^$'
fail_fast: false
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.247'
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-debugger, flake8-bugbear, mccabe]
args: [--max-complexity, "10"]
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/abi_l1b_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setup_cache(self):
if len(get_filenames(self.subdir)) != 16:
raise RuntimeError("Existing data files do not match the expected number of files.")
download_rsr()
download_luts(aerosol_type='rayleigh_only')
download_luts(aerosol_type="rayleigh_only")

def setup(self):
"""Set up the benchmarks."""
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/ahi_hsd_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HimawariHSD(GeoBenchmarks):
timeout = 600
data_files: list[str] = []
subdir = os.path.join("ahi_hsd", "20210417_0500_typhoon_surigae")
reader = 'ahi_hsd'
reader = "ahi_hsd"

def setup_cache(self):
"""Fetch the data files."""
Expand All @@ -43,7 +43,7 @@ def setup_cache(self):
except ImportError:
assert len(get_filenames(self.subdir)) == 4 # nosec
download_rsr()
download_luts(aerosol_type='rayleigh_only')
download_luts(aerosol_type="rayleigh_only")

def setup(self):
"""Set up the benchmarks."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/seviri_hrit_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setup_cache(self):
except ImportError:
assert len(get_filenames(self.subdir)) == 114 # nosec
download_rsr()
download_luts(aerosol_type='rayleigh_only')
download_luts(aerosol_type="rayleigh_only")

def setup(self):
"""Set up the benchmarks."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def save_composite_as_geotiff(self, composite, resampler="native",
area=None, filenames=None):
"""Save a composite to disk as geotiff."""
lscn = self.load_and_resample(composite, resampler, area, filenames)
lscn.save_dataset(composite, filename='test.tif', tiled=True)
lscn.save_dataset(composite, filename="test.tif", tiled=True)

def compute_channel(self, channel, filenames=None):
"""Load and compute one channel."""
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/viirs_sdr_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup_cache(self):
except ImportError:
assert len(self.get_filenames()) == 6 * 3 # nosec
download_rsr()
download_luts(aerosol_type='rayleigh_only')
download_luts(aerosol_type="rayleigh_only")

def setup(self, name):
"""Set up the benchmarks."""
Expand All @@ -58,14 +58,14 @@ def get_filenames(self):
def load(self, composite):
"""Load one composite."""
from satpy import Scene
scn = Scene(filenames=self.data_files, reader='viirs_sdr')
scn = Scene(filenames=self.data_files, reader="viirs_sdr")
scn.load([composite])
return scn

def load_and_native_resample(self, composite):
"""Load and native resample a composite."""
scn = self.load(composite)
lscn = scn.resample(resampler='native')
lscn = scn.resample(resampler="native")
return lscn


Expand Down Expand Up @@ -119,4 +119,4 @@ def compute_composite(self, name):
def save_composite_as_geotiff(self, name):
"""Save a composite to disk as geotiff."""
lscn = self.load_and_native_resample(name)
lscn.save_dataset(name, filename='test.tif', tiled=True)
lscn.save_dataset(name, filename="test.tif", tiled=True)
104 changes: 52 additions & 52 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath('../../'))
sys.path.append(os.path.abspath("../../"))
sys.path.append(os.path.abspath(os.path.dirname(__file__)))

from reader_table import generate_reader_table # noqa: E402
Expand All @@ -33,10 +33,10 @@
# built documents.
#
# get version using setuptools-scm
release = get_distribution('satpy').version
release = get_distribution("satpy").version
# The full version, including alpha/beta/rc tags.
# for example take major/minor
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])


class Mock(object): # noqa
Expand All @@ -53,8 +53,8 @@ def __call__(self, *args, **kwargs):
@classmethod
def __getattr__(cls, name):
"""Mock common module attributes used in documentation."""
if name in ('__file__', '__path__'):
return '/dev/null'
if name in ("__file__", "__path__"):
return "/dev/null"
elif name[0] == name[0].upper():
mockType = type(name, (), {})
mockType.__module__ = __name__
Expand All @@ -66,15 +66,15 @@ def __getattr__(cls, name):


# https://github.com/sphinx-doc/sphinx/issues/3920
MOCK_MODULES = ['h5py']
MOCK_MODULES = ["h5py"]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock() # type: ignore

autodoc_mock_imports = ['cf', 'glymur', 'h5netcdf', 'imageio', 'mipp', 'netCDF4',
'pygac', 'pygrib', 'pyhdf', 'pyninjotiff',
'pyorbital', 'pyspectral', 'rasterio', 'trollimage',
'zarr']
autoclass_content = 'both' # append class __init__ docstring to the class docstring
autodoc_mock_imports = ["cf", "glymur", "h5netcdf", "imageio", "mipp", "netCDF4",
"pygac", "pygrib", "pyhdf", "pyninjotiff",
"pyorbital", "pyspectral", "rasterio", "trollimage",
"zarr"]
autoclass_content = "both" # append class __init__ docstring to the class docstring

# auto generate reader table from reader config files
with open("reader_table.rst", mode="w") as f:
Expand All @@ -84,40 +84,40 @@ def __getattr__(cls, name):

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage',
'sphinx.ext.doctest', 'sphinx.ext.napoleon', 'sphinx.ext.autosummary', 'doi_role',
'sphinx.ext.viewcode', 'sphinxcontrib.apidoc',
'sphinx.ext.mathjax']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.todo", "sphinx.ext.coverage",
"sphinx.ext.doctest", "sphinx.ext.napoleon", "sphinx.ext.autosummary", "doi_role",
"sphinx.ext.viewcode", "sphinxcontrib.apidoc",
"sphinx.ext.mathjax"]

# API docs
apidoc_module_dir = "../../satpy"
apidoc_output_dir = "api"
apidoc_excluded_paths = [
'readers/caliop_l2_cloud.py',
'readers/ghrsst_l3c_sst.py',
'readers/li_l2.py',
'readers/scatsat1_l2b.py',
"readers/caliop_l2_cloud.py",
"readers/ghrsst_l3c_sst.py",
"readers/li_l2.py",
"readers/scatsat1_l2b.py",
]
apidoc_separate_modules = True
apidoc_extra_args = [
"--private",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'Satpy'
copyright = u'2009-{}, The PyTroll Team'.format(datetime.utcnow().strftime("%Y"))
project = u"Satpy"
copyright = u"2009-{}, The PyTroll Team".format(datetime.utcnow().strftime("%Y"))

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -151,7 +151,7 @@ def __getattr__(cls, name):
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -161,7 +161,7 @@ def __getattr__(cls, name):

# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -190,16 +190,16 @@ def __getattr__(cls, name):
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

html_css_files = [
'theme_overrides.css', # override wide tables in RTD theme
'https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css',
"theme_overrides.css", # override wide tables in RTD theme
"https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css",
]

html_js_files = [
'https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js',
'main.js',
"https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js",
"main.js",
]


Expand Down Expand Up @@ -239,7 +239,7 @@ def __getattr__(cls, name):
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'NWCSAFMSGPPdoc'
htmlhelp_basename = "NWCSAFMSGPPdoc"


# -- Options for LaTeX output --------------------------------------------------
Expand All @@ -253,8 +253,8 @@ def __getattr__(cls, name):
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'satpy.tex', 'Satpy Documentation',
'Satpy Developers', 'manual'),
("index", "satpy.tex", "Satpy Documentation",
"Satpy Developers", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -277,22 +277,22 @@ def __getattr__(cls, name):

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'dask': ('https://docs.dask.org/en/latest', None),
'geoviews': ('http://geoviews.org', None),
'jobqueue': ('https://jobqueue.dask.org/en/latest', None),
'numpy': ('https://numpy.org/doc/stable', None),
'pydecorate': ('https://pydecorate.readthedocs.io/en/stable', None),
'pyorbital': ('https://pyorbital.readthedocs.io/en/stable', None),
'pyproj': ('https://pyproj4.github.io/pyproj/dev', None),
'pyresample': ('https://pyresample.readthedocs.io/en/stable', None),
'pytest': ('https://docs.pytest.org/en/stable/', None),
'python': ('https://docs.python.org/3', None),
'scipy': ('http://scipy.github.io/devdocs', None),
'trollimage': ('https://trollimage.readthedocs.io/en/stable', None),
'trollsift': ('https://trollsift.readthedocs.io/en/stable', None),
'xarray': ('https://xarray.pydata.org/en/stable', None),
'rasterio': ('https://rasterio.readthedocs.io/en/latest', None),
'donfig': ('https://donfig.readthedocs.io/en/latest', None),
'pooch': ('https://www.fatiando.org/pooch/latest/', None),
'fsspec': ('https://filesystem-spec.readthedocs.io/en/latest/', None),
"dask": ("https://docs.dask.org/en/latest", None),
"geoviews": ("http://geoviews.org", None),
"jobqueue": ("https://jobqueue.dask.org/en/latest", None),
"numpy": ("https://numpy.org/doc/stable", None),
"pydecorate": ("https://pydecorate.readthedocs.io/en/stable", None),
"pyorbital": ("https://pyorbital.readthedocs.io/en/stable", None),
"pyproj": ("https://pyproj4.github.io/pyproj/dev", None),
"pyresample": ("https://pyresample.readthedocs.io/en/stable", None),
"pytest": ("https://docs.pytest.org/en/stable/", None),
"python": ("https://docs.python.org/3", None),
"scipy": ("http://scipy.github.io/devdocs", None),
"trollimage": ("https://trollimage.readthedocs.io/en/stable", None),
"trollsift": ("https://trollsift.readthedocs.io/en/stable", None),
"xarray": ("https://xarray.pydata.org/en/stable", None),
"rasterio": ("https://rasterio.readthedocs.io/en/latest", None),
"donfig": ("https://donfig.readthedocs.io/en/latest", None),
"pooch": ("https://www.fatiando.org/pooch/latest/", None),
"fsspec": ("https://filesystem-spec.readthedocs.io/en/latest/", None),
}
20 changes: 10 additions & 10 deletions doc/source/doi_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def doi_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
content = []
text = utils.unescape(text)
has_explicit_title, title, part = split_explicit_title(text)
full_url = 'https://doi.org/' + part
full_url = "https://doi.org/" + part
if not has_explicit_title:
title = 'DOI:' + part
title = "DOI:" + part
pnode = nodes.reference(title, title, internal=False, refuri=full_url)
return [pnode], []

Expand All @@ -40,20 +40,20 @@ def arxiv_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
content = []
text = utils.unescape(text)
has_explicit_title, title, part = split_explicit_title(text)
full_url = 'https://arxiv.org/abs/' + part
full_url = "https://arxiv.org/abs/" + part
if not has_explicit_title:
title = 'arXiv:' + part
title = "arXiv:" + part
pnode = nodes.reference(title, title, internal=False, refuri=full_url)
return [pnode], []


def setup_link_role(app):
app.add_role('doi', doi_role, override=True)
app.add_role('DOI', doi_role, override=True)
app.add_role('arXiv', arxiv_role, override=True)
app.add_role('arxiv', arxiv_role, override=True)
app.add_role("doi", doi_role, override=True)
app.add_role("DOI", doi_role, override=True)
app.add_role("arXiv", arxiv_role, override=True)
app.add_role("arxiv", arxiv_role, override=True)


def setup(app):
app.connect('builder-inited', setup_link_role)
return {'version': '0.1', 'parallel_read_safe': True}
app.connect("builder-inited", setup_link_role)
return {"version": "0.1", "parallel_read_safe": True}
2 changes: 2 additions & 0 deletions doc/source/reader_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def rst_table_row(columns=None):
Args:
columns (list[str]): Content of each column.
Returns:
str
"""
Expand All @@ -48,6 +49,7 @@ def rst_table_header(name=None, header=None, header_rows=1, widths="auto"):
width (optional[list[int]]): Width of each column as a list. If not specified
defaults to auto and will therefore determined by the backend
(see <https://docutils.sourceforge.io/docs/ref/rst/directives.html#table>)
Returns:
str
"""
Expand Down

0 comments on commit 652a236

Please sign in to comment.