From f51a1eefa74730c79c73e0424491a5733cb738bb Mon Sep 17 00:00:00 2001 From: hirwa Date: Thu, 21 Mar 2024 10:20:07 +0530 Subject: [PATCH 1/4] update ruff to the previous linter --- .pre-commit-config.yaml | 46 +++-------------- .flake8 => .ruffconfig | 4 +- pyproject.toml | 110 ++++++++++++++++++++++++++++++++++++++++ setup.cfg | 5 -- 4 files changed, 119 insertions(+), 46 deletions(-) rename .flake8 => .ruffconfig (60%) create mode 100644 pyproject.toml delete mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b71c00c8..1f71303b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,6 @@ ci: autoupdate_schedule: quarterly -# https://pre-commit.com/ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 @@ -12,52 +11,21 @@ repos: - id: check-yaml - id: debug-statements - id: mixed-line-ending - # This wants to go before isort & flake8 - - repo: https://github.com/PyCQA/autoflake - rev: "v2.2.1" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.2 hooks: - - id: autoflake # isort should run before black as black sometimes tweaks the isort output - args: ["--in-place", "--ignore-init-module-imports"] - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: ["--profile", "black"] - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: - - "--py38-plus" - # https://github.com/python/black#version-control-integration + # run the linter + - id: ruff + args: [--fix, --ignore-noqa] + - repo: https://github.com/psf/black rev: 23.12.1 hooks: - id: black - id: black-jupyter + - repo: https://github.com/keewis/blackdoc rev: v0.3.9 hooks: - id: blackdoc exclude: docs/index.rst - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 - hooks: - - id: mypy - exclude: "properties|asv_bench" - # This is slow and so we take it out of the fast-path; requires passing - # `--hook-stage manual` to pre-commit - stages: [manual] - additional_dependencies: [ - # Type stubs - types-python-dateutil, - types-pkg_resources, - types-PyYAML, - types-pytz, - typing-extensions, - numpy, - ] diff --git a/.flake8 b/.ruffconfig similarity index 60% rename from .flake8 rename to .ruffconfig index b671ff93..7609a434 100644 --- a/.flake8 +++ b/.ruffconfig @@ -1,5 +1,5 @@ -[flake8] -ignore = E203, E266, E501, W503, F403, F401 +[lint] +ignore = E203,E266,E501,W503,F403,F401 max-line-length = 89 max-complexity = 18 select = B,C,E,F,W,T4,B9 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..0566a93d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,110 @@ +[build-system] +requires = ["setuptools>=42", "wheel", "pip"] +build-backend = "setuptools.build_meta" + +[tool.pytest] +addopts = "--ignore=setup.py" + +[tool.pytest.ini_options] +norecursedirs = [ + ".git", + ".github", + "docs", +] + +[tool.ruff] +line-length = 120 +target-version = "py38" +exclude = [".git", "asv_bench", "docs", "conftest.py"] + + +[tool.ruff.lint] +select = [ + # https://pypi.org/project/pycodestyle + "E", + "W", + # https://pypi.org/project/pyflakes + "F", + # https://pypi.org/project/flake8-bandit + "S", + # https://docs.astral.sh/ruff/rules/#pyupgrade-up + "UP", + "I002", # Missing required imports + "UP008", # Super calls with redundant arguments passed. + "G010", # Deprecated log warn. + "PLR1722", # Use sys.exit() instead of exit() and quit(). + "PT014", # pytest-duplicate-parametrize-test-cases. + "PT006", # Checks for the type of parameter names passed to pytest.mark.parametrize. + "PT007", # Checks for the type of parameter values passed to pytest.mark.parametrize. + "PT018", # Checks for assertions that combine multiple independent conditions. +] + +extend-select = [ + "I", # isort + "C4", # https://pypi.org/project/flake8-comprehensions +] + +ignore = [ + "S101", # Use of `assert` detected + "E203", # Whitespace-before-punctuation. + "E402", # Module-import-not-at-top-of-file. + "E731", # Do not assign a lambda expression, use a def. + "D100", # Missing docstring in public module. + "D101", # Missing docstring in public class. + "D102", # Missing docstring in public method. + "D103", # Missing docstring in public function. + "D104", # Missing docstring in public package. + "D105", # Missing docstring in magic method. + "D106", # Missing docstring in public nested class. + "D107", # Missing docstring in `__init__`. + "RET504", # Unnecessary variable assignment before `return` statement. + "S101", # Use of `assert` detected. + "S108", + "D203", # 1 blank line required before class docstring. + "D205", # 1 blank line required between summary line and description. + "D212", # Multi-line docstring summary should start at the first line. + "D213", # Multi-line docstring summary should start at the second line. + "D209", # Multi-line docstring closing quotes should be on a separate line. + "D400", # First line should end with a period. + "D413", # Missing blank line after last section of docstrings. + "D401", # First line of docstring should be in imperative mood. + "D415", # First line should end with a period, question mark, or exclamation point. + "D416", # Section name should end with a colon ("Attributes"). + "D417", # Missing argument description in the docstring for argument "X". + "RUF100", # https://docs.astral.sh/ruff/rules/unused-noqa/ + "C408", + "SIM118", + "RET506", + "TRY004", + "RET505", + "RET507", + "SIM108", + "SIM102", + "E501", # line too long + "E266", + "F403", + "F401", + "F841", + "RET", + "SIM", + "PT", +] +ignore-init-module-imports = true + +[tool.ruff.lint.per-file-ignores] + +"setup.py" = ["S101"] +"**/__init__.py" = ["F401", "F403", "F405", "F811", "F821", "E501", "SIM102"] +"tests/**" = [ + "S605", # Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell` + "S607", # Starting a process with a partial executable path + "RET504", # todo:Unnecessary variable assignment before `return` statement + "PT004", # Fixture `tmpdir_unittest_fixture` does not return anything, add leading underscore + "PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + "PT012", # `pytest.raises()` block should contain a single simple statement + "PT019", # Fixture `_` without value is injected as parameter, use `@pytest.mark.usefixtures` instead + "PT006" # Checks for the type of parameter names passed to pytest.mark.parametrize. +] + +[tool.blackdoc] +exclude = "docs/index.rst" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index d81669c6..00000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[bdist_wheel] -universal = 1 - -[tool:pytest] -addopts = --ignore=setup.py From 5c03430ec223adc961826ab3404daa1b5414c3a2 Mon Sep 17 00:00:00 2001 From: hirwa Date: Thu, 21 Mar 2024 10:22:00 +0530 Subject: [PATCH 2/4] remove ruffconfig --- .ruffconfig | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .ruffconfig diff --git a/.ruffconfig b/.ruffconfig deleted file mode 100644 index 7609a434..00000000 --- a/.ruffconfig +++ /dev/null @@ -1,6 +0,0 @@ -[lint] -ignore = E203,E266,E501,W503,F403,F401 -max-line-length = 89 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 -exclude = docs From 5203675983b2f42dbc51885728cd5ae2b991bd59 Mon Sep 17 00:00:00 2001 From: Hauke Schulz <43613877+observingClouds@users.noreply.github.com> Date: Fri, 5 Apr 2024 21:08:01 -0700 Subject: [PATCH 3/4] adjust tests to new xarray cfscale return dtype algorithm --- tests/test_bitround.py | 8 ++++---- xbitinfo/xbitinfo.py | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/test_bitround.py b/tests/test_bitround.py index aaa126b9..99464f38 100644 --- a/tests/test_bitround.py +++ b/tests/test_bitround.py @@ -86,26 +86,26 @@ def test_bitround_along_dim(air_temperature): ds, info_per_bit, dim="lon", inflevels=[1.0, 0.9999, 0.99, 0.975] ) - assert ds_bitrounded_along_lon.air.dtype == "float32" + assert ds_bitrounded_along_lon.air.dtype == "float64" assert ds_bitrounded_along_lon.lon.size == ds.lon.size assert ds_bitrounded_along_lon.lat.size == ds.lat.size assert ds_bitrounded_along_lon.time.size == ds.time.size assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype - assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001 + assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01 # test for keepbits ds_bitrounded_along_lon = bi.bitround_along_dim( ds, info_per_bit, dim="lon", inflevels=None, keepbits=2 ) - assert ds_bitrounded_along_lon.air.dtype == "float32" + assert ds_bitrounded_along_lon.air.dtype == "float64" assert ds_bitrounded_along_lon.lon.size == ds.lon.size assert ds_bitrounded_along_lon.lat.size == ds.lat.size assert ds_bitrounded_along_lon.time.size == ds.time.size assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype - assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001 + assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01 # Test error when both keepbits and inflevels are provided with pytest.raises(ValueError): diff --git a/xbitinfo/xbitinfo.py b/xbitinfo/xbitinfo.py index 4450a98f..9a98f408 100644 --- a/xbitinfo/xbitinfo.py +++ b/xbitinfo/xbitinfo.py @@ -152,13 +152,13 @@ def get_bitinformation( # noqa: C901 ------- >>> ds = xr.tutorial.load_dataset("air_temperature") >>> xb.get_bitinformation(ds, dim="lon") # doctest: +ELLIPSIS - Size: 652B - Dimensions: (bitfloat32: 32) + Size: 1kB + Dimensions: (bitfloat64: 64) Coordinates: - * bitfloat32 (bitfloat32) >> xb.get_bitinformation(ds) - Size: 1kB - Dimensions: (bitfloat32: 32, dim: 3) + Size: 2kB + Dimensions: (bitfloat64: 64, dim: 3) Coordinates: - * bitfloat32 (bitfloat32) >> xb.get_keepbits(info_per_bit, inflevel=0.99999999) Size: 28B Dimensions: (inflevel: 1) @@ -419,7 +419,7 @@ def get_keepbits(info_per_bit, inflevel=0.99): dim >> xb.get_keepbits(info_per_bit, inflevel=1.0) Size: 28B Dimensions: (inflevel: 1) @@ -427,7 +427,7 @@ def get_keepbits(info_per_bit, inflevel=0.99): dim >> info_per_bit = xb.get_bitinformation(ds) >>> xb.get_keepbits(info_per_bit) Size: 80B @@ -436,7 +436,7 @@ def get_keepbits(info_per_bit, inflevel=0.99): * dim (dim) Date: Sun, 31 Mar 2024 01:00:16 +0000 Subject: [PATCH 4/4] Update GitHub Action Versions --- .github/workflows/benchmarks.yml | 2 +- .github/workflows/ci.yaml | 8 ++++---- .github/workflows/pypi.yml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 6162f8f7..70513de2 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -26,7 +26,7 @@ jobs: fetch-depth: 0 - name: Setup Miniconda - uses: conda-incubator/setup-miniconda@v3.0.2 + uses: conda-incubator/setup-miniconda@v3.0.3 with: # installer-url: https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh installer-url: https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2dd80b37..02ca731b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: with: fetch-depth: 0 - name: Set up conda - uses: conda-incubator/setup-miniconda@v3.0.2 + uses: conda-incubator/setup-miniconda@v3.0.3 with: auto-update-conda: false channels: conda-forge @@ -60,7 +60,7 @@ jobs: shell: 'bash -l {0}' steps: - uses: actions/checkout@v4.1.1 - - uses: conda-incubator/setup-miniconda@v3.0.2 + - uses: conda-incubator/setup-miniconda@v3.0.3 with: channels: conda-forge miniforge-variant: Mambaforge @@ -91,7 +91,7 @@ jobs: steps: - uses: actions/checkout@v4.1.1 - name: Set up conda - uses: conda-incubator/setup-miniconda@v3.0.2 + uses: conda-incubator/setup-miniconda@v3.0.3 with: auto-update-conda: false channels: conda-forge @@ -134,7 +134,7 @@ jobs: with: fetch-depth: 0 - name: Setup python - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.1.0 with: python-version: '3.11' - name: Set up Julia diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 34ae4030..3b4fa779 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4.1.1 - name: Set up Python - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.1.0 with: python-version: "3.10" @@ -45,7 +45,7 @@ jobs: - name: Publish a Python distribution to PyPI if: success() && github.event_name == 'release' - uses: pypa/gh-action-pypi-publish@v1.8.11 + uses: pypa/gh-action-pypi-publish@v1.8.14 with: user: __token__ password: ${{ secrets.PYPI_PASSWORD }}