Skip to content

Commit

Permalink
Fix error with lowercase list for Python 3.8-3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
shmulvad committed Nov 8, 2023
1 parent a6ec85c commit 21e9ea2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
8 changes: 0 additions & 8 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ env:
CIBW_TEST_COMMAND: pytest {project}/tests
CIBW_TEST_EXTRAS: test


jobs:
build_sdist:
name: Build SDist
Expand All @@ -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 }}
Expand Down Expand Up @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: fast_tsp
version: 0.1.3
version: 0.1.4

source:
path: ..
Expand All @@ -24,7 +24,6 @@ requirements:
run:
- python


test:
imports:
- fast_tsp
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ select = [
"RUF",
]
ignore-init-module-imports = true
target-version = "py311"
target-version = "py38"
# show-source = true

[tool.ruff.format]
Expand Down
6 changes: 4 additions & 2 deletions src/fast_tsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from __future__ import annotations

import warnings
from typing import List
from typing import Union

import numpy as np

Expand All @@ -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

Expand Down
24 changes: 24 additions & 0 deletions tests/basic_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 21e9ea2

Please sign in to comment.