From e795458fb5c1d87e38dbec972cde4a77d112a414 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 7 Oct 2023 08:37:55 +0200 Subject: [PATCH 1/3] Add pyright type checker --- .github/workflows/ci-additional.yaml | 112 +++++++++++++++++++++++++++ pyproject.toml | 25 ++++++ 2 files changed, 137 insertions(+) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index ec1c192fd35..cd169da5369 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -190,6 +190,118 @@ jobs: + pyright: + name: Pyright + runs-on: "ubuntu-latest" + needs: detect-ci-trigger + # temporarily skipping due to https://github.com/pydata/xarray/issues/6551 + if: needs.detect-ci-trigger.outputs.triggered == 'false' + defaults: + run: + shell: bash -l {0} + env: + CONDA_ENV_FILE: ci/requirements/environment.yml + PYTHON_VERSION: "3.10" + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches and tags. + + - name: set environment variables + run: | + echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + - name: Setup micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ${{env.CONDA_ENV_FILE}} + environment-name: xarray-tests + create-args: >- + python=${{env.PYTHON_VERSION}} + conda + cache-environment: true + cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" + - name: Install xarray + run: | + python -m pip install --no-deps -e . + - name: Version info + run: | + conda info -a + conda list + python xarray/util/print_versions.py + - name: Install pyright + run: | + python -m pip install pyright --force-reinstall + + - name: Run pyright + run: | + python -m pyright xarray/ + + - name: Upload pyright coverage to Codecov + uses: codecov/codecov-action@v3.1.4 + with: + file: pyright_report/cobertura.xml + flags: pyright + env_vars: PYTHON_VERSION + name: codecov-umbrella + fail_ci_if_error: false + + pyright39: + name: Pyright 3.9 + runs-on: "ubuntu-latest" + needs: detect-ci-trigger + defaults: + run: + shell: bash -l {0} + env: + CONDA_ENV_FILE: ci/requirements/environment.yml + PYTHON_VERSION: "3.9" + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches and tags. + + - name: set environment variables + run: | + echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + - name: Setup micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ${{env.CONDA_ENV_FILE}} + environment-name: xarray-tests + create-args: >- + python=${{env.PYTHON_VERSION}} + conda + cache-environment: true + cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" + - name: Install xarray + run: | + python -m pip install --no-deps -e . + - name: Version info + run: | + conda info -a + conda list + python xarray/util/print_versions.py + - name: Install pyright + run: | + python -m pip install pyright --force-reinstall + + - name: Run pyright + run: | + python -m pyright xarray/ + + - name: Upload mypy coverage to Codecov + uses: codecov/codecov-action@v3.1.4 + with: + file: pyright_report/cobertura.xml + flags: pyright39 + env_vars: PYTHON_VERSION + name: codecov-umbrella + fail_ci_if_error: false + + + min-version-policy: name: Minimum Version Policy runs-on: "ubuntu-latest" diff --git a/pyproject.toml b/pyproject.toml index e24f88d9679..1a24a4b4eda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,6 +198,31 @@ warn_return_any = true module = ["xarray.namedarray.*", "xarray.tests.test_namedarray"] +[tool.pyright] +# include = ["src"] +# exclude = ["**/node_modules", + # "**/__pycache__", + # "src/experimental", + # "src/typestubs" +# ] +# ignore = ["src/oldstuff"] +defineConstant = { DEBUG = true } +# stubPath = "src/stubs" +# venv = "env367" + +reportMissingImports = true +reportMissingTypeStubs = false + +# pythonVersion = "3.6" +# pythonPlatform = "Linux" + +# executionEnvironments = [ + # { root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ] }, + # { root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] }, + # { root = "src/tests", extraPaths = ["src/tests/e2e", "src/sdk" ]}, + # { root = "src" } +# ] + [tool.ruff] builtins = ["ellipsis"] exclude = [ From c632025f811b98c0a1599048326168eb31585ec6 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 7 Oct 2023 08:47:22 +0200 Subject: [PATCH 2/3] Update ci-additional.yaml --- .github/workflows/ci-additional.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index cd169da5369..819501c6505 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -194,8 +194,13 @@ jobs: name: Pyright runs-on: "ubuntu-latest" needs: detect-ci-trigger - # temporarily skipping due to https://github.com/pydata/xarray/issues/6551 - if: needs.detect-ci-trigger.outputs.triggered == 'false' + if: | + always() + && ( + (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') + || needs.detect-ci-trigger.outputs.triggered == 'true' + || contains( github.event.pull_request.labels.*.name, 'run-pyright') + ) defaults: run: shell: bash -l {0} @@ -250,6 +255,13 @@ jobs: name: Pyright 3.9 runs-on: "ubuntu-latest" needs: detect-ci-trigger + if: | + always() + && ( + (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') + || needs.detect-ci-trigger.outputs.triggered == 'true' + || contains( github.event.pull_request.labels.*.name, 'run-pyright') + ) defaults: run: shell: bash -l {0} From 3eb442f7098335aeeb219b655553d1452da8a3b5 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 7 Oct 2023 09:10:07 +0200 Subject: [PATCH 3/3] Update ci-additional.yaml --- .github/workflows/ci-additional.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 819501c6505..9868c01baa5 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -197,9 +197,7 @@ jobs: if: | always() && ( - (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') - || needs.detect-ci-trigger.outputs.triggered == 'true' - || contains( github.event.pull_request.labels.*.name, 'run-pyright') + contains( github.event.pull_request.labels.*.name, 'run-pyright') ) defaults: run: @@ -258,9 +256,7 @@ jobs: if: | always() && ( - (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') - || needs.detect-ci-trigger.outputs.triggered == 'true' - || contains( github.event.pull_request.labels.*.name, 'run-pyright') + contains( github.event.pull_request.labels.*.name, 'run-pyright') ) defaults: run: @@ -303,7 +299,7 @@ jobs: run: | python -m pyright xarray/ - - name: Upload mypy coverage to Codecov + - name: Upload pyright coverage to Codecov uses: codecov/codecov-action@v3.1.4 with: file: pyright_report/cobertura.xml