Skip to content

Commit

Permalink
Merge changes to modernize code from 0.21 to 0.22
Browse files Browse the repository at this point in the history
See #1751
  • Loading branch information
hgrecco committed May 1, 2023
2 parents 95f3eac + b1c0186 commit 556aeea
Show file tree
Hide file tree
Showing 86 changed files with 1,377 additions and 1,038 deletions.
26 changes: 8 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.19,<2.0.0"]
python-version: [3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0"]
uncertainties: [null, "uncertainties==3.1.6", "uncertainties>=3.1.6,<4.0.0"]
extras: [null]
include:
- python-version: 3.8 # Minimal versions
- python-version: 3.9 # Minimal versions
numpy: "numpy"
extras: matplotlib==2.2.5
- python-version: 3.8
- python-version: 3.9
numpy: "numpy"
uncertainties: "uncertainties"
extras: "sparse xarray netCDF4 dask[complete]==2023.4.0 graphviz babel==2.8"
Expand Down Expand Up @@ -92,8 +92,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
numpy: [ "numpy>=1.19,<2.0.0" ]
python-version: [3.9, "3.10", "3.11"]
numpy: [ "numpy>=1.21,<2.0.0" ]
runs-on: windows-latest

env:
Expand Down Expand Up @@ -153,8 +153,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.19,<2.0.0" ]
python-version: [3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0" ]
runs-on: macos-latest

env:
Expand Down Expand Up @@ -226,13 +226,3 @@ jobs:
# run: |
# pip install coveralls "requests<2.29"
# coveralls --finish

# Dummy task to summarize all. See https://github.com/bors-ng/bors-ng/issues/1300
# ci-success:
# name: ci
# if: ${{ success() }}
# needs: test-linux
# runs-on: ubuntu-latest
# steps:
# - name: CI succeeded
# run: exit 0
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Get tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Set up Python 3.8
- name: Set up minimal Python version
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Get pip cache dir
id: pip-cache
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and publish to PyPI

on:
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install build

- name: Build package
run: python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sphinx:
configuration: docs/conf.py
fail_on_warning: false
python:
version: 3.8
version: 3.9
install:
- requirements: requirements_docs.txt
- method: pip
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and constants. Due to its modular design, you can extend (or even rewrite!)
the complete list without changing the source code. It supports a lot of
numpy mathematical operations **without monkey patching or wrapping numpy**.

It has a complete test coverage. It runs in Python 3.8+ with no other dependency.
It has a complete test coverage. It runs in Python 3.9+ with no other dependency.
It is licensed under BSD.

It is extremely easy and natural to use:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/20_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
units = ("meter", "kilometer", "second", "minute", "angstrom")
all_values = ("int", "float", "complex")
all_values_q = tuple(
"%s_%s" % (a, b) for a, b in it.product(all_values, ("meter", "kilometer"))
f"{a}_{b}" for a, b in it.product(all_values, ("meter", "kilometer"))
)

op1 = (operator.neg, operator.truth)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/30_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

lengths = ("short", "mid")
all_values = tuple(
"%s_%s" % (a, b) for a, b in it.product(lengths, ("list", "tuple", "array"))
f"{a}_{b}" for a, b in it.product(lengths, ("list", "tuple", "array"))
)
all_arrays = ("short_array", "mid_array")
units = ("meter", "kilometer")
all_arrays_q = tuple("%s_%s" % (a, b) for a, b in it.product(all_arrays, units))
all_arrays_q = tuple(f"{a}_{b}" for a, b in it.product(all_arrays, units))

ureg = None
data = {}
Expand Down
8 changes: 0 additions & 8 deletions bors.toml

This file was deleted.

2 changes: 0 additions & 2 deletions docs/dev/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Pint uses (and thanks):
- `github actions`_ to test all commits and PRs.
- coveralls_ to monitor coverage test coverage
- readthedocs_ to host the documentation.
- `bors-ng`_ as a merge bot and therefore every PR is tested before merging.
- black_, isort_ and flake8_ as code linters and pre-commit_ to enforce them.
- pytest_ to write tests
- sphinx_ to write docs.
Expand Down Expand Up @@ -133,7 +132,6 @@ features that work best as an extension package versus direct inclusion in Pint

.. _github: http://github.com/hgrecco/pint
.. _`issue tracker`: https://github.com/hgrecco/pint/issues
.. _`bors-ng`: https://github.com/bors-ng/bors-ng
.. _`github docs`: https://help.github.com/articles/closing-issues-via-commit-messages/
.. _`github actions`: https://docs.github.com/en/actions
.. _coveralls: https://coveralls.io/
Expand Down
2 changes: 1 addition & 1 deletion docs/getting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The getting started guide aims to get you using pint productively as quickly as
Installation
------------

Pint has no dependencies except Python itself. In runs on Python 3.8+.
Pint has no dependencies except Python itself. In runs on Python 3.9+.

.. grid:: 2

Expand Down
2 changes: 1 addition & 1 deletion docs/getting/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Due to its modular design, you can extend (or even rewrite!) the complete list
without changing the source code. It supports a lot of numpy mathematical
operations **without monkey patching or wrapping numpy**.

It has a complete test coverage. It runs in Python 3.8+ with no other
It has a complete test coverage. It runs in Python 3.9+ with no other
dependencies. It is licensed under a `BSD 3-clause style license`_.

It is extremely easy and natural to use:
Expand Down
48 changes: 46 additions & 2 deletions pint/_typing.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Tuple, TypeVar, Union
from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union, Protocol

# TODO: Remove when 3.11 becomes minimal version.
Self = TypeVar("Self")

if TYPE_CHECKING:
from .facets.plain import PlainQuantity as Quantity
from .facets.plain import PlainUnit as Unit
from .util import UnitsContainer


class PintScalar(Protocol):
def __add__(self, other: Any) -> Any:
...

def __sub__(self, other: Any) -> Any:
...

def __mul__(self, other: Any) -> Any:
...

def __truediv__(self, other: Any) -> Any:
...

def __floordiv__(self, other: Any) -> Any:
...

def __mod__(self, other: Any) -> Any:
...

def __divmod__(self, other: Any) -> Any:
...

def __pow__(self, other: Any, modulo: Any) -> Any:
...


class PintArray(Protocol):
def __len__(self) -> int:
...

def __getitem__(self, key: Any) -> Any:
...

def __setitem__(self, key: Any, value: Any) -> None:
...


Magnitude = PintScalar | PintScalar


UnitLike = Union[str, "UnitsContainer", "Unit"]

QuantityOrUnitLike = Union["Quantity", UnitLike]

Shape = Tuple[int, ...]
Shape = tuple[int, ...]

_MagnitudeType = TypeVar("_MagnitudeType")
S = TypeVar("S")
Expand Down
6 changes: 3 additions & 3 deletions pint/babel_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .compat import HAS_BABEL

_babel_units = dict(
_babel_units: dict[str, str] = dict(
standard_gravity="acceleration-g-force",
millibar="pressure-millibar",
metric_ton="mass-metric-ton",
Expand Down Expand Up @@ -141,6 +141,6 @@
if not HAS_BABEL:
_babel_units = {}

_babel_systems = dict(mks="metric", imperial="uksystem", US="ussystem")
_babel_systems: dict[str, str] = dict(mks="metric", imperial="uksystem", US="ussystem")

_babel_lengths = ["narrow", "short", "long"]
_babel_lengths: list[str] = ["narrow", "short", "long"]
Loading

0 comments on commit 556aeea

Please sign in to comment.