Skip to content

Commit

Permalink
drop python 3.9 and update to ruff 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DocOtak committed Mar 1, 2024
1 parent 0358b3b commit fd1933a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 91 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'

- name: Upgrade pip
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/do-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- name: Install Bundling dependencies
run: |
python -m pip install --upgrade pip
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v10
with:
python-version: 3.9
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel
pip install .[complete]
- name: Lint with ruff
uses: chartboost/ruff-action@v1
run: |
ruff check .
- name: Test code style with ruff
run: |
ruff format --check .
- name: Test with pytest
run: |
pytest --cov-report xml --cov=cchdo.params
- name: Test code style with black
run: |
black --check .
- name: Test typing
run: |
mypy --namespace-packages --explicit-package-bases cchdo
Expand Down
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.3.0
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [sqlalchemy, click, jinja2]
Expand Down
15 changes: 7 additions & 8 deletions cchdo/params/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib.metadata import PackageNotFoundError, version
from importlib.resources import files
from json import loads
from typing import NamedTuple, Optional, Union
from typing import NamedTuple

from ._cf_names import cf_standard_names as _cf_standard_names
from ._whp_names import _aliases
Expand All @@ -18,10 +18,10 @@
except PackageNotFoundError:
__version__ = "999"

WHPNameKey = Union[str, tuple[str, Optional[str]]]
WHPNameKey = str | tuple[str, str | None]


def to_odv(key: tuple[str, Optional[str]]):
def to_odv(key: tuple[str, str | None]):
"""Transform a (param, unit) tuple into the correct ODV style PARAM [UNIT] string
Does not check if the param exists
Expand All @@ -44,7 +44,7 @@ class WHPNameGroups(NamedTuple):


def normalize_odv_name(name: str, return_parts=False):
unit: Optional[str] = None
unit: str | None = None
if not ("[" in name or "]" in name):
if return_parts:
return name, unit
Expand Down Expand Up @@ -119,7 +119,7 @@ class _WHPNames(dict[WHPNameKey, WHPName]):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._aliases: dict[WHPNameKey, tuple[str, Optional[str]]] = dict()
self._aliases: dict[WHPNameKey, tuple[str, str | None]] = dict()

@cached_property
def odv_names(self):
Expand Down Expand Up @@ -274,7 +274,7 @@ def legacy_json(self):

return params

def add_alias(self, alias: WHPNameKey, current: tuple[str, Optional[str]]):
def add_alias(self, alias: WHPNameKey, current: tuple[str, str | None]):
"""Adds an alias to the WHPNames dict for this session only
Some alias names are a little dangerous to add without larger context.
Expand All @@ -295,8 +295,7 @@ def add_alias(self, alias: WHPNameKey, current: tuple[str, Optional[str]]):
self._aliases[alias] = current


class _CFStandardNames(UserDict[Optional[str], CFStandardName]):
...
class _CFStandardNames(UserDict[str | None, CFStandardName]): ...


CFStandardNames = _CFStandardNames(_cf_standard_names)
Expand Down
64 changes: 32 additions & 32 deletions cchdo/params/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field, replace
from datetime import date, time
from math import isnan
from typing import Literal, Optional, Union
from typing import Literal


@dataclass(frozen=True)
Expand All @@ -13,10 +13,10 @@ class CFStandardName:

#: name is the cf standard name itself, comes from the "id" property in the XML
name: str
canonical_units: Optional[str]
grib: Optional[str]
amip: Optional[str]
description: Optional[str] = field(repr=False, hash=False)
canonical_units: str | None
grib: str | None
amip: str | None
description: str | None = field(repr=False, hash=False)

