Skip to content

Commit

Permalink
chore(pre-commit): [pre-commit.ci] autoupdate (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Xuehai Pan <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and XuehaiPan authored Nov 5, 2024
1 parent 46731f5 commit b75db44
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 52 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
PYTHON_TAG: "py3" # to be updated

jobs:
build-sdist:
name: Build sdist
Expand Down Expand Up @@ -88,17 +91,25 @@ jobs:
matrix:
runner: [ubuntu-latest, windows-latest, macos-latest]
python-version:
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.13t", "pypy-3.9", "pypy-3.10"]
archs: [
# Generic
"auto",
# Linux
"aarch64",
"ppc64le",
"s390x",
# Windows
"ARM64",
]
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.13t"
- "pypy-3.9"
- "pypy-3.10"
archs:
# Generic
- "auto"
# Linux
- "aarch64"
- "ppc64le"
- "s390x"
# Windows
- "ARM64"
include:
- runner: macos-13
python-version: "3.7"
Expand Down Expand Up @@ -169,7 +180,7 @@ jobs:
update-environment: true
allow-prereleases: true

- name: Upgrade pip
- name: Set up Environment
run: |
python -m pip install --upgrade pip setuptools wheel pybind11
Expand All @@ -186,13 +197,12 @@ jobs:
shell: bash
run: |
PYTHON_TAG="$(
python -c \
"import sys; print(
'{0.name[0]}p{1.major}{1.minor}'.format(
sys.implementation,
sys.version_info,
).lower(),
)"
echo 'import sys; print(
"{0.name[0]}p{1.major}{1.minor}".format(
sys.implementation,
sys.version_info,
).lower(),
)' | python -
)"
if [[ "${{ matrix.python-version }}" == *"t" ]]; then
PYTHON_TAG="${PYTHON_TAG}t"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install OpTree
run: |
python -m pip install -vvv --no-build-isolation --editable '.[lint,benchmark]'
python -m pip install -vv --no-build-isolation --editable '.[lint,benchmark]'
- name: pre-commit
run: |
Expand Down
42 changes: 30 additions & 12 deletions .github/workflows/tests-with-pydebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ concurrency:

env:
OPTREE_CXX_WERROR: "ON"
PYTHON: "python" # to be updated
PYTHON_VERSION: "3" # to be updated
PYENV_ROOT: "~/.pyenv" # to be updated
COLUMNS: "128"

jobs:
test:
Expand All @@ -36,7 +40,14 @@ jobs:
strategy:
matrix:
runner: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
python-abiflags: ["d", "td"]
exclude:
- python-version: "3.7"
Expand All @@ -55,35 +66,42 @@ jobs:
python-version: "3.13"
python-abiflags: "td"
fail-fast: false
timeout-minutes: 90
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pyenv
id: setup-pyenv-unix
if: runner.os != 'Windows'
run: |
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}"
git clone https://github.com/pyenv/pyenv.git "${PYENV_ROOT}"
echo "PYENV_ROOT=${PYENV_ROOT}" >> "${GITHUB_ENV}"
echo "PATH=${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}" >> "${GITHUB_ENV}"
echo "PATH=${PATH}" >> "${GITHUB_ENV}"
- name: Set up pyenv
id: setup-pyenv-windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$Env:PYENV_ROOT = "$Env:USERPROFILE\.pyenv"
$Env:PATH = "$Env:PYENV_ROOT\pyenv-win\bin;$Env:PYENV_ROOT\pyenv-win\shims;$Env:PATH"
git clone https://github.com/pyenv-win/pyenv-win.git "$Env:PYENV_ROOT"
Write-Output "PYENV_ROOT=$Env:PYENV_ROOT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PYENV_ROOT\pyenv-win\bin;$Env:PYENV_ROOT\pyenv-win\shims;$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Determine Python version
shell: bash
run: |
if [[ "${{ runner.os }}" == 'Windows' ]]; then
pyenv update
fi
echo "::group::pyenv install --list"
pyenv install --list
echo "::endgroup::"
if [[ "${{ matrix.python-abiflags }}" == *t* ]]; then
PYTHON_VERSION="$(
pyenv install --list | tr -d ' ' | grep -E "^${{ matrix.python-version }}" |
Expand All @@ -95,8 +113,7 @@ jobs:
grep -vF '-' | grep -E '[0-9]$' | sort -rV | head -n 1
)"
fi
echo "Using Python version: ${PYTHON_VERSION}"
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> "${GITHUB_ENV}"
echo "PYTHON_VERSION=${PYTHON_VERSION}" | tee -a "${GITHUB_ENV}"
- uses: actions/cache@v4
id: python-cache
Expand All @@ -120,17 +137,18 @@ jobs:
fi
fi
pyenv install ${{ env.PYTHON_VERSION }} "${PYENV_INSTALL_ARGS[@]}"
pyenv global ${{ env.PYTHON_VERSION }}
pyenv global "$(pyenv versions | grep -F '${{ env.PYTHON_VERSION }}' | tr -d ' ')"
pyenv rehash
- name: Upgrade pip
- name: Set up Environment
run: |
python --version
python -c 'from pprint import pprint; import sysconfig; pprint(sysconfig.get_config_vars())'
python -m pip install --upgrade pip setuptools wheel
${{ env.PYTHON }} --version
${{ env.PYTHON }} -c 'from pprint import pprint; import sysconfig; pprint(sysconfig.get_config_vars())'
${{ env.PYTHON }} -m pip install --upgrade pip setuptools wheel
- name: Install OpTree
run: |
python -m pip install -vvv --editable '.[test]'
${{ env.PYTHON }} -m pip install -vv --editable '.[test]'
- name: Test with pytest
run: |
Expand Down
31 changes: 18 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ concurrency:
env:
OPTREE_CXX_WERROR: "ON"
FULL_TEST_PYTHON_VERSIONS: "3.10;3.11"
PYTHON: "python" # to be updated
COLUMNS: "128"

