Skip to content

Commit

Permalink
Drop support for Python 3.8 (#112)
Browse files Browse the repository at this point in the history
* Bump to Python 3.9

* Get rid of Tuple, List and Dict

* Upgrade actions
  • Loading branch information
leonlan authored Jun 20, 2024
1 parent 3094e8c commit ec1bd38
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 80 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/vrplib.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/vrplib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: VRPLIB

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [created]


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Update pip and poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Cache Python dependencies
uses: actions/cache@v4
id: cache-python
with:
path: ~/.cache/pypoetry
key: python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install Python dependencies
if: steps.cache-python.outputs.cache-hit != 'true'
run: poetry install
- name: Cache pre-commit
uses: actions/cache@v4
id: cache-pre-commit
with:
path: ~/.cache/pre-commit/
key: pre-commit-${{ env.pythonLocation }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commit
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: poetry run pre-commit install --install-hooks
- name: Run pre-commit
run: poetry run pre-commit run --all-files
- name: Run pytest
run: poetry run pytest
- uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

deploy:
needs: build
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Deploy to PyPI
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry build
poetry publish
589 changes: 589 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ readme = "README.md"
repository = "https://github.com/PyVRP/VRPLIB"

[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.19"
python = "^3.9"
numpy = "^1.19.3"

[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
Expand Down
6 changes: 2 additions & 4 deletions tests/parse/test_parse_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from typing import List

import pytest
from numpy.testing import assert_equal

from vrplib.parse.parse_utils import text2lines


@pytest.mark.parametrize(("text", "expected"), [("", []), ("\n", [])])
def test_empty_lines(text: str, expected: List[str]):
def test_empty_lines(text: str, expected: list[str]):
assert_equal(text2lines(text), expected)


Expand All @@ -23,5 +21,5 @@ def test_empty_lines(text: str, expected: List[str]):
(" # comment after whitespace", []),
],
)
def test_comments(text: str, expected: List[str]):
def test_comments(text: str, expected: list[str]):
assert_equal(text2lines(text), expected)
4 changes: 2 additions & 2 deletions vrplib/parse/parse_distances.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from itertools import combinations
from typing import List, Optional, Union
from typing import Optional, Union

import numpy as np


def parse_distances(
data: List,
data: list[float],
edge_weight_type: str,
edge_weight_format: Optional[str] = None,
node_coord: Optional[np.ndarray] = None,
Expand Down
6 changes: 3 additions & 3 deletions vrplib/parse/parse_solomon.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, List, Union
from typing import Union

import numpy as np

from .parse_distances import pairwise_euclidean
from .parse_utils import text2lines

Instance = Dict[str, Union[str, float, np.ndarray]]
Instance = dict[str, Union[str, float, np.ndarray]]


def parse_solomon(text: str, compute_edge_weights: bool = True) -> Instance:
Expand Down Expand Up @@ -46,7 +46,7 @@ def parse_solomon(text: str, compute_edge_weights: bool = True) -> Instance:
return instance


def is_valid_solomon_instance(lines: List[str]):
def is_valid_solomon_instance(lines: list[str]):
"""
Checks if the passed-in lines follow the Solomon format requirements.
"""
Expand Down
4 changes: 2 additions & 2 deletions vrplib/parse/parse_solution.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Dict, List, Union
from typing import Union

from .parse_utils import infer_type, text2lines

Solution = Dict[str, Union[float, str, List]]
Solution = dict[str, Union[float, str, list]]


def parse_solution(text: str) -> Solution:
Expand Down
4 changes: 2 additions & 2 deletions vrplib/parse/parse_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Union
from typing import Union


def text2lines(text: str) -> List[str]:
def text2lines(text: str) -> list[str]:
"""
Takes a string and returns a list of non-empty, stripped lines. Also
removes any comment lines from the given string.
Expand Down
10 changes: 5 additions & 5 deletions vrplib/parse/parse_vrplib.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import re
from typing import Dict, List, Tuple, Union
from typing import Union

import numpy as np

from .parse_distances import parse_distances
from .parse_utils import infer_type, text2lines

Instance = Dict[str, Union[str, float, np.ndarray]]
Instance = dict[str, Union[str, float, np.ndarray]]


def parse_vrplib(text: str, compute_edge_weights: bool = True) -> Instance:
Expand Down Expand Up @@ -53,7 +53,7 @@ def parse_vrplib(text: str, compute_edge_weights: bool = True) -> Instance:
return instance


def group_specifications_and_sections(lines: List[str]):
def group_specifications_and_sections(lines: list[str]):
"""
Groups instance lines into specifications and section parts.
"""
Expand Down Expand Up @@ -88,7 +88,7 @@ def group_specifications_and_sections(lines: List[str]):
return specs, sections


def parse_specification(line: str) -> Tuple[str, Union[float, str]]:
def parse_specification(line: str) -> tuple[str, Union[float, str]]:
"""
Parses a specification line as keyword-value pair, split at the first colon
occurrence. The keyword is made lowercase and the value is unmodified.
Expand All @@ -97,7 +97,7 @@ def parse_specification(line: str) -> Tuple[str, Union[float, str]]:
return k.lower(), infer_type(v)


def parse_section(lines: List, instance: Dict) -> np.ndarray:
def parse_section(lines: list, instance: dict) -> np.ndarray:
"""
Parses the data section into numpy arrays.
"""
Expand Down
4 changes: 2 additions & 2 deletions vrplib/read/read_instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Any, Dict, Union
from typing import Any, Union

from vrplib.parse import parse_solomon, parse_vrplib

Expand All @@ -8,7 +8,7 @@ def read_instance(
path: Union[str, os.PathLike],
instance_format: str = "vrplib",
compute_edge_weights: bool = True,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""
Reads the instance from the passed-in file path.
Expand Down
4 changes: 2 additions & 2 deletions vrplib/read/read_solution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from typing import Any, Dict, Union
from typing import Any, Union

from vrplib.parse import parse_solution


def read_solution(path: Union[str, os.PathLike]) -> Dict[str, Union[str, Any]]:
def read_solution(path: Union[str, os.PathLike]) -> dict[str, Any]:
"""
Reads the solution from the passed-in file path.
Expand Down
6 changes: 3 additions & 3 deletions vrplib/write/write_instance.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from typing import Dict, List, Tuple, TypeVar, Union
from typing import TypeVar, Union

import numpy as np

_ArrayLike = TypeVar("_ArrayLike", List, Tuple, np.ndarray)
_ArrayLike = TypeVar("_ArrayLike", list, tuple, np.ndarray)


def write_instance(
path: Union[str, os.PathLike],
data: Dict[str, Union[str, int, float, _ArrayLike]],
data: dict[str, Union[str, int, float, _ArrayLike]],
):
"""
Writes a VRP instance to file following the VRPLIB format [1].
Expand Down
6 changes: 3 additions & 3 deletions vrplib/write/write_solution.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from typing import Any, Dict, List, Optional, Union
from typing import Any, Optional, Union


def write_solution(
path: Union[str, os.PathLike],
routes: List[List[int]],
data: Optional[Dict[str, Any]] = None,
routes: list[list[int]],
data: Optional[dict[str, Any]] = None,
):
"""
Writes a VRP solution to file following the VRPLIB convention.
Expand Down

0 comments on commit ec1bd38

Please sign in to comment.