@property
def cf(self):
Expand All @@ -38,7 +38,7 @@ class WHPName:
nc_name: str = field(repr=False)
#: if CF wants this variable collaposed into something with extra dimmensions
#: the final variable will have this name
nc_group: Optional[str] = field(repr=False)
nc_group: str | None = field(repr=False)
#: The historic ordering of columns in a file are determined by this rank, lower rank comes first.
#: used for sorting the parameters
rank: float = field(repr=False)
Expand All @@ -57,60 +57,60 @@ class WHPName:
#: Not all unitless parameters will have a value of `None`.
#: For example, practical salinity will have "PSS-78" rather than
#: empty units.
whp_unit: Optional[str] = None
whp_unit: str | None = None
#: Which set of woce flag definitions to use for this parameter
flag_w: Union[
Literal["woce_discrete", "woce_ctd", "no_flags", "woce_bottle"], None
] = field(default=None, repr=False)
flag_w: Literal["woce_discrete", "woce_ctd", "no_flags", "woce_bottle"] | None = (
field(default=None, repr=False)
)
#: if one exists, the cf standard name for this parameter/unit pair
cf_name: Optional[str] = None
cf_name: str | None = None
#: The expected minimum value for this parameter/unit pair
numeric_min: Optional[float] = field(default=None, repr=False)
numeric_min: float | None = field(default=None, repr=False)
#: The expected maximum value for this parameter/unit pair
numeric_max: Optional[float] = field(default=None, repr=False)
numeric_max: float | None = field(default=None, repr=False)
#: The historic print precision for this parameter
#:
#: .. danger::
#: The use of print precisions as an approximation for uncertainty should only be used if there is no other source of uncertainty.
numeric_precision: Optional[int] = field(default=None, repr=False)
numeric_precision: int | None = field(default=None, repr=False)
#: A brief description of the parameter, this is the definition of the parameter
description: Optional[str] = field(default=None, repr=False)
description: str | None = field(default=None, repr=False)
#: Any additional notes that are not really part of the definition
note: Optional[str] = field(default=None, repr=False)
note: str | None = field(default=None, repr=False)
#: If there is something tricky about this parameter, it should be a warning.
#: for example, you might interpret the NBR part of the two parameters BTLNBR and STNNBR
#: as meaning that this field can only have numeric value, this is not correct.
warning: Optional[str] = field(default=None, repr=False)
warning: str | None = field(default=None, repr=False)
#: Due to historic limitations, there is no standard way of having an error (uncertanty) parameter.
#: so a mapping is needed.
error_name: Optional[str] = field(default=None, repr=False)
error_name: str | None = field(default=None, repr=False)
#: What the units sould be in a netcdf file, these must be readable by UDUNITS2
cf_unit: Optional[str] = field(default=None, repr=False)
cf_unit: str | None = field(default=None, repr=False)
#: The calibration scale if not tied to the units, e.g. temperature has ITS-90 and IPTS-68 but bother are deg C or K
reference_scale: Optional[str] = field(default=None, repr=False)
reference_scale: str | None = field(default=None, repr=False)
#: In woce sum files, the parameters were numbered. Not all parameters have a number, and some parameter numbers present classes
#: e.g. "hydrocarbon" parameters might all have the same whp_number
whp_number: Optional[int] = field(default=None, repr=False)
whp_number: int | None = field(default=None, repr=False)
#: does this parameter apply to an entire cruise, a single profile, or a single sample record (bottle closure or ctd scan)
scope: str = field(default="sample", repr=False)
#: If reporting temperature is important, the name of the variable which will have that temperature
analytical_temperature_name: Optional[str] = field(default=None, repr=False)
analytical_temperature_name: str | None = field(default=None, repr=False)
#: If reporting temperature is important, the units of the variable which has the temperature
analytical_temperature_units: Optional[str] = field(default=None, repr=False)
analytical_temperature_units: str | None = field(default=None, repr=False)

# optics stuff
radiation_wavelength: Optional[float] = field(default=None, repr=False)
scattering_angle: Optional[float] = field(default=None, repr=False)
excitation_wavelength: Optional[float] = field(default=None, repr=False)
emission_wavelength: Optional[float] = field(default=None, repr=False)
radiation_wavelength: float | None = field(default=None, repr=False)
scattering_angle: float | None = field(default=None, repr=False)
excitation_wavelength: float | None = field(default=None, repr=False)
emission_wavelength: float | None = field(default=None, repr=False)

# API Things
alt_depth: int = field(default=0, repr=False)
#: If this param represents an alternate parameter, how deep in the alternates are we.
#: This is 0 for the builtin params
whp_name_alias: Optional[str] = field(default=None, repr=False, compare=False)
whp_name_alias: str | None = field(default=None, repr=False, compare=False)
#: If this param was instianciated from an alias, what was that alias name
whp_unit_alias: Optional[str] = field(default=None, repr=False, compare=False)
whp_unit_alias: str | None = field(default=None, repr=False, compare=False)
#: If this param was instantiated from an alias, what was that alias unit
error_col: bool = field(default=False)
#: The name that found this param was for the uncertainty/error name
Expand Down Expand Up @@ -203,7 +203,7 @@ def data_type(self):
return str

@property
def cf(self) -> Optional[CFStandardName]:
def cf(self) -> CFStandardName | None:
"""The :class:`CFStandardName` equivalent to this WHPName
Returns none if there does not exist an equivalent :class:`CFStandardName`.
Expand Down Expand Up @@ -281,8 +281,8 @@ def strfex(
self,
value,
flag: bool = False,
numeric_precision_override: Optional[int] = None,
date_or_time: Optional[Literal["date", "time"]] = None,
numeric_precision_override: int | None = None,
date_or_time: Literal["date", "time"] | None = None,
) -> str:
"""Format a value using standard WHP Exchange conventions:
Expand Down
Loading

0 comments on commit fd1933a

Please sign in to comment.