Skip to content

Commit

Permalink
Update Makefile.
Browse files Browse the repository at this point in the history
- include copy of valgrind-python.supp that adds suppresions for reads
  of size 8
- make faulthandler module optional
- fix bug with empty terminals and latex output.
- warn that specifying training set size as fraction is not possible
  with --rerun
  • Loading branch information
andreasvc committed Oct 12, 2014
1 parent 5c6b4af commit d6b651a
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 31 deletions.
45 changes: 25 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,46 @@ docs:
cd docs && make html

test: all inplace
py.test --doctest-modules discodop/ tests/unittests.py && \
python -tt -3 tests.py && \
cd tests/ && \
sh run.sh
py.test --doctest-modules discodop/ tests/unittests.py \
&& python -tt -3 tests.py \
&& cd tests/ \
&& sh run.sh

test3:
rm -rf sample/
test3: clean
python3 setup.py install --user
cp --update build/lib.*/discodop/*.so discodop/
PYTHONIOENCODING=utf-8 python3 -bb -tt tests.py

debug:
python-dbg setup.py build_ext --inplace --debug --pyrex-gdb

testdebug: debug valgrind-python.supp
valgrind --tool=memcheck --leak-check=full --num-callers=30 \
--suppressions=valgrind-python.supp python-dbg -tt -3 tests.py

valgrind-python.supp:
wget http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

inplace: discodop
# python setup.py build_ext --inplace
cp --update build/lib.*/discodop/*.so discodop/

install: discodop docs

debug:
# NB: debug build requires all external modules to be compiled
# with debug symbols as well (e.g., install python-numpy-dbg package)
python-dbg setup.py build_ext --inplace --debug --pyrex-gdb

debugvalgrind: debug inplace
valgrind --tool=memcheck --leak-check=full --num-callers=30 \
--suppressions=valgrind-python.supp --show-leak-kinds=definite \
python-dbg tests.py

valgrind: inplace
valgrind --tool=memcheck --leak-check=full --num-callers=30 \
--suppressions=valgrind-python.supp --show-leak-kinds=definite \
python tests.py

# pylint: R=refactor, C0103 == Invalid name
lint: inplace
# Any files with more than 999 lines?
cd discodop; wc -l *.py *.pyx *.pxi *.pxd | egrep '[0-9]{4,}'
# Docstrings without single line summaries?
cd discodop; egrep -n '""".*[^.\"\\)]$$' *.pxd *.pyx *.py || echo 'none!'
pep8 --ignore=E1,W1 \
discodop/*.py web/*.py tests/*.py && \
pep8 --ignore=E1,W1,F,E901,E225,E227,E211 \
discodop/*.pyx discodop/*.pxi && \
pylint --indent-string='\t' --disable=R,bad-continuation,invalid-name \
discodop/*.py web/*.py tests/*.py \
&& pep8 --ignore=E1,W1,F,E901,E225,E227,E211 \
discodop/*.pyx discodop/*.pxi \
&& pylint --indent-string='\t' --disable=R,bad-continuation,invalid-name \
discodop/*.py web/*.py tests/*.py
4 changes: 2 additions & 2 deletions discodop/bit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ cdef inline int iteratesetbits(ULong *vec, int slots,
``idx`` should be initialized to 0, and ``cur`` to the first element of
the bit array ``vec``, i.e., ``cur = vec[idx]``.
:returns: the index of a set bit, or -1 if there are no more set
bits. The result of calling stopped iterator is undefined.
bits. The result of calling a stopped iterator is undefined.
e.g.::
Expand All @@ -191,7 +191,7 @@ cdef inline int iteratesetbits(ULong *vec, int slots,

cdef inline int iterateunsetbits(ULong *vec, int slots,
ULong *cur, int *idx):
""" Like ``iteratesetbits``, but return indices of zero bits. """
"""Like ``iteratesetbits``, but return indices of zero bits."""
cdef int tmp
while not ~cur[0]:
idx[0] += 1
Expand Down
7 changes: 5 additions & 2 deletions discodop/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,11 @@ def workerfunc(func):
@wraps(func)
def wrapper(*args, **kwds):
"""Apply decorated function."""
import faulthandler
faulthandler.enable() # Dump information on segfault.
try:
import faulthandler
faulthandler.enable() # Dump information on segfault.
except ImportError:
pass
# NB: only concurrent.futures on Python 3.3+ will exit gracefully.
try:
return func(*args, **kwds)
Expand Down
10 changes: 8 additions & 2 deletions discodop/runexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def startexp(
corpusfmt, traincorpus, binarization, punct, functions,
morphology, removeempty, transformations,
relationalrealizational)
elif isinstance(traincorpus.numsents, float):
raise ValueError('need to specify number of training set sentences, '
'not fraction, in rerun mode.')

testset = treebank.READERS[corpusfmt](
testcorpus.path, encoding=testcorpus.encoding,
Expand Down Expand Up @@ -946,8 +949,11 @@ def test():

def main(argv=None):
"""Parse command line arguments."""
import faulthandler
faulthandler.enable()
try:
import faulthandler
faulthandler.enable()
except ImportError:
pass
if argv is None:
argv = sys.argv
if len(argv) == 1:
Expand Down
6 changes: 4 additions & 2 deletions discodop/treedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ def tikzmatrix(self, nodecolor='blue', leafcolor='red',
PDF can be produced with pdflatex. Uses TiKZ matrices meaning that
nodes are put into a fixed grid. Where the cells of each column all
have the same width."""
result = ['%% %s\n%% %s' % (self.tree, ' '.join(self.sent)),
result = ['%% %s\n%% %s' % (
self.tree, ' '.join(a or '' for a in self.sent)),
r'''\begin{tikzpicture}[scale=1, minimum height=1.25em,
text height=1.25ex, text depth=.25ex,
inner sep=0mm, node distance=1mm]''',
Expand Down Expand Up @@ -579,7 +580,8 @@ def tikznode(self, nodecolor='blue', leafcolor='red', funccolor='green'):
Nodes are drawn with the \\node command so they can have arbitrary
coordinates."""
result = ['%% %s\n%% %s' % (self.tree, ' '.join(self.sent)),
result = ['%% %s\n%% %s' % (
self.tree, ' '.join(a or '' for a in self.sent)),
r'''\begin{tikzpicture}[scale=0.75, minimum height=1.25em,
text height=1.25ex, text depth=.25ex,
inner sep=0mm, node distance=1mm]''',
Expand Down
4 changes: 1 addition & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import sys
from doctest import testmod, NORMALIZE_WHITESPACE, REPORT_NDIFF
from operator import itemgetter
# do not import from current directory, since our compiled modules will only be
# installed system-wide or in the user's equivalent.
sys.path.pop(0)

MODULES = """bit coarsetofine demos disambiguation estimates eval fragments
_fragments gen grammar lexicon kbest plcfrs pcfg tree treedist treedraw
treebank treebanktransforms treetransforms runexp""".split()
Expand Down
Loading

0 comments on commit d6b651a

Please sign in to comment.