Closed johnyf closed 6 years ago
Ctrl + \
quits a process running Cython code, on both Linux and Darwin (by sending the signal SIGQUIT
). See stty -a
.
In contrast, Ctrl + C
sends the signal SIGINT
, which Cython ignores by default.
Addressed in e391daf706153056aabe9b1841c5206beedfb516, eaf804b1717c401c5df84f842540f4c7178cdc4d.
92543050965fc602ed987615c3469c22faa11486 introduced use of
cysignals
to allow Ctrl+C interruption of CUDD calls. Cython's conditional compilation was used tocimport
thecysignals
package or not. Ifcysignals
is present (i.e., already installed) when cythonizingdd/cudd.pyx
, thendd/cudd.c
and thus the moduledd.cudd
will depend oncysignals
.Windows is unsupported as of
cysignals >= 1.7.0
. Socysignals
is an optional dependency ofdd
:https://github.com/johnyf/dd/blob/dc0b3c3a178064a3eeb1d2a8245bc6635c52860f/setup.py#L48-L49
https://github.com/johnyf/dd/blob/dc0b3c3a178064a3eeb1d2a8245bc6635c52860f/requirements.txt#L2
Wheel and source distributions present a challenge in this area.
Wheels
If
cysignals
is present when creating a wheel file (python setup.py bdist_wheel
), thendd.cudd
will depend oncysignals
. Wheels with compileddd.cudd
are platform specific, so in principle this dependence can always be satisfied on that specific platform (otherwisecysignals
would have been absent when building the wheel file). However,cysignals
is absent frominstall_requires
. So the resultingwheel
file will be installed with missing requirements.A solution is to use an environment marker for conditional dependency specification (PEP 508, see
setuptools
docs). For example:In theory, this would work, adding the
cysignals
to the requirements for Linux and Darwin wheels.Source archives
What about the source distribution? As recommended by Cython's docs, we include both
cudd.pyx
(source) andcudd.c
(generated bycythonize
) in the source distribution, in order to allow compilingdd.cudd
in absence of Cython (at least in principle).If
cysignals
happens to be installed in the environment ofpython setup.py sdist
, then the generatedcudd.c
depends oncysignals
(headers due tocimport
). So compiling in absence ofcysignals
will raise an error, even though the environment markerplatform_system
(discussed above) would ensure thatcysignals
is present where possible.In other words, Cython's conditionals are interpreted "early", when
cythonize
runs. If that happens on a platform different than the target one, thencysignals
is injected as a dependency when it shouldn't (contrast to an#ifdef
).Moreover, there should be one source distribution, not multiple (unlike wheels, which can be platform-specific). So
dd/cudd.c
should be independent ofcysignals
.With the current implementation:
https://github.com/johnyf/dd/blob/dc0b3c3a178064a3eeb1d2a8245bc6635c52860f/download.py#L86-L87
we need to uninstall
cysignals
before runningpython setup.py sdist --cudd
(and cleandd/cudd.c
, if it already exists; an additional complication). It is easy to forget this step. Asserting that:would avoid forgetting. A smoother alternative is to set
HAVE_CYSIGNALS = False
if building a source distribution (in that case we should rename the directive toUSE_CYSIGNALS
).Conclusion
In principle, all this would work. Simple is better than complex [PEP 20]. Indeed, if
install_requires
containscysignals
, thenpython setup.py install --cudd
raises an error:However, we cannot install
dd.cudd
from source usingpip
(viapip
only from wheels), due to how--install-option
propagates. Even if we could,python setup.py install
should remain possible.Thus,
cysignals
cannot be included ininstall_requires
, so neither source nor wheel distributions should depend oncysignals
. To ensure this, a suitable assertion is needed (as above, but also forbdist
), and cleaning before creating the distribution. Adapting the followingMakefile
rules seems appropriate:https://github.com/johnyf/dd/blob/dc0b3c3a178064a3eeb1d2a8245bc6635c52860f/Makefile#L15-L17
https://github.com/johnyf/dd/blob/dc0b3c3a178064a3eeb1d2a8245bc6635c52860f/Makefile#L36-L44
To use
cysignals
, one wouldpip install cysignals cython
(orpip install -r requirements.txt
), and thenpython setup.py install --cudd
.