Skip to content

Commit

Permalink
0.4.2: update versions: python 3.12, minizinc 2.6-2.7.6 (#77)
Browse files Browse the repository at this point in the history
* fix changelog.md

* update versions in ci (#72)

* 0.4.2: update versions: python 3.12, minizinc 2.6-2.7.6 (#73)

Co-authored-by: Artsiom Kaltovich <[email protected]>

* 0.4.2: update versions: python 3.12, minizinc 2.6-2.7.6 (#76)

0.4.2: update versions: python 3.12, minizinc 2.6-2.7.6 (#76)

---------

Co-authored-by: Artsiom Kaltovich <[email protected]>
  • Loading branch information
artsiomkaltovich and Artsiom Kaltovich committed Oct 15, 2023
1 parent bad01c3 commit 6a422bd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 33 deletions.
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
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
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="[email protected]",
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

0 comments on commit 6a422bd

Please sign in to comment.