jobs:
test:
Expand All @@ -38,7 +40,15 @@ jobs:
matrix:
runner: [ubuntu-latest, windows-latest, macos-latest]
python-version:
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9", "pypy-3.10"]
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "pypy-3.9"
- "pypy-3.10"
include:
- runner: macos-13
python-version: "3.7"
Expand All @@ -58,32 +68,27 @@ jobs:
update-environment: true
allow-prereleases: true

- name: Upgrade pip
- name: Set up Environment
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Set `SETUPTOOLS_ENABLE_FEATURES`
if: ${{ matrix.python-version == '3.7' && runner.os == 'Windows' }}
run: |
Write-Output 'SETUPTOOLS_ENABLE_FEATURES=legacy-editable' | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
${{ env.PYTHON }} -m pip install --upgrade pip setuptools wheel
- name: Install test dependencies
shell: bash
run: |
if [[ ";${FULL_TEST_PYTHON_VERSIONS};" == *";${{ matrix.python-version }};"* ]]; then
python -m pip install -r tests/requirements.txt
${{ env.PYTHON }} -m pip install -r tests/requirements.txt
fi
- name: Test installable with C++17
if: runner.os != 'Windows'
run: |
OPTREE_CXX_WERROR=OFF CMAKE_CXX_STANDARD=17 python -m pip install -vvv --editable .
python -X dev -W 'always' -W 'error' -c 'import optree'
python -m pip uninstall -y optree
OPTREE_CXX_WERROR=OFF CMAKE_CXX_STANDARD=17 ${{ env.PYTHON }} -m pip install -vv --editable .
${{ env.PYTHON }} -X dev -W 'always' -W 'error' -c 'import optree'
${{ env.PYTHON }} -m pip uninstall -y optree
- name: Install OpTree
run: |
python -m pip install -vvv --editable '.[test]'
${{ env.PYTHON }} -m pip install -vv --editable '.[test]'
- name: Test with pytest
run: |
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ repos:
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.2
rev: v19.1.3
hooks:
- id: clang-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.7.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ default: install

.PHONY: install
install:
$(PYTHON) -m pip install -vvv .
$(PYTHON) -m pip install -vv .

.PHONY: install-editable install-e
install-editable install-e:
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install --upgrade setuptools wheel
$(PYTHON) -m pip install --upgrade pybind11 cmake
OPTREE_CXX_WERROR="$(OPTREE_CXX_WERROR)" CMAKE_CXX_STANDARD="$(CMAKE_CXX_STANDARD)" \
$(PYTHON) -m pip install -vvv --no-build-isolation --editable .
$(PYTHON) -m pip install -vv --no-build-isolation --editable .

.PHONY: uninstall
uninstall:
Expand Down Expand Up @@ -265,7 +265,7 @@ format: py-format-install ruff-install clang-format-install addlicense-install

.PHONY: clean-py
clean-py:
find . -type f -name '*.py[co]' -delete
find . -type f -name '*.py[co]' -delete
find . -depth -type d -name "__pycache__" -exec rm -r "{}" +
find . -depth -type d -name ".ruff_cache" -exec rm -r "{}" +
find . -depth -type d -name ".mypy_cache" -exec rm -r "{}" +
Expand Down
4 changes: 4 additions & 0 deletions include/optree/pymacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ limitations under the License.

namespace py = pybind11;

#if PY_VERSION_HEX < 0x03070000 // Python 3.7
#error "Python 3.7 or newer is required."
#endif

#ifndef Py_ALWAYS_INLINE
#define Py_ALWAYS_INLINE
#endif
Expand Down
9 changes: 7 additions & 2 deletions optree/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ class PyTree(Generic[T]): # pragma: no cover
@_tp_cache
def __class_getitem__( # noqa: C901
cls,
item: T | tuple[T] | tuple[T, str | None],
item: (
type[T]
| TypeAlias
| tuple[type[T] | TypeAlias]
| tuple[type[T] | TypeAlias, str | None]
),
) -> TypeAlias:
"""Instantiate a PyTree type with the given type."""
if not isinstance(item, tuple):
Expand Down Expand Up @@ -322,7 +327,7 @@ class PyTreeTypeVar: # pragma: no cover
"""

@_tp_cache
def __new__(cls, name: str, param: type) -> TypeAlias:
def __new__(cls, name: str, param: type | TypeAlias) -> TypeAlias:
"""Instantiate a PyTree type variable with the given name and parameter."""
if not isinstance(name, str):
raise TypeError(f'{cls.__name__} only supports a string of type name, got {name!r}.')
Expand Down

0 comments on commit b75db44

Please sign in to comment.