PKG Added the python-sat package (#710)

This commit is contained in:
Alexey Ignatiev 2020-07-07 20:28:33 +10:00 committed by GitHub
parent 76efcaccf7
commit 3032dcc5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 203 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package:
name: python-sat
version: 0.1.6.dev3
source:
sha256: 7dca4ad3a697db4fa50de4deb889ddd3ce9b2d9930abdc28c5e4203c6098683b
url: https://github.com/pysathq/pysat/releases/download/0.1.6.dev3/python-sat-0.1.6.dev3.tar.gz
patches:
- patches/dummy_threading.patch
- patches/force_malloc.patch
- patches/proper_build.patch
test:
imports:
- pysat

View File

@ -0,0 +1,13 @@
diff --git a/pysat/_utils.py b/pysat/_utils.py
index 8bdf132..74fb9fd 100644
--- a/pysat/_utils.py
+++ b/pysat/_utils.py
@@ -32,7 +32,7 @@
#
#==============================================================================
-import threading
+import dummy_threading as threading
#

View File

@ -0,0 +1,54 @@
diff --git a/cardenc/pycard.cc b/cardenc/pycard.cc
index 4ae27fe..5941d0a 100644
--- a/cardenc/pycard.cc
+++ b/cardenc/pycard.cc
@@ -11,6 +11,7 @@
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <Python.h>
#include "card.hh"
@@ -122,8 +123,14 @@ static struct PyModuleDef module_def = {
NULL, /* m_free */
};
+static volatile int *_dummy_malloc;
+
PyMODINIT_FUNC PyInit_pycard(void)
{
+ _dummy_malloc = (int *)malloc(sizeof(int));
+ *_dummy_malloc = 1;
+ free((void *)_dummy_malloc);
+
PyObject *m = PyModule_Create(&module_def);
if (m == NULL)
diff --git a/solvers/pysolvers.cc b/solvers/pysolvers.cc
index 7066cb4..6b4d7de 100644
--- a/solvers/pysolvers.cc
+++ b/solvers/pysolvers.cc
@@ -15,6 +15,7 @@
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <vector>
#ifdef WITH_CADICAL
@@ -493,8 +494,14 @@ static struct PyModuleDef module_def = {
NULL, /* m_free */
};
+static volatile int *_dummy_malloc;
+
PyMODINIT_FUNC PyInit_pysolvers(void)
{
+ _dummy_malloc = (int *)malloc(sizeof(int));
+ *_dummy_malloc = 1;
+ free((void *)_dummy_malloc);
+
PyObject *m = PyModule_Create(&module_def);
if (m == NULL)

View File

@ -0,0 +1,120 @@
diff --git a/setup.py b/setup.py
index 4e810df..d191d6d 100644
--- a/setup.py
+++ b/setup.py
@@ -68,8 +68,8 @@ Details can be found at `https://pysathq.github.io <https://pysathq.github.io>`_
# solvers to install
#==============================================================================
-to_install = ['cadical', 'glucose30', 'glucose41', 'lingeling', 'maplechrono',
- 'maplecm', 'maplesat', 'minicard', 'minisat22', 'minisatgh']
+to_install = ['cadical', 'glucose30', 'glucose41', 'maplechrono', 'maplecm',
+ 'maplesat', 'minicard', 'minisat22', 'minisatgh']
# example scripts to install as standalone executables
@@ -77,47 +77,9 @@ to_install = ['cadical', 'glucose30', 'glucose41', 'lingeling', 'maplechrono',
scripts = ['fm', 'genhard', 'lbx', 'lsu', 'mcsls', 'models', 'musx', 'rc2']
-# we need to redefine the build command to
-# be able to download and compile solvers
-#==============================================================================
-class build(distutils.command.build.build):
- """
- Our custom builder class.
- """
-
- def run(self):
- """
- Download, patch and compile SAT solvers before building.
- """
- # download and compile solvers
- if platform.system() != 'Windows':
- prepare.do(to_install)
-
- # now, do standard build
- distutils.command.build.build.run(self)
-
-# same with build_ext
-#==============================================================================
-class build_ext(distutils.command.build_ext.build_ext):
- """
- Our custom builder class.
- """
-
- def run(self):
- """
- Download, patch and compile SAT solvers before building.
- """
- # download and compile solvers
- if platform.system() != 'Windows':
- prepare.do(to_install)
-
- # now, do standard build
- distutils.command.build_ext.build_ext.run(self)
-
-
# compilation flags for C extensions
#==============================================================================
-compile_flags, cpplib = ['-std=c++11', '-Wall', '-Wno-deprecated'], ['stdc++']
+compile_flags, cpplib = ['-std=c++11', '-O3', '-Wall', '-Wno-deprecated', '-DQUIET'], ['stdc++']
if platform.system() == 'Darwin':
compile_flags += ['--stdlib=libc++']
cpplib = ['c++']
@@ -140,23 +102,19 @@ pycard_ext = Extension('pycard',
pysolvers_sources = ['solvers/pysolvers.cc']
-if platform.system() == 'Windows':
- prepare.do(to_install)
- with chdir('solvers'):
- for solver in to_install:
- with chdir(solver):
- for filename in glob.glob('*.c*'):
- pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
- for filename in glob.glob('*/*.c*'):
- pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
- libraries = []
- library_dirs = []
-else:
- libraries = to_install + cpplib
- library_dirs = list(map(lambda x: os.path.join('solvers', x), to_install))
+prepare.do(to_install)
+with chdir('solvers'):
+ for solver in to_install:
+ with chdir(solver):
+ for filename in glob.glob('*.c*'):
+ pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+ for filename in glob.glob('*/*.c*'):
+ pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+libraries = []
+library_dirs = []
pysolvers_ext = Extension('pysolvers',
- sources=pysolvers_sources,
+ sources=sorted(pysolvers_sources),
extra_compile_args=compile_flags + \
list(map(lambda x: '-DWITH_{0}'.format(x.upper()), to_install)),
include_dirs=['solvers'],
@@ -181,7 +139,6 @@ setup(name='python-sat',
url='https://github.com/pysathq/pysat',
ext_modules=[pycard_ext, pysolvers_ext],
scripts=['examples/{0}.py'.format(s) for s in scripts],
- cmdclass={'build': build, 'build_ext': build_ext},
install_requires=['six'],
extras_require = {
'aiger': ['py-aiger-cnf>=2.0.0'],
diff --git a/solvers/prepare.py b/solvers/prepare.py
index f947be1..97ccaa5 100644
--- a/solvers/prepare.py
+++ b/solvers/prepare.py
@@ -421,8 +421,6 @@ def do(to_install):
adapt_files(solver)
patch_solver(solver)
- if platform.system() != 'Windows':
- compile_solver(solver)
#
#==============================================================================