-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1660 from OceanParcels/v/type-annotations
Type annotations, mypy config, pydoclint setup, and other changes
- Loading branch information
Showing
27 changed files
with
399 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "monthly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ on: | |
- "master" | ||
- "test-me/*" | ||
pull_request: | ||
branches: | ||
- "*" | ||
schedule: | ||
- cron: "0 7 * * 1" # Run every Monday at 7:00 UTC | ||
|
||
concurrency: | ||
group: branch-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -el {0} | ||
|
@@ -81,3 +83,25 @@ jobs: | |
with: | ||
name: Integration test report | ||
path: ${{ matrix.os }}_integration_test_report.html | ||
typechecking: | ||
name: mypy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Conda and parcels | ||
uses: ./.github/actions/install-parcels | ||
with: | ||
environment-file: environment.yml | ||
- run: conda install lxml # dep for report generation | ||
- name: Typechecking | ||
run: | | ||
mypy --install-types --non-interactive parcels --cobertura-xml-report mypy_report | ||
- name: Upload mypy coverage to Codecov | ||
uses: codecov/[email protected] | ||
if: ${{ always() }} # Upload even on error of mypy | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: mypy_report/cobertura.xml | ||
flags: mypy | ||
fail_ci_if_error: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Import helpers for compatability between installations.""" | ||
|
||
__all__ = ["MPI", "KMeans"] | ||
|
||
from typing import Any | ||
|
||
MPI: Any | None = None | ||
KMeans: Any | None = None | ||
|
||
try: | ||
from mpi4py import MPI # type: ignore[no-redef] | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
# KMeans is used in MPI. sklearn not installed by default | ||
try: | ||
from sklearn.cluster import KMeans # type: ignore[no-redef] | ||
except ModuleNotFoundError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Typing support for Parcels. | ||
This module contains type aliases used throughout Parcels as well as functions that are | ||
used for runtime parameter validation (to ensure users are only using the right params). | ||
""" | ||
|
||
import ast | ||
import datetime | ||
import os | ||
from typing import Callable, Literal | ||
|
||
|
||
class ParcelsAST(ast.AST): | ||
ccode: str | ||
|
||
|
||
InterpMethodOption = Literal[ | ||
"linear", | ||
"nearest", | ||
"freeslip", | ||
"partialslip", | ||
"bgrid_velocity", | ||
"bgrid_w_velocity", | ||
"cgrid_velocity", | ||
"linear_invdist_land_tracer", | ||
"nearest", | ||
"bgrid_tracer", | ||
"cgrid_tracer", | ||
] # corresponds with `tracer_interp_method` | ||
InterpMethod = ( | ||
InterpMethodOption | dict[str, InterpMethodOption] | ||
) # corresponds with `interp_method` (which can also be dict mapping field names to method) | ||
PathLike = str | os.PathLike | ||
Mesh = Literal["spherical", "flat"] # corresponds with `mesh` | ||
VectorType = Literal["3D", "2D"] | None # corresponds with `vector_type` | ||
ChunkMode = Literal["auto", "specific", "failsafe"] # corresponds with `chunk_mode` | ||
GridIndexingType = Literal["pop", "mom5", "mitgcm", "nemo"] # corresponds with `grid_indexing_type` | ||
UpdateStatus = Literal["not_updated", "first_updated", "updated"] # corresponds with `update_status` | ||
TimePeriodic = float | datetime.timedelta | Literal[False] # corresponds with `update_status` | ||
NetcdfEngine = Literal["netcdf4", "xarray", "scipy"] | ||
|
||
|
||
KernelFunction = Callable[..., None] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.