This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
380 lines (329 loc) · 10.6 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# Make uses /bin/sh by default, but we are using some bash features. On Ubuntu
# /bin/sh is POSIX compliant, ie it's not bash. So let's be explicit:
SHELL=/bin/bash
# Black magic to get module directories
PYTHON_MODULES := $(foreach initpy, $(foreach dir, $(wildcard lib/*), $(wildcard $(dir)/__init__.py)), $(realpath $(dir $(initpy))))
# Configure Black to support only syntax supported by the minimum supported Python version in setup.py.
BLACK=black --target-version=py36
.PHONY: help
help:
@# Magic line used to create self-documenting makefiles.
@# See https://stackoverflow.com/a/35730928
@awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' Makefile | column -s: -t
.PHONY: all
# Get dependencies, build frontend, install Streamlit into Python environment.
all: init frontend install
.PHONY: all-devel
# Get dependencies and install Streamlit into Python environment -- but do not build the frontend.
all-devel: init develop
@echo ""
@echo " The frontend has *not* been rebuilt."
@echo " If you need to make a wheel file or test S3 sharing, run:"
@echo ""
@echo " make frontend"
@echo ""
.PHONY: mini-devel
# Get minimal dependencies and install Streamlit into Python environment -- but do not build the frontend.
mini-devel: mini-init develop
.PHONY: init
# Install all Python and JS dependencies.
init: setup pipenv-install react-init scssvars protobuf
.PHONY: mini-init
# Install minimal Python and JS dependencies for development.
mini-init: setup pipenv-dev-install react-init scssvars protobuf
.PHONY: frontend
# Build frontend into static files.
frontend: react-build
.PHONY: setup
setup:
pip install pip-tools pipenv black ;
.PHONY: pipenv-install
pipenv-install: pipenv-dev-install pipenv-test-install
.PHONY: pipenv-dev-install
pipenv-dev-install: lib/Pipfile
# Run pipenv install; don't update the Pipfile.lock.
# We use `--sequential` here to ensure our results are...
# "more deterministic", per pipenv's documentation.
# (Omitting this flag is causing incorrect dependency version
# resolution on CircleCI.)
cd lib; \
pipenv install --dev --skip-lock --sequential
.PHONY: pipenv-test-install
pipenv-test-install: lib/test-requirements.txt
# Installing from a requirements file copies the packages into
# the Pipfile so we revert these changes after the install.
cd lib ; \
cp Pipfile Pipfile.bkp ; \
pipenv install --dev --skip-lock --sequential -r test-requirements.txt ; \
mv Pipfile.bkp Pipfile
.PHONY: pylint
# Run "black", our Python formatter, to verify that our source files
# are properly formatted. Does not modify any files. Returns with a non-zero
# status if anything is not properly formatted. (This isn't really
# "linting"; we're not checking anything but code style.)
pylint:
if command -v "black" > /dev/null; then \
$(BLACK) --check docs/ ; \
$(BLACK) --check examples/ ; \
$(BLACK) --check lib/streamlit/ --exclude=/*_pb2.py$/ ; \
$(BLACK) --check lib/tests/ ; \
$(BLACK) --check e2e/scripts/ ; \
fi
.PHONY: pyformat
# Run "black", our Python formatter, to fix any source files that are not
# properly formatted.
pyformat:
if command -v "black" > /dev/null; then \
$(BLACK) docs/ ; \
$(BLACK) examples/ ; \
$(BLACK) lib/streamlit/ --exclude=/*_pb2.py$/ ; \
$(BLACK) lib/tests/ ; \
$(BLACK) e2e/scripts/ ; \
fi
.PHONY: pytest
# Run Python unit tests.
pytest:
# Just testing. No code coverage.
cd lib; \
PYTHONPATH=. \
pytest -v \
--junitxml=test-reports/pytest/junit.xml \
-l tests/ \
$(PYTHON_MODULES)
.PHONY: pycoverage
# Show Python test coverage.
pycoverage:
# testing + code coverage
cd lib; \
PYTHONPATH=. \
pytest -v \
--junitxml=test-reports/pytest/junit.xml \
-l $(foreach dir,$(PYTHON_MODULES),--cov=$(dir)) \
--cov-report=term-missing tests/ \
$(PYTHON_MODULES)
.PHONY: pycoverage_html
# Generate HTML report of Python test coverage.
pycoverage_html:
# testing + code coverage
cd lib; \
PYTHONPATH=. \
pytest -v \
--junitxml=test-reports/pytest/junit.xml \
-l $(foreach dir,$(PYTHON_MODULES),--cov=$(dir)) \
--cov-report=html tests/ \
$(PYTHON_MODULES)
.PHONY: mypy
# Run Mypy static type checker.
mypy:
./scripts/mypy
.PHONY: integration-tests
# Run Python integration tests. Currently, this is just a script that runs
# all the e2e tests in "bare" mode and checks for non-zero exit codes.
integration-tests:
python scripts/run_bare_integration_tests.py
.PHONY: install
# Install Streamlit into your Python environment.
install:
cd lib ; python setup.py install
.PHONY: develop
# Install Streamlit as links in your Python environment, pointing to local workspace.
develop:
cd lib ; python setup.py develop
.PHONY: wheel
# Create a Python wheel file in dist/.
wheel:
# Get rid of the old build folder to make sure that we delete old js and css.
rm -rfv lib/build
cd lib ; python setup.py bdist_wheel --universal
# cd lib ; python setup.py bdist_wheel sdist
.PHONY: package
# Create a Python wheel file in dist/.
package: mini-devel frontend install wheel
.PHONY: clean
# Remove all generated files.
clean: clean-docs
cd lib; rm -rf build dist .eggs *.egg-info
find . -name '*.pyc' -type f -delete || true
find . -name __pycache__ -type d -delete || true
find . -name .pytest_cache -exec rm -rfv {} \; || true
rm -rf .mypy_cache
rm -f lib/streamlit/proto/*_pb2.py*
rm -rf lib/streamlit/static
rm -f lib/Pipfile.lock
rm -rf frontend/build
rm -rf frontend/node_modules
rm -f frontend/src/autogen/proto.js
rm -f frontend/src/autogen/proto.d.ts
rm -f frontend/src/autogen/scssVariables.ts
rm -rf frontend/public/reports
find . -name .streamlit -type d -exec rm -rfv {} \; || true
cd lib; rm -rf .coverage .coverage\.*
.PHONY: clean-docs
# Remove all generated files from the docs folder.
clean-docs:
cd docs; \
make distclean
.PHONY: docs
# Generate HTML documentation at /docs/_build.
docs: clean-docs
mkdir -p docs/_static/css
cd docs; \
make html; \
python replace_vars.py css/custom.css _static/css/custom.css
.PHONY: devel-docs
# Build docs and start a test server at port 8000.
devel-docs: docs
cd docs/_build/html; \
python -m http.server 8000
.PHONY: protobuf
# Recompile Protobufs for Python and Javascript.
protobuf:
@# Python protobuf generation
protoc \
--proto_path=proto \
--python_out=lib \
--mypy_out=lib \
proto/streamlit/proto/*.proto
@# Create a folder for autogenerated files
mkdir -p frontend/src/autogen
@# JS protobuf generation. The --es6 flag generates a proper es6 module.
cd frontend/ ; ( \
echo "/* eslint-disable */" ; \
echo ; \
./node_modules/protobufjs/bin/pbjs \
../proto/streamlit/proto/*.proto \
-t static-module --es6 \
) > ./src/autogen/proto.js
@# Typescript type declarations for our generated protobufs
cd frontend/ ; ( \
echo "/* eslint-disable */" ; \
echo ; \
./node_modules/protobufjs/bin/pbts ./src/autogen/proto.js \
) > ./src/autogen/proto.d.ts
.PHONY: react-init
react-init:
cd frontend/ ; yarn install --frozen-lockfile
.PHONY: react-build
react-build:
cd frontend/ ; yarn run build
rsync -av --delete --delete-excluded --exclude=reports \
frontend/build/ lib/streamlit/static/
# If you're debugging sharing, you may want to comment this out so that
# sourcemaps exist.
find lib/streamlit/static -type 'f' -iname '*.map' | xargs rm -fv
.PHONY: scssvars
# Generate frontend/src/autogen/scssVariables.ts, which has SCSS variables that we can use in TS.
scssvars: react-init
mkdir -p frontend/src/autogen
cd frontend ; ( \
echo "export const SCSS_VARS = " ; \
yarn run --silent scss-to-json src/assets/css/variables.scss \
) > src/autogen/scssVariables.ts
.PHONY: jslint
# Lint the JS code. Saves results to test-reports/eslint/eslint.xml.
jslint:
@# max-warnings 0 means we'll exit with a non-zero status on any lint warning
ifndef CIRCLECI
cd frontend; \
./node_modules/.bin/eslint \
--ext .js \
--ext .jsx \
--ext .ts \
--ext .tsx \
--ignore-pattern 'src/autogen/*' \
--max-warnings 0 \
./src
else
cd frontend; \
./node_modules/.bin/eslint \
--ext .js \
--ext .jsx \
--ext .ts \
--ext .tsx \
--ignore-pattern 'src/autogen/*' \
--max-warnings 0 \
--format junit \
--output-file test-reports/eslint/eslint.xml \
./src
endif #CIRCLECI
.PHONY: jsformat
# Runs "Prettier" on our JavaScript and TypeScript code to fix formatting
# issues.
jsformat:
yarn --cwd "frontend" pretty-quick \
--pattern "**/*.*(js|jsx|ts|tsx)"
.PHONY: jstest
# Run JS unit tests.
jstest:
ifndef CIRCLECI
cd frontend; yarn run test
else
# Use --runInBand on CircleCI, per
# https://jestjs.io/docs/en/troubleshooting#tests-are-extremely-slow-on-docker-andor-continuous-integration-ci-server
cd frontend; yarn run test --runInBand
endif
.PHONY: jscoverage
# Run JS unit tests and generate a coverage report
jscoverage:
cd frontend; yarn run test --coverage --watchAll=false
.PHONY: e2etest
# Run E2E tests.
e2etest:
./scripts/run_e2e_tests.py
.PHONY: loc
# Counts the number of lines of code in the project
loc:
find . -iname '*.py' -or -iname '*.js' | \
egrep -v "(node_modules)|(_pb2)|(lib\/streamlit\/proto)|(dist\/)" | \
xargs wc
.PHONY: distribute
# Distributes the package to PyPi
distribute:
cd lib/dist; \
twine upload $$(ls -t *.whl | head -n 1)
.PHONY: notices
# Rebuild the NOTICES file.
notices:
cd frontend; \
yarn licenses generate-disclaimer --silent --production > ../NOTICES
# NOTE: This file may need to be manually edited. Look at the Git diff and
# the parts that should be edited will be obvious.
./scripts/append_license.sh frontend/src/assets/font/IBM_Plex_Fonts.LICENSE
./scripts/append_license.sh frontend/src/assets/img/Material-Icons.LICENSE
./scripts/append_license.sh frontend/src/assets/img/Noto-Emoji-Font.LICENSE
./scripts/append_license.sh frontend/src/assets/img/Open-Iconic.LICENSE
.PHONY: headers
# Update the license header on all source files.
headers:
./scripts/add_license_headers.py \
lib/streamlit \
lib/tests \
e2e/scripts \
e2e/specs \
frontend/src \
frontend/public \
proto \
examples \
scripts
.PHONY: build-circleci
# Build docker image that mirrors circleci
build-circleci:
docker build -t streamlit_circleci -f e2e/Dockerfile .
.PHONY: run-circleci
# Run circleci image with volume mounts
run-circleci:
mkdir -p frontend/mochawesome-report
docker-compose \
-f e2e/docker-compose.yml \
run \
--rm \
--name streamlit_circleci \
streamlit
.PHONY: connect-circleci
# Connect to running circleci container
connect-circleci:
docker exec -it streamlit_circleci /bin/bash
.PHONY: flake8
# Run flake8 and show errors: E9,F63,F7,F82
flake8:
scripts/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=./frontend,./lib/build