Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.4.2: update versions: python 3.12, minizinc 2.6-2.7.6 #77

Merged
merged 4 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
build:
os: "ubuntu-20.04"
os: "ubuntu-22.04"
tools:
python: "3.8"
jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+

Expand Down
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
40 changes: 16 additions & 24 deletions zython/_compile/zinc/flags.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
}
11 changes: 4 additions & 7 deletions zython/_compile/zinc/zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down