From 3bcd8399844eda761494d0e91e64453afc05bb4c Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:04:52 +0200 Subject: [PATCH 01/12] drop Python 3.7 support --- .github/workflows/cicd.yaml | 2 +- pyproject.toml | 9 +++++---- setup.cfg | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index ad1def2..4049f21 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12'] + python: ['3.8', '3.9', '3.10', '3.11', '3.12'] prerelease: [false] include: - python: '3.13' diff --git a/pyproject.toml b/pyproject.toml index defec7e..b16dcf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,16 +23,17 @@ show_missing = true [tool.black] line-length = 80 -target-version = ["py37"] +target-version = ["py38"] [tool.isort] line_length = 80 -py_version = "37" +py_version = "38" profile = "black" src_paths = ["airbase", "tests"] extend_skip = ["scripts"] [tool.mypy] +python_version = "3.8" warn_unused_configs = true warn_unused_ignores = false warn_no_return = true @@ -41,7 +42,7 @@ warn_unreachable = true show_error_codes = true pretty = true sqlite_cache = true -exclude = "docs|scripts" +exclude = "docs|scripts|build" [[tool.mypy.overrides]] module = ["tqdm"] @@ -50,7 +51,7 @@ ignore_missing_imports = true [tool.tox] legacy_tox_ini = """ [tox] -envlist = py37, py38, py39, py310, py311, py312, lint, docs, integration +envlist = py38, py39, py310, py311, py312, lint, docs, integration skip_missing_interpreters = True isolated_build = True diff --git a/setup.cfg b/setup.cfg index 318a6b7..d691e49 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,6 @@ classifiers = License :: OSI Approved :: MIT License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -21,7 +20,7 @@ classifiers = Topic :: Scientific/Engineering :: Atmospheric Science [options] -python_requires = >=3.7,<4 +python_requires = >=3.8,<4 install_requires = aiohttp; python_version < "3.12" aiohttp >= 3.9.0; python_version >= "3.12" From 51b92cb9334b8b3117a6e43bde1c2e837df32415 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:09:40 +0200 Subject: [PATCH 02/12] configure ruff w/pyupgrade rules --- pyproject.toml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b16dcf1..c419c71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,20 @@ profile = "black" src_paths = ["airbase", "tests"] extend_skip = ["scripts"] +[tool.ruff] +target-version = "py38" +line-length = 80 +extend-exclude = ["docs", "scripts", "build"] + +[tool.ruff.lint] +select = ["UP"] + +[tool.ruff.lint.per-file-ignores] +"cli.py" = [ # typer needs typing.Optional and typing.List + "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation/ + "UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation/ +] + [tool.mypy] python_version = "3.8" warn_unused_configs = true From bd7e69c866cdea56cef492386060f478651a844d Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:15:46 +0200 Subject: [PATCH 03/12] remove Python 3.7 imports --- airbase/__version__.py | 7 +------ airbase/airbase.py | 6 +----- setup.cfg | 1 - 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/airbase/__version__.py b/airbase/__version__.py index a0a7ad7..06b8ce6 100644 --- a/airbase/__version__.py +++ b/airbase/__version__.py @@ -1,11 +1,6 @@ from __future__ import annotations -import sys - -if sys.version_info >= (3, 8): # pragma: no cover - from importlib import metadata -else: # pragma: no cover - import importlib_metadata as metadata +from importlib import metadata __version__: str | None try: diff --git a/airbase/airbase.py b/airbase/airbase.py index 4a7ecb6..202f6c2 100644 --- a/airbase/airbase.py +++ b/airbase/airbase.py @@ -4,11 +4,7 @@ import warnings from datetime import datetime from pathlib import Path - -if sys.version_info >= (3, 8): # pragma: no cover - from typing import TypedDict -else: # pragma: no cover - from typing_extensions import TypedDict +from typing import TypedDict from .fetch import ( fetch_text, diff --git a/setup.cfg b/setup.cfg index d691e49..e922768 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,6 @@ install_requires = aiofiles importlib_resources; python_version < "3.11" tqdm - typing_extensions; python_version < "3.8" typer >=0.9.1 packages = find: include_package_data = True From c998ce873551c8d6e717eb7da5468672ab634b4c Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:16:45 +0200 Subject: [PATCH 04/12] use f-strings --- airbase/airbase.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/airbase/airbase.py b/airbase/airbase.py index 202f6c2..bcb0c62 100644 --- a/airbase/airbase.py +++ b/airbase/airbase.py @@ -330,9 +330,7 @@ def _get_csv_links(self, force: bool = False) -> None: if self.verbose: print( - "Generated {:,} CSV links ready for downloading".format( - len(self._csv_links) - ), + f"Generated {len(self._csv_links):,} CSV links ready for downloading", file=sys.stderr, ) From 040a7f5f8255aed1d16cb508fabbd9e344c3ed98 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:26:18 +0200 Subject: [PATCH 05/12] configure ruff w/pyflakes rules --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c419c71..8deabae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ line-length = 80 extend-exclude = ["docs", "scripts", "build"] [tool.ruff.lint] -select = ["UP"] +select = ["F", "UP"] [tool.ruff.lint.per-file-ignores] "cli.py" = [ # typer needs typing.Optional and typing.List From ddf604a7e1c57a809ec27f2d559e1aa1552da39b Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:27:25 +0200 Subject: [PATCH 06/12] use plain strings --- airbase/airbase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airbase/airbase.py b/airbase/airbase.py index bcb0c62..654849b 100644 --- a/airbase/airbase.py +++ b/airbase/airbase.py @@ -154,8 +154,8 @@ def request( if shortpl is not None: warnings.warn( - f"the shortpl option has been deprecated and will be removed on v1. " - f"Use client.request([client._pollutants_ids[p] for p in shortpl], ...) instead.", + "the shortpl option has been deprecated and will be removed on v1. " + "Use client.request([client._pollutants_ids[p] for p in shortpl], ...) instead.", DeprecationWarning, stacklevel=2, ) From dc9d2087be53377f09e6e3dffa5999d39c58f964 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:31:11 +0200 Subject: [PATCH 07/12] configure ruff w/pycodestyle rules --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8deabae..a71bd3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,10 @@ line-length = 80 extend-exclude = ["docs", "scripts", "build"] [tool.ruff.lint] -select = ["F", "UP"] +select = ["E", "W", "F", "UP"] +ignore = [ + "E501", # https://docs.astral.sh/ruff/rules/line-too-long/ +] [tool.ruff.lint.per-file-ignores] "cli.py" = [ # typer needs typing.Optional and typing.List From 10b98349037225257e5580600210a7488669c813 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:36:33 +0200 Subject: [PATCH 08/12] ambiguous variable name, E741 --- tests/test_airbase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_airbase.py b/tests/test_airbase.py index 2db52c1..a247332 100644 --- a/tests/test_airbase.py +++ b/tests/test_airbase.py @@ -156,7 +156,7 @@ def test_download_file(self, tmp_path: Path): assert header == header_expected # make sure header only there once - is_header = (l.strip() == header_expected for l in lines) + is_header = (line.strip() == header_expected for line in lines) assert sum(is_header) == 1 def test_download_metadata(self, tmp_path: Path): From 2a4ba6acfa9c3cfd8c1099f9884a638fc34b694e Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:37:29 +0200 Subject: [PATCH 09/12] use function def instead of lambda, E731 --- tests/test_fetch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 8f3cabe..518bfc3 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -134,7 +134,9 @@ def test_fetch_to_file(tmp_path: Path, csv_urls: dict[str, str]): assert path.exists() # drop the header and compare data rows - rows = lambda text: text.splitlines()[1:] + def rows(text: str) -> list[str]: + return text.splitlines()[1:] + data_on_file = rows(path.read_text()) data_rows = list( itertools.chain.from_iterable(rows(text) for text in csv_urls.values()) From ba577444e352d0fa90510117546915d09e619f3e Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:39:40 +0200 Subject: [PATCH 10/12] configure ruff w/isort rules --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a71bd3c..1098fdb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ line-length = 80 extend-exclude = ["docs", "scripts", "build"] [tool.ruff.lint] -select = ["E", "W", "F", "UP"] +select = ["E", "W", "F", "I", "UP"] ignore = [ "E501", # https://docs.astral.sh/ruff/rules/line-too-long/ ] From 619280e3e2803ca1e18eec853faff12eaba19d0c Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Thu, 20 Jun 2024 10:55:50 +0200 Subject: [PATCH 11/12] lint with ruff --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c7c94b..23c88cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,7 @@ repos: hooks: - id: isort name: isort (python) +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.9 + hooks: + - id: ruff # run the linter From 1b14dc92556fe37b21f9f58f85b31dec5d363e07 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Tue, 25 Jun 2024 10:20:35 +0200 Subject: [PATCH 12/12] replace black & isort with ruff --- .pre-commit-config.yaml | 17 ++++------------- README.md | 3 +-- airbase/resources.py | 1 + pyproject.toml | 11 ----------- 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23c88cf..aee8859 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,12 @@ repos: -- repo: https://github.com/psf/black - rev: "22.3.0" +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.9 hooks: - - id: black - args: [-l, "80"] + - id: ruff-format # formatter + - id: ruff # linter - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.10.0 hooks: - id: mypy exclude: '(docs/.*)|(setup\.py)' additional_dependencies: [types-aiofiles, types-requests] -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort (python) -- repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.9 - hooks: - - id: ruff # run the linter diff --git a/README.md b/README.md index bb5128d..82b73e9 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,8 @@ [![CI/CD](https://github.com/JohnPaton/airbase/actions/workflows/cicd.yaml/badge.svg?branch=master)](https://github.com/JohnPaton/airbase/actions/workflows/cicd.yaml) [![Documentation Status](https://readthedocs.org/projects/airbase/badge/?version=latest)](https://airbase.readthedocs.io/en/latest/?badge=latest) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) -[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) -[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) # 🌬 AirBase diff --git a/airbase/resources.py b/airbase/resources.py index 136126e..4d3d44e 100644 --- a/airbase/resources.py +++ b/airbase/resources.py @@ -1,4 +1,5 @@ """Global variables for URL templating""" + import datetime E1A_SUMMARY_URL = "http://discomap.eea.europa.eu/map/fme/E1a/summaryE1a.js" diff --git a/pyproject.toml b/pyproject.toml index 1098fdb..6d4cf53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,17 +21,6 @@ skip_covered = true skip_empty = true show_missing = true -[tool.black] -line-length = 80 -target-version = ["py38"] - -[tool.isort] -line_length = 80 -py_version = "38" -profile = "black" -src_paths = ["airbase", "tests"] -extend_skip = ["scripts"] - [tool.ruff] target-version = "py38" line-length = 80