-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
115 lines (88 loc) · 3.2 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
all: venv
# define the name of the virtual environment directory
VENV=myenv
$(VENV)/bin/activate: requirements.txt
python3 -m venv $(VENV)
./$(VENV)/bin/pip install -r requirements.txt
# env is a shortcut target
venv: $(VENV)/bin/activate
COVRUN=coverage run -a --source=. --omit=setup.py
envset:
test -n "$$VIRTUAL_ENV" || (echo "Python env is not activated" && false)
check: envset flake8 ruff test
test: envset
PYTHONPATH=. pytest --mpl --cov=nemo --doctest-modules
coverage: replay.json replay-noscenario.json replay-nocost.json
$(COVRUN) evolve --list-scenarios > /dev/null
# these tests are needed because we need to control external
# environment variables
NEMORC=nemo.cfg $(COVRUN) evolve -g1 -s __one_ccgt__ > /dev/null
unset NEMORC && $(COVRUN) evolve -g1 -s __one_ccgt__ > /dev/null
unset DISPLAY && $(COVRUN) evolve -g1 -s __one_ccgt__ > /dev/null
if test -f trace.out; then rm trace.out; fi
$(COVRUN) evolve -v --lambda 2 -g1 -s __one_ccgt__ \
--trace-file=trace.out --emissions-limit=0 \
--fossil-limit=0.1 --reserves=1000 \
--reliability-std=0.002 --min-regional-generation=0.5 > /dev/null
test -f trace.out && rm trace.out
$(COVRUN) replay -f replay.json -v -v > /dev/null
$(COVRUN) replay -f replay-noscenario.json -v > /dev/null || true
$(COVRUN) replay -f replay-nocost.json -v > /dev/null || true
$(COVRUN) evolve -g1 -s __one_ccgt__ -p > /dev/null
$(COVRUN) evolve -g1 -s __one_ccgt__ > output.txt
$(COVRUN) summary < output.txt
$(COVRUN) replay -p -f replay.json > /dev/null
rm results.json output.txt
rm replay.json replay-noscenario.json replay-nocost.json
make html
.PHONY: html
html:
coverage html
replay.json:
printf "# %s\n%s\n\n" "comment line" "malformed line" >> $@
printf '{"options": {"carbon_price": 0, "ccs_storage_costs": 27, "gas_price": 11,' >> $@
printf ' "coal_price": 2, "costs": "Null", "discount_rate": 0.05, "supply_scenario": "__one_ccgt__",' >> $@
printf ' "nsp_limit": 0.75, "parameters": [1]}\n' >> $@
replay-noscenario.json: replay.json
sed 's/__one_ccgt__/noexist/' < $< > $@
replay-nocost.json: replay.json
sed 's/Null/noexist/' < $< > $@
stub.py:
printf 'import nemo\n' > $@
printf 'c = nemo.Context()\n' >> $@
printf 'nemo.run(c)\n' >> $@
nemo.prof: stub.py
python3 -m cProfile -o $@ $<
prof: nemo.prof
snakeviz $<
lineprof: stub.py
kernprof -v -l stub.py
LINTSRC=evolve replay summary $(wildcard *.py awklite/*.py nemo/*.py nemo/costs/*.py tests/*.py)
flake8: envset
flake8 $(LINTSRC) --ignore=N801
ruff: envset
ruff check --select ALL \
--ignore=I001,D203,D213,Q000,ARG002,T201,ANN,N801,SLF,PLR,PT,INP \
--output-format=concise $(LINTSRC)
pylint:
pylint --enable=useless-suppression $(LINTSRC)
lint: envset flake8 ruff pylint
codespell -d -L assertin,fom,hsa,trough,harge $(LINTSRC) || true
isort --check $(LINTSRC)
pylama $(LINTSRC)
-vulture --min-confidence=70 $(LINTSRC)
bandit -qq -s B101 $(LINTSRC)
pydocstyle $(LINTSRC)
coveralls:
coveralls
dist:
python3 setup.py sdist bdist_wheel
upload: dist
twine upload dist/*
pdoc:
pdoc3 --force --html nemo
clean:
-rm -r dist build *.egg-info
-rm -r .coverage htmlcov
-rm replay.json replay-noscenario.json replay-nocost.json
-rm *.pyc tests/*.pyc nemo.prof stub.py stub.py.lprof