diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 4a832e6..e8f52fe 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: python-version: ["3.8"] - minizinc-version: ["2.7.2", "2.5.4"] + minizinc-version: ["2.7.6", "2.6.0"] env: MINIZINC_URL: https://github.com/MiniZinc/MiniZincIDE/releases/download/${{ matrix.minizinc-version }}/MiniZincIDE-${{ matrix.minizinc-version }}-x86_64.AppImage diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml new file mode 100644 index 0000000..6591653 --- /dev/null +++ b/.github/workflows/release-test.yml @@ -0,0 +1,53 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: On release + +on: + pull_request: + branches: [ release ] + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + minizinc-version: ["2.7.6", "2.6.0"] + + env: + MINIZINC_URL: https://github.com/MiniZinc/MiniZincIDE/releases/download/${{ matrix.minizinc-version }}/MiniZincIDE-${{ matrix.minizinc-version }}-x86_64.AppImage + steps: + - uses: actions/checkout@v3 + - name: Add bin/ to PATH + run: | + mkdir -p ${{ github.workspace }}/bin + echo "${{ github.workspace }}/bin" >> $GITHUB_PATH + - name: Install libfuse (AppImage dependency) + run: | + sudo apt-get update + sudo apt-get install libfuse2 + sudo apt-get install libegl1 + - name: Cache MiniZinc + id: cache-minizinc + uses: actions/cache@v3 + with: + path: ${{ github.workspace }}/bin/minizinc + key: ${{ env.MINIZINC_URL }} + - name: Download MiniZinc + if: steps.cache-minizinc.outputs.cache-hit != 'true' + run: | + sudo curl -o ${{ github.workspace }}/bin/minizinc -L $MINIZINC_URL + sudo chmod +x ${{ github.workspace }}/bin/minizinc + minizinc --version + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install nox + run: | + pip install nox + - name: Test + run: | + nox diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 451d64b..27e4362 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] - minizinc-version: ["2.7.2", "2.5.4"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + minizinc-version: ["2.7.6", "2.6.0"] env: MINIZINC_URL: https://github.com/MiniZinc/MiniZincIDE/releases/download/${{ matrix.minizinc-version }}/MiniZincIDE-${{ matrix.minizinc-version }}-x86_64.AppImage diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f304eb6..1d12913 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: python-version: ["3.8"] - minizinc-version: ["2.7.2", "2.5.4"] + minizinc-version: ["2.7.6", "2.6.0"] env: MINIZINC_URL: https://github.com/MiniZinc/MiniZincIDE/releases/download/${{ matrix.minizinc-version }}/MiniZincIDE-${{ matrix.minizinc-version }}-x86_64.AppImage diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 40f6da8..53ae964 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,6 +1,6 @@ version: 2 build: - os: "ubuntu-20.04" + os: "ubuntu-22.04" tools: python: "3.8" jobs: diff --git a/README.md b/README.md index 2eff09b..31bd66c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ programs. ### Prerequisites -- You should have minizinc 2.5.4+ install and have it executable in ``$PATH``. +- You should have minizinc 2.6.0+ install and have it executable in ``$PATH``. You can download it from [official site](https://www.minizinc.org/). - Python 3.8+ diff --git a/changelog.md b/changelog.md index 6f5a4d4..b3dae5b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,16 @@ +## 0.4.2 +#### CI changes +- use minizinc 2.7.6 as maximum version in CI (as in minizinc-python) +- use minizinc 2.6.0 as minimum version in CI (as in minizinc-python) +#### Python interpreters support +- add 3.12 CPython + ## 0.4.1 #### Added - ``table`` constraint - ``contains`` method for arrays and sets, to check if elem presented in collection - ``except_`` argument to ``all_different`` constraint -#### Changed ## 0.4.0 #### Added diff --git a/setup.py b/setup.py index d97a985..0608299 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="zython", version=read_version(), - python_requires=">=3.7", + python_requires=">=3.8", author="Artsiom Kaltovich", author_email="kaltovichartyom@gmail.com", description="Express constraint programming problem with python and solve it with minizinc", @@ -30,6 +30,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Intended Audience :: Developers", diff --git a/zython/_compile/zinc/flags.py b/zython/_compile/zinc/flags.py index 87e5f9c..e440b28 100644 --- a/zython/_compile/zinc/flags.py +++ b/zython/_compile/zinc/flags.py @@ -1,6 +1,6 @@ import enum -from collections import UserDict from functools import partial +from typing import Callable, Dict from zython._compile.zinc.types import SourceCode @@ -22,30 +22,22 @@ class Flags(enum.Flag): float_used = enum.auto() -FLAG_TO_SRC_PREFIX = { - Flags.alldifferent: 'include "alldifferent.mzn";', - Flags.alldifferent_except_0: 'include "alldifferent_except_0.mzn";', - Flags.alldifferent_except: 'include "alldifferent_except.mzn";', - Flags.all_equal: 'include "all_equal.mzn";', - Flags.nvalue: 'include "nvalue_fn.mzn";', - Flags.circuit: 'include "circuit.mzn";', - Flags.increasing: 'include "increasing.mzn";', - Flags.strictly_increasing: 'include "strictly_increasing.mzn";', - Flags.decreasing: 'include "decreasing.mzn";', - Flags.strictly_decreasing: 'include "strictly_decreasing.mzn";', - Flags.cumulative: 'include "cumulative.mzn";', - Flags.table: 'include "table.mzn";', -} - - def append(src: SourceCode, line: str): src.appendleft(line) -class FlagProcessors(UserDict): - def __init__(self): - super().__init__() - self[Flags.float_used] = None - - def __missing__(self, key): - return partial(append, line=FLAG_TO_SRC_PREFIX[key]) +FLAG_PROCESSORS: Dict[Flags, Callable[[SourceCode], None]] = { + Flags.alldifferent: partial(append, line='include "alldifferent.mzn";'), + Flags.alldifferent_except_0: partial(append, line='include "alldifferent_except_0.mzn";'), + Flags.alldifferent_except: partial(append, line='include "alldifferent_except.mzn";'), + Flags.all_equal: partial(append, line='include "all_equal.mzn";'), + Flags.nvalue: partial(append, line='include "nvalue_fn.mzn";'), + Flags.circuit: partial(append, line='include "circuit.mzn";'), + Flags.increasing: partial(append, line='include "increasing.mzn";'), + Flags.strictly_increasing: partial(append, line='include "strictly_increasing.mzn";'), + Flags.decreasing: partial(append, line='include "decreasing.mzn";'), + Flags.strictly_decreasing: partial(append, line='include "strictly_decreasing.mzn";'), + Flags.cumulative: partial(append, line='include "cumulative.mzn";'), + Flags.table: partial(append, line='include "table.mzn";'), + Flags.float_used: lambda x: x, +} diff --git a/zython/_compile/zinc/zinc.py b/zython/_compile/zinc/zinc.py index 8e4890b..43dadee 100644 --- a/zython/_compile/zinc/zinc.py +++ b/zython/_compile/zinc/zinc.py @@ -3,7 +3,7 @@ from typing import Set from zython._compile.ir import IR -from zython._compile.zinc.flags import Flags, FlagProcessors +from zython._compile.zinc.flags import Flags, FLAG_PROCESSORS from zython._compile.zinc.to_str import to_str, _binary_op, _get_array_shape_decl from zython._compile.zinc.types import SourceCode from zython.operations.constraint import Constraint @@ -15,21 +15,18 @@ def to_zinc(ir: IR): result: SourceCode = deque() flags: Set[Flags] = set() - flag_processors = FlagProcessors() _process_enums(ir, result, flags) _process_pars(ir, result, flags) _process_vars(ir, result, flags) _process_constraints(ir, result, flags) _process_how_to_solve(ir, result) - _process_flags(flag_processors, flags, result) + _process_flags(flags, result) return "\n".join(result) -def _process_flags(flag_processors: FlagProcessors, flags, result: SourceCode): +def _process_flags(flags, result: SourceCode): for flag in flags: - pr = flag_processors.get(flag) - if pr: - pr(result) + FLAG_PROCESSORS[flag](result) def _process_enums(ir: IR, result: SourceCode, flags: Set[Flags]) -> None: