psyco: drop psyco support (closes #90272)

  • psyco is not maintained anymore.
  • psyco does not work on 64bit arch
  • psyco does not work with recent python
  • psyco is not in debian anymore
  • psyco prevents using efficient set as base class

psyco specify workaround are removed.

authorPierre-Yves David <pierre-yves.david@logilab.fr>
changeset1a324da0ffc8
branchdefault
phasepublic
hiddenno
parent revision#0cc8bde876c4 test: prevent spurious print during testrun
child revision#9cc3a1b9600f FiniteDomain: inherit from set builtins (closes #89865)
files modified by this revision
distributors.py
examples/menza.py
examples/menza_brute_force.py
propagation.py
psyco_wrapper.py
test/test_validation.py
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1331911152 -3600
# Fri Mar 16 16:19:12 2012 +0100
# Node ID 1a324da0ffc88352e22da3901e62473587854218
# Parent 0cc8bde876c4cdf7e4d904bf236eab62d5366e81
psyco: drop psyco support (closes #90272)

- psyco is not maintained anymore.
- psyco does not work on 64bit arch
- psyco does not work with recent python
- psyco is not in debian anymore
- psyco prevents using efficient set as base class

psyco specify workaround are removed.

diff --git a/distributors.py b/distributors.py
@@ -18,22 +18,21 @@
1 
2  """
3  distributors - part of Logilab's constraint satisfaction solver.
4  """
5 
6 -from logilab.constraint.psyco_wrapper import Psyobj
7  from logilab.constraint.interfaces import DistributorInterface
8  import math, random
9 
10  def make_new_domains(domains):
11      """return a shallow copy of dict of domains passed in argument"""
12      domain = {}
13      for key, value in domains.items():
14          domain[key] = value.copy()
15      return domain
16 
17 -class AbstractDistributor(Psyobj):
18 +class AbstractDistributor(object):
19      """Implements DistributorInterface but abstract because
20      _distribute is left unimplemented."""
21 
22      __implements__ = DistributorInterface
23 
diff --git a/examples/menza.py b/examples/menza.py
@@ -21,14 +21,13 @@
24  ABC*DE=FGHIJ with all letters different and in domain [0,9]
25  """
26  from __future__ import generators
27 
28  from logilab.constraint import *
29 -from logilab.constraint.psyco_wrapper import psyobj
30  from logilab.constraint.propagation import BasicConstraint, ConsistencyFailure
31 
32 -class DistinctDigits(BasicConstraint,psyobj):
33 +class DistinctDigits(BasicConstraint):
34      def __init__(self,variable):
35          BasicConstraint.__init__(self,variable,None,None)
36 
37      def narrow(self,domains):
38          domain = domains[self._variable]
diff --git a/examples/menza_brute_force.py b/examples/menza_brute_force.py
@@ -13,15 +13,10 @@
39  # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
40  # for more details.
41  #
42  # You should have received a copy of the GNU Lesser General Public License along
43  # with logilab-constraint. If not, see <http://www.gnu.org/licenses/>.
44 -try:
45 -    import psyco
46 -    psyco.full()
47 -except ImportError:
48 -    print 'Psyco not available'
49 
50  def menza():
51      sol = []
52      all_digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
53      for a in range(1000) :
diff --git a/propagation.py b/propagation.py
@@ -18,11 +18,10 @@
54  """The code of the constraint propagation algorithms"""
55  from __future__ import generators
56  from operator import mul as MUL
57  from time import strftime
58  from logilab.constraint.interfaces import DomainInterface, ConstraintInterface
59 -from logilab.constraint.psyco_wrapper import Psyobj
60 
61  def _default_printer(*msgs):
62      for msg in msgs[:-1]:
63          print msg,
64      print msgs[-1]
@@ -32,11 +31,11 @@
65 
66  class ConsistencyFailure(Exception):
67      """The repository is not in a consistent state"""
68      pass
69 
70 -class Repository(Psyobj):
71 +class Repository(object):
72      """Stores variables, domains and constraints
73      Propagates domain changes to constraints
74      Manages the constraint evaluation queue"""
75 
76      def __init__(self, variables, domains, constraints = None, printer=_default_printer):
@@ -228,11 +227,11 @@
77          for domain in self._domains.itervalues():
78              if domain.size() != 1:
79                  return 0
80          return 1
81 
82 -class Solver(Psyobj):
83 +class Solver(object):
84      """Top-level object used to manage the search"""
85 
86      def __init__(self, distributor=None, printer=_default_printer):
87          """if no distributer given, will use the default one"""
88          self.printer = printer
@@ -247,25 +246,21 @@
89          """Generates only one solution"""
90          self.verbose = verbose
91          self.max_depth = 0
92          self.distrib_cnt = 0
93          try:
94 -            # XXX  FIXME: this is a workaround a bug in psyco-1.4
95 -##             return  self._solve(repository).next()
96 -            return  self._solve(repository, 0).next()
97 +            return  self._solve(repository).next()
98          except StopIteration:
99              return
100 
101      def solve_best(self, repository, cost_func, verbose=0):
102          """Generates solution with an improving cost"""
103          self.verbose = verbose
104          self.max_depth = 0
105          self.distrib_cnt = 0
106          best_cost = None
107 -            # XXX  FIXME: this is a workaround a bug in psyco-1.4
108 -##        for solution in self._solve(repository):
109 -        for solution in self._solve(repository, 0):
110 +        for solution in self._solve(repository):
111              cost = cost_func(**solution)
112              if best_cost is None or cost <= best_cost:
113                  best_cost = cost
114                  yield solution, cost
115 
@@ -327,11 +322,11 @@
116 
117 
118 
119 
120 
121 -class BasicConstraint(Psyobj):
122 +class BasicConstraint(object):
123      """A BasicConstraint, which is never queued by the Repository
124      A BasicConstraint affects only one variable, and will be entailed
125      on the first call to narrow()"""
126 
127      __implements__ = ConstraintInterface
@@ -370,11 +365,11 @@
128              raise ConsistencyFailure('inconsistency while applying %s' % \
129                                       repr(self))
130          return 1
131 
132 
133 -class AbstractDomain(Psyobj):
134 +class AbstractDomain(object):
135      """Implements the functionnality related to the changed flag.
136      Can be used as a starting point for concrete domains"""
137 
138      __implements__ = DomainInterface
139      def __init__(self):
@@ -390,11 +385,11 @@
140          """The implementation of removeValue should call this method"""
141          self.__changed = 1
142          if self.size() == 0:
143              raise ConsistencyFailure()
144 
145 -class AbstractConstraint(Psyobj):
146 +class AbstractConstraint(object):
147      __implements__ = ConstraintInterface
148 
149      def __init__(self, variables):
150          """variables is a list of variables which appear in the formula"""
151          self._variables = variables
diff --git a/psyco_wrapper.py b/psyco_wrapper.py
@@ -1,42 +0,0 @@
152 -# pylint: disable-msg=W0232
153 -# copyright 2002-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
154 -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
155 -#
156 -# This file is part of logilab-constraint.
157 -#
158 -# logilab-constraint is free software: you can redistribute it and/or modify it
159 -# under the terms of the GNU Lesser General Public License as published by the
160 -# Free Software Foundation, either version 2.1 of the License, or (at your
161 -# option) any later version.
162 -#
163 -# logilab-constraint is distributed in the hope that it will be useful, but
164 -# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
165 -# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
166 -# for more details.
167 -#
168 -# You should have received a copy of the GNU Lesser General Public License along
169 -# with logilab-constraint. If not, see <http://www.gnu.org/licenses/>.
170 -
171 -"""Provides an psyobj class regardless of the availability of psyco"""
172 -
173 -import os
174 -
175 -try:
176 -    if "NO_PSYCO" in os.environ:
177 -        raise ImportError()
178 -    from psyco.classes import psyobj as Psyobj # pylint: disable-msg=W0611
179 -except ImportError:
180 -
181 -    class Psyobj:
182 -        pass
183 -
184 -    if hasattr(os,'uname') and os.uname()[-1] == 'x86_64':
185 -        pass # psyco only available for 32bits platforms
186 -    else:
187 -        from warnings import warn
188 -        warn("Psyco could not be loaded."
189 -             " Psyco is a Python just in time compiler available at http://psyco.sf.net"
190 -             " Installing it will enhance the performance of logilab.constraint",
191 -             stacklevel=2)
192 -
193 -
diff --git a/test/test_validation.py b/test/test_validation.py
@@ -90,17 +90,15 @@
194 
195  class Queens6Verbose_TC(Queens6_TC):
196      verbose = 3
197 
198 
199 -# remove if we are running with pylint, 'cos this gets too long without psyco
200 -if os.environ.get('PYLINT_IMPORT') != '1':
201 -    class Queens9_TC(Queens8_TC):
202 -        size=9
203 -        nb_sols=352
204 +class Queens9_TC(Queens8_TC):
205 +    size=9
206 +    nb_sols=352
207 
208 -    class Queens10_TC(Queens8_TC):
209 -        size=10
210 -        nb_sols=724
211 +class Queens10_TC(Queens8_TC):
212 +    size=10
213 +    nb_sols=724
214 
215  if __name__ == '__main__':
216      unittest_main()