forked from beancount/beancount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·266 lines (197 loc) · 7.09 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env make
INPUT = $(HOME)/q/office/accounting/blais.beancount
DOWNLOADS = $(HOME)/u/Downloads
TOOLS=./tools
PYTHON ?= python3
PYLINT ?= $(PYTHON) -m pylint
LEX = flex
YACC = bison
YFLAGS = --report=itemset --verbose -Wall -Werror
GRAPHER = dot
# Support PYTHON being the path to a python interpreter.
PYVERSION = $(shell $(PYTHON) -c 'import platform; print(".".join(platform.python_version_tuple()[:2]))')
PYCONFIG = "python$(PYVERSION)-config"
CFLAGS += $(shell $(PYCONFIG) --cflags) -I$(PWD) -fPIE -UNDEBUG -Wno-unused-function -Wno-unused-variable
LDFLAGS += $(shell $(PYCONFIG) --embed --ldflags)
LDLIBS += $(shell $(PYCONFIG) --embed --libs)
all: build
# Clean everything up.
clean:
rm -f core
rm -rf build
rm -f $(CROOT)/grammar.h $(CROOT)/grammar.c
rm -f $(CROOT)/lexer.h $(CROOT)/lexer.c
rm -f $(CROOT)/*.so
rm -f $(CROOT)/tokens_test
find . -name __pycache__ -exec rm -r "{}" \; -prune
# Targets to generate and compile the C parser.
CROOT = beancount/parser
$(CROOT)/grammar.c $(CROOT)/grammar.h: $(CROOT)/grammar.y
$(YACC) $(YFLAGS) -o $(CROOT)/grammar.c $<
$(CROOT)/lexer.c $(CROOT)/lexer.h: $(CROOT)/lexer.l $(CROOT)/grammar.h
$(LEX) --outfile=$(CROOT)/lexer.c --header-file=$(CROOT)/lexer.h $<
SOURCES = \
$(CROOT)/decimal.c \
$(CROOT)/decimal.h \
$(CROOT)/lexer.c \
$(CROOT)/lexer.h \
$(CROOT)/grammar.c \
$(CROOT)/grammar.h \
$(CROOT)/macros.h \
$(CROOT)/tokens.h
.PHONY: build
build: $(SOURCES)
$(PYTHON) setup.py build_ext -i
$(CROOT)/tokens_test: $(CROOT)/tokens_test.o $(CROOT)/tokens.o $(CROOT)/decimal.o
.PHONY: ctest
ctest: $(CROOT)/tokens_test
$(CROOT)/tokens_test
build35: $(SOURCES)
python3.5 setup.py build_ext -i
# Dump the lexer parsed output. This can be used to check across languages.
dump_lexer:
bean-dump-lexer $(INPUT)
# Check for memory leaks.
grind:
valgrind --leak-check=full $(PYTHON) bean-sandbox $(INPUT)
# Regenerate the website.
html docs:
projects docs beancount
# Compute and plot inter-module dependencies.
# We want to insure a really strict set of relationships between the modules,
# and this is the high-level picture.
build/beancount.deps:
sfood -i bin beancount > $@
CLUSTERS_REGEXPS = \
beancount/core/.*_test\.py core/tests \
beancount/core core \
beancount/ops/.*_test\.py ops/tests \
beancount/ops ops \
beancount/parser/printer_test\.py printer/tests \
beancount/parser/printer.py printer \
beancount/parser/options_test\.py options/tests \
beancount/parser/options.py options \
beancount/parser/.*_test\.py parser/tests \
beancount/parser parser \
beancount/plugins/.*_test\.py plugins/tests \
beancount/plugins plugins \
beancount/reports/.*_test\.py reports/tests \
beancount/reports reports \
beancount/scripts/bake.*_test\.py scripts/bake/tests \
beancount/scripts/bake.* scripts/bake \
beancount/scripts/.*_test\.py scripts/tests \
beancount/scripts scripts \
beancount/utils/.*_test\.py utils/tests \
beancount/utils utils \
beancount/web/.*_test\.py web/tests \
beancount/web web \
beancount/load.*_test\.py load/tests \
beancount/load.*\.py load \
beancount load
build/beancount.pdf: build/beancount.deps
cat $< | sfood-cluster-regexp $(CLUSTERS_REGEXPS) | grep -v /tests | sfood-graph | $(GRAPHER) -Tps | ps2pdf - $@
evince $@
build/beancount_tests.pdf: build/beancount.deps
cat $< | sfood-cluster-regexp $(CLUSTERS_REGEXPS) | sfood-graph | $(GRAPHER) -Tps | ps2pdf - $@
evince $@
# Compute ahd plot the dependencies within the core.
# We are considering a separation of the basic data structure and the basic operations.
# This provides the detail of the relationships between these sets of fils.
build/beancount-core.pdf: build/beancount-core.deps
sfood -ii beancount/core/*.py | sfood-graph | $(GRAPHER) -Tps | ps2pdf - $@
showdeps-core: build/beancount-core.pdf
evince $<
# Run in the debugger.
debug:
gdb --args $(PYTHON) /home/blais/p/beancount/bin/bean-sandbox $(INPUT)
# Bake a release, upload the source.
release:
rm -rf dist
python3 setup.py sdist bdist_wheel
python3.10 setup.py bdist_egg
python3.9 setup.py bdist_egg
twine upload dist/*.tar.gz dist/*.egg
vtest vtests verbose-test verbose-tests:
$(PYTHON) -m pytest -v -s beancount examples
qtest qtests quiet-test quiet-tests test tests:
$(PYTHON) -m pytest beancount
test-last test-last-failed test-failed:
$(PYTHON) -m pytest --last-failed beancount
test-naked:
PATH=/bin:/usr/bin PYTHONPATH= $(PYTHON) -m pytest -x beancount
# Run the parser and measure its performance.
.PHONY: check
check:
bean-check $(INPUT)
# Run the demo program.
demo:
bin/bean-web --debug examples/demo.beancount
# Generate the example file.
EXAMPLE=examples/example.beancount
example $(EXAMPLE):
./bin/bean-example --seed=0 -o $(EXAMPLE)
# Run the web server.
.PHONY: web
web:
bean-web --debug $(INPUT)
.PHONY: web-incognito
web-incognito:
bean-web --incognito --debug $(INPUT)
# Run the importer.
.PHONY: import
import:
bean-import $(INPUT) $(DOWNLOADS)
# My development sandbox script. This is messy and it's okay.
.PHONY: sandbox
sandbox:
bean-sandbox $(INPUT)
missing-tests:
$(TOOLS)/find_missing_tests.py beancount
fixmes:
egrep -srn '\b(FIXME|TODO\()' beancount || true
filter-terms:
egrep --exclude-dir='.hg' --exclude-dir='__pycache__' -srn 'GOOGL?\b' $(PWD) | grep -v GOOGLE_APIS || true
multi-imports:
(egrep -srn '^(from.*)?import.*,' beancount | grep -v 'from typing') || true
# Check for unused imports.
sfood-checker:
sfood-checker bin beancount
# Check dependency constraints.
constraints dep-constraints: build/beancount.deps
$(TOOLS)/dependency_constraints.py $<
# Run the linter on all source code.
# To list all messages, call: "pylint --list-msgs"
LINT_SRCS = \
beancount \
bin/* \
tools/*.py
pylint lint:
$(PYLINT) $(LINT_SRCS)
LINT_TESTS=useless-suppression,empty-docstring
pylint-only:
$(PYLINT) --disable=all --enable=$(LINT_TESTS) $(LINT_SRCS)
pyflakes:
pyflakes $(LINT_SRCS)
ruff:
ruff beancount examples/ingest/office/importers tools
# Check everything.
status check: pylint pyflakes filter-terms missing-tests dep-constraints multi-imports test
# Experimental docs conversion.
download-pdf:
./tools/download_docs.py pdf $(HOME)/p/beancount-downloads/pdf
download-odt:
./tools/download_docs.py odt $(HOME)/p/beancount-downloads/odt
sphinx sphinx_odt2rst:
./tools/sphinx_odt2rst.py $(HOME)/p/beancount-downloads/odt $(HOME)/p/beancount-docs
convert_test:
./tools/convert_doc.py --cache=/tmp/convert_test.cache '1WjARst_cSxNE-Lq6JnJ5CC41T3WndEsiMw4d46r2694' /tmp/trading.md
# This does not work well; import errors just won't go away, it's slow, and it
# seems you have to pregenerate all .pyi to do anything useful.
pytype:
find $(PWD)/beancount -name '*.py' | parallel -j16 pytype --pythonpath=$(PWD) -o {}i {}
pytype1:
pytype --pythonpath=$(PWD) beancount/utils/net_utils.py
links bazel-link:
rm -f beancount/parser/_parser.so
ln -s -f ../../bazel-bin/beancount/parser/_parser.so beancount/parser/_parser.so
ln -s -f ../../bazel-bin/beancount/cparser/extmodule.so beancount/cparser/extmodule.so