From 21e9ea29eb66d402b19ee38fb137cde5d48eaf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Hougaard=20Mulvad?= Date: Wed, 8 Nov 2023 14:21:29 +0800 Subject: [PATCH] Fix error with lowercase list for Python 3.8-3.9 --- .github/workflows/pip.yml | 8 ++------ .github/workflows/wheels.yml | 8 -------- CMakeLists.txt | 2 +- conda.recipe/meta.yaml | 3 +-- pyproject.toml | 2 +- src/fast_tsp/__init__.py | 6 ++++-- tests/basic_test.py | 24 ++++++++++++++++++++++++ 7 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 0583972..f69a5fa 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -9,24 +9,20 @@ on: jobs: build: - name: Build with Pip + name: Install locally with pip runs-on: ${{ matrix.platform }} strategy: fail-fast: false matrix: platform: [macos-latest, ubuntu-latest, windows-latest] - python-version: ["3.12"] - + python-version: ["3.8", "3.12"] steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - run: pip install --upgrade pip wheel - name: Build and install run: pip install --verbose ".[test]" - - name: Test run: pytest tests/ diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 5f3dc51..e440c8f 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -14,7 +14,6 @@ env: CIBW_TEST_COMMAND: pytest {project}/tests CIBW_TEST_EXTRAS: test - jobs: build_sdist: name: Build SDist @@ -23,18 +22,14 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Build SDist run: pipx run build --sdist - - name: Check metadata run: pipx run twine check dist/* - - uses: actions/upload-artifact@v3 with: path: dist/*.tar.gz - build_wheels: name: Wheels on ${{ matrix.builds.os }} runs-on: ${{ matrix.builds.os }} @@ -82,17 +77,14 @@ jobs: needs: [build_wheels, build_sdist] runs-on: ubuntu-latest if: github.event_name == 'release' - steps: - uses: actions/setup-python@v4 with: python-version: "3.x" - - uses: actions/download-artifact@v3 with: name: artifact path: dist - - uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ff8246..b9c4f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.15...3.28) -project(fast_tsp VERSION "0.1.3") +project(fast_tsp VERSION "0.1.4") if(SKBUILD) # Scikit-Build does not add your site-packages to the search path diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 89cdf24..e589eea 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -1,6 +1,6 @@ package: name: fast_tsp - version: 0.1.3 + version: 0.1.4 source: path: .. @@ -24,7 +24,6 @@ requirements: run: - python - test: imports: - fast_tsp diff --git a/pyproject.toml b/pyproject.toml index 1965081..5c8259b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ select = [ "RUF", ] ignore-init-module-imports = true -target-version = "py311" +target-version = "py38" # show-source = true [tool.ruff.format] diff --git a/src/fast_tsp/__init__.py b/src/fast_tsp/__init__.py index e9d3431..a01c80d 100644 --- a/src/fast_tsp/__init__.py +++ b/src/fast_tsp/__init__.py @@ -26,6 +26,8 @@ from __future__ import annotations import warnings +from typing import List +from typing import Union import numpy as np @@ -37,8 +39,8 @@ from ._core import score_tour as __score_tour # type: ignore from ._core import solve_tsp_exact as __solve_tsp_exact # type: ignore -Tour = list[int] -DistMatrix = list[list[int]] | np.ndarray +Tour = List[int] +DistMatrix = Union[List[List[int]], np.ndarray] _UINT16_MAX = 2**16 - 1 diff --git a/tests/basic_test.py b/tests/basic_test.py index d7e7cef..23d1caf 100644 --- a/tests/basic_test.py +++ b/tests/basic_test.py @@ -1,9 +1,33 @@ from __future__ import annotations +import re +from pathlib import Path + import fast_tsp import pytest +def test_version_is_consistent(): + base_dir = Path(__file__).resolve().parent.parent + + cmake_version = '' + cmake_file = base_dir / 'CMakeLists.txt' + for line in cmake_file.read_text(encoding='utf-8').splitlines(): + line_match = re.match(r'project\(fast_tsp VERSION "([\d\.]+)"\)', line) + if line_match: + cmake_version = line_match.group(1) + break + + conda_version = '' + conda_recipe = base_dir / 'conda.recipe' / 'meta.yaml' + for line in conda_recipe.read_text(encoding='utf-8').splitlines(): + line_match = re.match(r' *version: ([\d\.]+)', line) + if line_match: + conda_version = line_match.group(1) + break + assert cmake_version and cmake_version == conda_version + + def test_errors_with_wrong_signature(): with pytest.raises(ValueError, match='Distance matrix must be 2D'): fast_tsp.find_tour([0]) # type: ignore