python-constraint2 2.7.0__tar.gz → 2.7.2b2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/PKG-INFO +1 -1
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/cythonize_build.py +18 -4
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/pyproject.toml +2 -2
- python_constraint2-2.7.2b2/tests/test_examples.py +64 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/LICENSE +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/README.rst +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/__init__.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/constraints.c +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/constraints.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/domain.c +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/domain.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/parser.c +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/parser.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/problem.c +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/problem.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/solvers.c +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/constraint/solvers.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/__init__.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/benchmarks.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/setup_teardown.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_compilation.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_constraint.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_doctests.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_parser.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_problem.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_solvers.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_some_not_in_set.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_toml_file.py +0 -0
- {python_constraint2-2.7.0 → python_constraint2-2.7.2b2}/tests/test_util_benchmark.py +0 -0
|
@@ -4,6 +4,7 @@ Based on https://blagovdaryu.hashnode.dev/tremendously-speed-up-python-code-with
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
|
+
import sys
|
|
7
8
|
import shutil
|
|
8
9
|
from subprocess import CalledProcessError
|
|
9
10
|
from warnings import warn
|
|
@@ -15,10 +16,23 @@ from setuptools import Distribution, Extension
|
|
|
15
16
|
module_name = "constraint"
|
|
16
17
|
cython_modules = ["constraints", "domain", "problem", "solvers", "parser"]
|
|
17
18
|
ext = "py"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
macos_target = os.environ.get("MACOSX_DEPLOYMENT_TARGET")
|
|
20
|
+
if sys.platform == "darwin" and macos_target is not None:
|
|
21
|
+
macos_flags = [f"-mmacosx-version-min={macos_target}"]
|
|
22
|
+
extensions = [
|
|
23
|
+
Extension(
|
|
24
|
+
f"constraint.{module}",
|
|
25
|
+
[f"constraint/{module}.{ext}"],
|
|
26
|
+
extra_compile_args=["-O3", *macos_flags],
|
|
27
|
+
extra_link_args=macos_flags,
|
|
28
|
+
)
|
|
29
|
+
for module in cython_modules
|
|
30
|
+
]
|
|
31
|
+
else:
|
|
32
|
+
extensions = [
|
|
33
|
+
Extension(f"constraint.{module}", [f"constraint/{module}.{ext}"], extra_compile_args=["-O3"])
|
|
34
|
+
for module in cython_modules
|
|
35
|
+
]
|
|
22
36
|
|
|
23
37
|
# Cythonize the files
|
|
24
38
|
ext_modules = cythonize(extensions, include_path=[module_name], language_level=3, force=True)
|
|
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-constraint2" # when set back to "python-constraint", don't forget to remove '2' in other places (e.g. README)
|
|
7
7
|
description = "python-constraint is a module for efficiently solving CSPs (Constraint Solving Problems) over finite domains."
|
|
8
|
-
version = "2.7.
|
|
8
|
+
version = "2.7.2b2" # adhere to PEP440 versioning: https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#id55
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Floris-Jan Willemsen", email = "fjwillemsen97@gmail.com"},
|
|
11
11
|
{name = "Sébastien Celles", email = "s.celles@gmail.com"},
|
|
@@ -107,7 +107,7 @@ select = [
|
|
|
107
107
|
convention = "google"
|
|
108
108
|
|
|
109
109
|
[tool.pytest.ini_options]
|
|
110
|
-
minversion = "
|
|
110
|
+
minversion = "8.0.0"
|
|
111
111
|
pythonpath = [
|
|
112
112
|
"constraint",
|
|
113
113
|
] # necessary to get coverage reports without installing with `-e`
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Tests for python-constraint example solvers."""
|
|
2
|
+
|
|
3
|
+
from examples.crosswords import crosswords
|
|
4
|
+
from examples.sudoku import sudoku
|
|
5
|
+
from examples.wordmath import seisseisdoze, sendmoremoney, twotwofour
|
|
6
|
+
from examples.xsum import xsum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_sudoku():
|
|
10
|
+
"""Verify that sudoku solver returns valid 9x9 solutions."""
|
|
11
|
+
solutions = sudoku.solve()
|
|
12
|
+
assert len(solutions) >= 1
|
|
13
|
+
sol = solutions[0]
|
|
14
|
+
assert sol[12] == 9
|
|
15
|
+
row1 = [sol[10 + col] for col in range(1, 10)]
|
|
16
|
+
assert sorted(row1) == list(range(1, 10))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_sendmoremoney():
|
|
20
|
+
"""Verify cryptarithmetic solution for SEND+MORE=MONEY."""
|
|
21
|
+
solutions = sendmoremoney.solve()
|
|
22
|
+
assert len(solutions) == 1
|
|
23
|
+
s = solutions[0]
|
|
24
|
+
assert s["s"] == 9 and s["e"] == 5 and s["m"] == 1 and s["y"] == 2
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_twotwofour():
|
|
28
|
+
"""Verify cryptarithmetic solution for TWO+TWO=FOUR."""
|
|
29
|
+
solutions = twotwofour.solve()
|
|
30
|
+
assert len(solutions) > 0
|
|
31
|
+
for s in solutions:
|
|
32
|
+
two = s["t"] * 100 + s["w"] * 10 + s["o"]
|
|
33
|
+
four = s["f"] * 1000 + s["o"] * 100 + s["u"] * 10 + s["r"]
|
|
34
|
+
assert 2 * two == four
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_seisseisdoze():
|
|
38
|
+
"""Verify cryptarithmetic solution for SEIS+SEIS=DOZE."""
|
|
39
|
+
solutions = seisseisdoze.solve()
|
|
40
|
+
assert len(solutions) > 0
|
|
41
|
+
for s in solutions:
|
|
42
|
+
seis = s["s"] * 1000 + s["e"] * 100 + s["i"] * 10 + s["s"]
|
|
43
|
+
doze = s["d"] * 1000 + s["o"] * 100 + s["z"] * 10 + s["e"]
|
|
44
|
+
assert 2 * seis == doze
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_xsum():
|
|
48
|
+
"""Verify xsum solver where each 5-number row sums to 27."""
|
|
49
|
+
solutions = xsum.solve()
|
|
50
|
+
assert len(solutions) > 0
|
|
51
|
+
for s in solutions:
|
|
52
|
+
row1_sum = s["a"] + s["b"] + s["c"] + s["d"] + s["x"]
|
|
53
|
+
row2_sum = s["e"] + s["f"] + s["g"] + s["h"] + s["x"]
|
|
54
|
+
assert row1_sum == 27
|
|
55
|
+
assert row2_sum == 27
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_crosswords():
|
|
59
|
+
"""Verify crossword puzzle solver execution with sample mask and word list."""
|
|
60
|
+
puzzle = "####\n####\n####\n####"
|
|
61
|
+
words = ["DATA", "CODE", "TEST", "MATH", "BYTE", "DISK", "FILE", "FLOW"]
|
|
62
|
+
solution, matrix = crosswords.solve(puzzle, words)
|
|
63
|
+
assert isinstance(matrix, list)
|
|
64
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|