-
Notifications
You must be signed in to change notification settings - Fork 151
/
Makefile
816 lines (687 loc) · 32.4 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
SHELL:=$(shell /usr/bin/env which bash)
DEV_DOCKER_IMG:=concrete-ml-dev
DEV_DOCKERFILE:=docker/Dockerfile.dev
DEV_CONTAINER_VENV_VOLUME:=concrete-ml-venv
DEV_CONTAINER_CACHE_VOLUME:=concrete-ml-cache
DOCKER_VENV_PATH:="$${HOME}"/dev_venv/
SRC_DIR:=src
CONCRETE_PACKAGE_PATH=$(SRC_DIR)/concrete
COUNT?=1
RANDOMLY_SEED?=$$RANDOM
PYTEST_OPTIONS:=
POETRY_VERSION:=1.2.2
APIDOCS_OUTPUT?="./docs/developer-guide/api"
OPEN_PR="true"
# If one wants to force the installation of a given rc version
# /!\ WARNING /!\: This version should NEVER be a wildcard as it might create some
# issues when trying to run it in the future.
CP_VERSION_SPEC_FOR_RC="concrete-python==2.2.0"
# If one wants to use the last RC version
# CP_VERSION_SPEC_FOR_RC="$$(poetry run python \
# ./script/make_utils/pyproject_version_parser_helper.py \
# --pyproject-toml-file pyproject.toml \
# --get-pip-install-spec-for-dependency concrete-python)"
.PHONY: setup_env # Set up the environment
setup_env:
@# The keyring install is to allow pip to fetch credentials for our internal repo if needed
PIP_INDEX_URL=https://pypi.org/simple \
PIP_EXTRA_INDEX_URL=https://pypi.org/simple \
poetry run python --version
poetry run python -m pip install keyring
poetry run python -m pip install -U pip wheel
@# Only for linux and docker, reinstall setuptools. On macOS, it creates warnings, see 169
if [[ $$(uname) != "Darwin" ]]; then \
poetry run python -m pip install -U --force-reinstall setuptools; \
fi
if [[ $$(uname) != "Linux" ]] && [[ $$(uname) != "Darwin" ]]; then \
poetry install --only dev; \
else \
poetry install; \
fi
echo "Installing $(CP_VERSION_SPEC_FOR_RC)" && \
poetry run python -m pip install -U --pre "$(CP_VERSION_SPEC_FOR_RC)" --no-deps
.PHONY: sync_env # Synchronise the environment
sync_env: check_poetry_version
if [[ $$(uname) != "Linux" ]] && [[ $$(uname) != "Darwin" ]]; then \
poetry install --remove-untracked --only dev; \
else \
poetry install --remove-untracked; \
fi
"$(MAKE)" setup_env
.PHONY: update_env # Same as sync_env, sets the venv state to be synced with the rpo
update_env: sync_env
.PHONY: reinstall_env # Remove venv and reinstall
reinstall_env:
@VENV_SCRIPT_PATH=bin && \
if [[ $$(uname) != "Linux" && $$(uname) != "Darwin" ]]; then \
VENV_SCRIPT_PATH="Scripts"; \
fi && \
if [[ "$${VIRTUAL_ENV}" != "" ]]; then \
echo "Please deactivate the current venv first."; \
else \
VENV_PATH=$$(./script/make_utils/remove_venv.sh); \
SOURCE_VENV_PATH="$${VENV_PATH}$${VENV_SCRIPT_PATH}/activate"; \
python3 -m venv "$${VENV_PATH}"; \
source "$${SOURCE_VENV_PATH}"; \
"$(MAKE)" setup_env; \
echo "Source venv with:"; \
echo "source $${SOURCE_VENV_PATH}"; \
fi
.PHONY: check_poetry_version # Check poetry's version
check_poetry_version:
if [[ $$(poetry --version) == "Poetry (version $(POETRY_VERSION))" ]];then \
echo "Poetry version is ok";\
else\
echo "Expected poetry version is not the expected one: $(POETRY_VERSION)"\
exit 1;\
fi
.PHONY: python_format # Apply python formatting
python_format:
poetry run env bash ./script/source_format/format_python.sh \
--dir $(SRC_DIR) --dir tests --dir benchmarks --dir script --dir docker/release_resources \
--dir use_case_examples --file conftest.py
.PHONY: check_python_format # Check python format
check_python_format:
poetry run env bash ./script/source_format/format_python.sh \
--dir $(SRC_DIR) --dir tests --dir benchmarks --dir script --dir docker/release_resources \
--dir use_case_examples --file conftest.py \
--check
.PHONY: check_finalize_nb # Check sanitization of notebooks
check_finalize_nb:
poetry run python ./script/nbmake_utils/notebook_finalize.py docs --check &
poetry run python ./script/nbmake_utils/notebook_finalize.py use_case_examples --check
.PHONY: pylint # Run pylint
pylint:
"$(MAKE)" --keep-going pylint_src pylint_tests pylint_script pylint_benchmarks
.PHONY: pylint_src # Run pylint on sources
pylint_src:
poetry run pylint --rcfile=pylintrc $(SRC_DIR)
.PHONY: pylint_tests # Run pylint on tests
pylint_tests:
@# Disable duplicate code detection (R0801) in tests
@# Disable unnecessary lambda (W0108) for tests
@# Disable ungrouped-imports (C0412) because pylint does mistakes between our package and CP
find ./tests/ -type f -name "*.py" | xargs poetry run pylint --disable=R0801,W0108,C0412 \
--rcfile=pylintrc
poetry run pylint --disable=R0801,W0108,C0412 conftest.py \
--rcfile=pylintrc
.PHONY: pylint_benchmarks # Run pylint on benchmarks
pylint_benchmarks:
@# Disable duplicate code detection (R0801) in benchmarks
@# Disable duplicate code detection, docstring requirement, too many locals/statements
@# Disable ungrouped-imports (C0412) because pylint does mistakes between our package and CP
find ./benchmarks/ -type f -name "*.py" | xargs poetry run pylint \
--disable=R0801,R0914,R0915,C0103,C0114,C0115,C0116,C0302,W0108,C0412 --rcfile=pylintrc
.PHONY: pylint_script # Run pylint on scripts
pylint_script:
find ./script/ -type f -name "*.py" | xargs poetry run pylint --rcfile=pylintrc
find docker/release_resources -type f -name "*.py" | xargs poetry run pylint --rcfile=pylintrc
.PHONY: flake8 # Run flake8 (including darglint)
flake8:
poetry run flake8 --config flake8_src.cfg $(SRC_DIR) script/
@# --extend-ignore=DAR is because we don't want to run darglint on tests/ script/ benchmarks/
poetry run flake8 --config flake8_others.cfg tests/ script/ benchmarks/ \
docker/release_resources/ conftest.py
.PHONY: ruff # Run ruff
ruff:
poetry run ruff $(SRC_DIR) script tests conftest.py
.PHONY: ruff # Run ruff fix
fix_ruff:
poetry run ruff $(SRC_DIR) tests script --fix
.PHONY: python_linting # Run python linters
python_linting: ruff pylint flake8
.PHONY: conformance # Run command to fix some conformance issues automatically
conformance: finalize_nb python_format licenses nbqa supported_ops mdformat
.PHONY: check_issues # Run command to check if all referenced issues are opened
check_issues:
python ./script/make_utils/check_issues.py
# We need to launch forbidden words aftwerwards because of conflicts with the files created by nbqa
# https://nbqa.readthedocs.io/en/latest/known-limitations.html#known-limitations
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3516
.PHONY: pcc # Run pre-commit checks
pcc:
@"$(MAKE)" --keep-going --jobs $$(./script/make_utils/ncpus.sh) --output-sync=recurse \
--no-print-directory pcc_internal
@"$(MAKE)" check_forbidden_words
.PHONY: spcc # Run selected pre-commit checks (those which break most often, for SW changes)
spcc:
@"$(MAKE)" --keep-going --jobs $$(./script/make_utils/ncpus.sh) --output-sync=recurse \
--no-print-directory spcc_internal
PCC_DEPS := check_python_format check_finalize_nb python_linting mypy_ci pydocstyle shell_lint
PCC_DEPS += check_version_coherence check_licenses check_nbqa check_supported_ops
PCC_DEPS += check_refresh_notebooks_list check_mdformat
PCC_DEPS += check_unused_images check_utils_use_case gitleaks
.PHONY: pcc_internal
pcc_internal: $(PCC_DEPS)
# flake8 has been removed since it is too slow
SPCC_DEPS := check_python_format pylint_src pylint_tests mypy mypy_test pydocstyle ruff
.PHONY: spcc_internal
spcc_internal: $(SPCC_DEPS)
# One can reproduce pytest thanks to the --randomly-seed option from pytest-randomly
# To repeat a single test, apply something like @pytest.mark.repeat(3) on the test function
# -n Const because most tests include parallel execution using all CPUs, too many
# parallel tests would lead to contention. Thus Const is set to something much lower than num_cpus
# --durations=10 is to show the 10 slowest tests
# --capture=tee-sys is to make sure that, in case of crash, we can search for "Forcing seed to" in
# stdout in order to be able to reproduce the failed test using that seed
# --global-coverage-infos-json=global-coverage-infos.json is to dump the coverage report in the file
# --cov PATH is the directory PATH to consider for coverage
# --randomly-dont-reorganize is to prevent Pytest from shuffling the tests' order
# --cov-report=term-missing:skip-covered is used to print the missing lines for coverage withtout
# taking into account skiped tests
# --count N is to repeate all tests N times (with different seeds). Default is to 1.
# --randomly-dont-reset-seed is to make sure that, if we run the same test several times (with
# @pytest.mark.repeat(3)), different seeds are used, even if things are still deterministic using
# the main seed
# --cache-clear is to clear all Pytest's cache at before running the tests. This is done in order to prevent inconsistencies
# when running pytest several times in a row (for example, in the CI)
.PHONY: pytest # Run pytest on all tests
pytest:
poetry run pytest --version
poetry run pytest tests/ \
-svv \
-n 4 \
--durations=10 \
--capture=tee-sys \
--global-coverage-infos-json=global-coverage-infos.json \
--cov=$(SRC_DIR) \
--cov-fail-under=100 \
--randomly-dont-reorganize \
--cov-report=term-missing:skip-covered \
--count=$(COUNT) \
--randomly-dont-reset-seed \
--cache-clear \
${PYTEST_OPTIONS}
.PHONY: pytest_one # Run pytest on a single file or directory (TEST) a certain number of times (COUNT)
pytest_one:
poetry run pytest \
-svv \
-n $$(./script/make_utils/ncpus.sh) \
--durations=10 \
--capture=tee-sys \
--randomly-dont-reorganize \
--count=$(COUNT) \
--randomly-dont-reset-seed \
--cache-clear \
${PYTEST_OPTIONS} \
"$${TEST}"
.PHONY: pytest_one_single_cpu # Run pytest on a single file or directory (TEST) with a single CPU with RANDOMLY_SEED seed
# Don't set --durations=10, because it is not reproducible and we use this target for determinism
# checks
pytest_one_single_cpu:
poetry run pytest \
-svv \
--capture=tee-sys \
--randomly-dont-reorganize \
--randomly-dont-reset-seed \
--cache-clear \
${PYTEST_OPTIONS} \
"$${TEST}" --randomly-seed=${RANDOMLY_SEED}
.PHONY: pytest_macOS_for_GitHub # Run pytest with some coverage options which are removed
# These options are removed since they look to fail on macOS for no obvious reason
# (see https://github.com/zama-ai/concrete-ml-internal/issues/1554)
pytest_macOS_for_GitHub:
poetry run pytest \
-svv \
-n 4 \
--durations=10 \
--capture=tee-sys \
--randomly-dont-reorganize \
--count=$(COUNT) \
--randomly-dont-reset-seed \
--cache-clear \
${PYTEST_OPTIONS}
.PHONY: check_current_flaky_tests # Print the current list of known flaky tests
check_current_flaky_tests:
echo "Skip the following known flaky tests (test file: number of skipped configs):"
poetry run pytest ./tests --collect-only -m flaky -qq
.PHONY: pytest_no_flaky # Run pytest but ignore known flaky issues (so no coverage as well)
pytest_no_flaky: check_current_flaky_tests
poetry run pytest --version
echo "Warning: known flaky tests are skipped and coverage is disabled"
poetry run pytest tests/ \
--durations=10 -svv \
--capture=tee-sys \
-n 4 \
--randomly-dont-reorganize \
--count=$(COUNT) \
--randomly-dont-reset-seed \
--no-flaky \
--cache-clear \
${PYTEST_OPTIONS}
# Runnning latest failed tests works by accessing pytest's cache. It is therefore recommended to
# call '--cache-clear' when calling the previous pytest run.
# The '--last-failed' option runs all last failed tests. In case there is none, the
# '--last-failed-no-failures none' option indicates pytest not to run anything (instead of running
# all tests over again)
.PHONY: pytest_run_last_failed # Run all failed tests from the previous pytest run
pytest_run_last_failed:
poetry run pytest ./tests --last-failed --last-failed-no-failures none
# Printing latest failed tests works by accessing pytest's cache. It is therefore recommended to
# call '--cache-clear' when calling the previous pytest run.
# The '--cache-show' option prints pytest's complete cache (cacehd tests, random_seed, ...). Last
# failed tests are found in the 'cache/lastfailed' section, which can be used to filter the output
.PHONY: pytest_get_last_failed # Get the list of last failed tests
pytest_get_last_failed:
poetry run pytest ./tests --cache-show cache/lastfailed
.PHONY: pytest_and_report # Run pytest and output the report in a JSON file
pytest_and_report:
"$(MAKE)" pytest \
PYTEST_OPTIONS="--json-report --json-report-file='pytest_report.json' --json-report-omit collectors log traceback streams warnings --json-report-indent=4"
# Not a huge fan of ignoring missing imports, but some packages do not have typing stubs
.PHONY: mypy # Run mypy
mypy:
poetry run mypy -p $(SRC_DIR) --ignore-missing-imports --implicit-optional --check-untyped-defs
# Friendly target to run mypy without ignoring missing stubs and still have errors messages
# Allows to see which stubs we are missing
.PHONY: mypy_ns # Run mypy (without ignoring missing stubs)
mypy_ns:
poetry run mypy -p $(SRC_DIR)
.PHONY: mypy_test # Run mypy on test files
mypy_test:
find ./tests/ -name "*.py" | xargs poetry run mypy --ignore-missing-imports --implicit-optional --check-untyped-defs
poetry run mypy conftest.py --ignore-missing-imports --check-untyped-defs
.PHONY: mypy_script # Run mypy on scripts
mypy_script:
find ./script/ -name "*.py" | xargs poetry run mypy --ignore-missing-imports --implicit-optional --check-untyped-defs
find ./docker/release_resources -name "*.py" | xargs poetry run mypy --ignore-missing-imports --implicit-optional --check-untyped-defs
.PHONY: mypy_benchmark # Run mypy on benchmark files
mypy_benchmark:
find ./benchmarks/ -name "*.py" | xargs poetry run mypy --ignore-missing-imports --implicit-optional --check-untyped-defs
# The plus indicates that make will be called by the command and allows to share the context with
# the parent make execution. We serialize calls to these targets as they may overwrite each others
# cache which can cause issues.
.PHONY: mypy_ci # Run all mypy checks for CI
mypy_ci:
"$(MAKE)" --keep-going mypy mypy_test mypy_script mypy_benchmark
.PHONY: docker_build # Build dev docker
docker_build:
BUILD_ARGS=; \
if [[ $$(uname) == "Linux" ]]; then \
BUILD_ARGS="--build-arg BUILD_UID=$$(id -u) --build-arg BUILD_GID=$$(id -g)"; \
fi; \
DOCKER_BUILDKIT=1 docker build $${BUILD_ARGS:+$$BUILD_ARGS} \
--pull -t $(DEV_DOCKER_IMG) -f $(DEV_DOCKERFILE) .
.PHONY: docker_rebuild # Rebuild docker
docker_rebuild: docker_clean_volumes
BUILD_ARGS=; \
if [[ $$(uname) == "Linux" ]]; then \
BUILD_ARGS="--build-arg BUILD_UID=$$(id -u) --build-arg BUILD_GID=$$(id -g)"; \
fi; \
DOCKER_BUILDKIT=1 docker build $${BUILD_ARGS:+$$BUILD_ARGS} \
--pull --no-cache -t $(DEV_DOCKER_IMG) -f $(DEV_DOCKERFILE) .
.PHONY: docker_start # Launch docker
docker_start:
EV_FILE="$$(mktemp tmp.docker.XXXX)" && \
poetry run env bash ./script/make_utils/generate_authenticated_pip_urls.sh "$${EV_FILE}" && \
echo "" >> "$${EV_FILE}" && \
export $$(cat "$${EV_FILE}" | xargs) && rm -f "$${EV_FILE}" && \
docker run --rm -it \
-p 8888:8888 \
--env DISPLAY=host.docker.internal:0 \
$${PIP_INDEX_URL:+--env "PIP_INDEX_URL=$${PIP_INDEX_URL}"} \
$${PIP_EXTRA_INDEX_URL:+--env "PIP_EXTRA_INDEX_URL=$${PIP_EXTRA_INDEX_URL}"} \
--volume /"$$(pwd)":/src \
--volume $(DEV_CONTAINER_VENV_VOLUME):/home/dev_user/dev_venv \
--volume $(DEV_CONTAINER_CACHE_VOLUME):/home/dev_user/.cache \
$(DEV_DOCKER_IMG) || rm -f "$${EV_FILE}"
.PHONY: docker_build_and_start # Docker build and start
docker_build_and_start: docker_build docker_start
.PHONY: docker_bas # Docker build and start
docker_bas: docker_build_and_start
.PHONY: docker_clean_volumes # Docker clean volumes
docker_clean_volumes:
docker volume rm -f $(DEV_CONTAINER_VENV_VOLUME)
docker volume rm -f $(DEV_CONTAINER_CACHE_VOLUME)
.PHONY: docker_cv # Docker clean volumes
docker_cv: docker_clean_volumes
.PHONY: docs # Build docs
docs: clean_docs check_docs_dollars
@# Rebuild the index from README.md, to have in the home of Sphinx a copy of README.md
echo " .. Warning, auto-generated by \`make docs\`, don\'t edit" > docs/index.rst
echo "" >> docs/index.rst
pandoc --from markdown --to rst docs/README.md >> docs/index.rst
@# To be sure there is a blank line at the end
echo "" >> docs/index.rst
cat docs/index.toc.txt >> docs/index.rst
@# Create _static if nothing is commited in it
mkdir -p docs/_static/
@# Generate the auto summary of documentations
@# Cannot do without specifying top module currently with sphinx-apidoc
poetry run sphinx-apidoc --implicit-namespaces -o docs/_apidoc $(CONCRETE_PACKAGE_PATH)
@# Doing a copy of docs, where we modify files
rm -rf docs-copy
cp -r docs docs-copy
@# Admonitions
./script/make_utils/sphinx_gitbook_admonitions.sh --gitbook_to_sphinx
@# Check that there is no more GitBook hint
! grep -r "hint style" docs-copy
@# Replace $$, $/$ and /$$ by $
./script/make_utils/fix_double_dollars_issues_with_mdformat.sh docs-copy --single_dollar
@# Fix not-compatible paths
./script/make_utils/fix_gitbook_paths.sh docs-copy
@# Fixing cardboard
poetry run python script/doc_utils/fix_gitbook_table.py --files docs-copy/getting-started/showcase.md
@# Docs
cd docs-copy && poetry run "$(MAKE)" html SPHINXOPTS='-W --keep-going'
@# Copy images from GitBook
cp docs/.gitbook/assets/*.png docs-copy/_build/html/_images
cp -r use_case_examples docs-copy/_build/
cp -r docs-copy/_build docs/
rm -rf docs-copy
@# Check links
"$(MAKE)" check_links
.PHONY: remove_5c_docs # Remove the ugly %5C that we have in the doc, due to management of _ with GitBook
remove_5c_docs:
sed -i "" -e "s@%5C_@_@g" docs/*.md docs/*/*.md docs/*/*/*.md
sed -i "" -e "s@%5C%5C@@g" docs/*.md docs/*/*.md docs/*/*/*.md
.PHONY: apidocs # Builds API docs
apidocs:
@# At release time, one needs to change --src-base-url (to be a public release/A.B.x branch)
./script/doc_utils/update_apidocs.sh "$(APIDOCS_OUTPUT)"
# Update our summary
./script/doc_utils/update_apidocs_files_in_SUMMARY.sh
"$(MAKE)" mdformat
.PHONY: check_apidocs # Check that API docs are ok and
check_apidocs:
@# Check nothing has changed
./script/doc_utils/check_apidocs.sh
.PHONY: clean_docs # Clean docs build directory
clean_docs:
rm -rf docs/_apidoc docs/_build
.PHONY: check_docs_dollars # Check that latex equations are enclosed by double dollar signs
check_docs_dollars:
# Find any isolated $ signs in the docs, except developer guide where
# some codeblocks will show bash examples
# Only double dollar signs $$ should be used in order to
# show properly in gitbook
./script/make_utils/check_double_dollars_in_doc.sh
.PHONY: open_docs # Launch docs in a browser
open_docs:
python3 -m webbrowser -t "file://${PWD}/docs/_build/html/index.html"
.PHONY: docs_and_open # Make docs and open them in a browser
docs_and_open: docs open_docs
.PHONY: pydocstyle # Launch syntax checker on source code documentation
pydocstyle:
@# From http://www.pydocstyle.org/en/stable/error_codes.html
poetry run pydocstyle $(SRC_DIR) --convention google --add-ignore=D1,D202 --add-select=D401
poetry run pydocstyle tests --convention google --add-ignore=D1,D202 --add-select=D401
poetry run pydocstyle conftest.py --convention google --add-ignore=D1,D202 --add-select=D401
.PHONY: finalize_nb # Sanitize notebooks
finalize_nb:
poetry run python ./script/nbmake_utils/notebook_finalize.py docs use_case_examples
# A warning in a package unrelated to the project made pytest fail with notebooks
# Run notebook tests without warnings as sources are already tested with warnings treated as errors
# We need to disable xdist with -n0 to make sure to not have IPython port race conditions
.PHONY: pytest_nb # Launch notebook tests
pytest_nb:
NOTEBOOKS=$$(find docs -name "*.ipynb" | grep -v _build | grep -v .ipynb_checkpoints || true) && \
if [[ "$${NOTEBOOKS}" != "" ]]; then \
echo "$${NOTEBOOKS}" | xargs poetry run pytest -svv \
--capture=tee-sys \
-n0 \
--randomly-dont-reorganize \
--count=$(COUNT) \
--randomly-dont-reset-seed -Wignore --nbmake; \
else \
echo "No notebook found"; \
fi
.PHONY: jupyter_open # Launch jupyter, to be able to choose notebook you want to run
jupyter_open:
./script/make_utils/jupyter.sh --open
.PHONY: jupyter_execute # Execute all jupyter notebooks sequentially and sanitize
jupyter_execute:
poetry run env ./script/make_utils/jupyter.sh --run_all_notebooks
"$(MAKE)" finalize_nb
.PHONY: jupyter_execute_one # Execute one jupyter notebook and sanitize
jupyter_execute_one:
poetry run env ./script/make_utils/jupyter.sh --run_notebook "$${NOTEBOOK}"
"$(MAKE)" finalize_nb
.PHONY: jupyter_execute_parallel # Execute all jupyter notebooks in parallel (on the same machine) and sanitize
jupyter_execute_parallel:
poetry run env ./script/make_utils/jupyter.sh --run_all_notebooks_parallel
"$(MAKE)" finalize_nb
.PHONY: refresh_notebooks_list # Refresh the list of notebooks currently available
refresh_notebooks_list:
poetry run python script/actions_utils/refresh_notebooks_list.py .github/workflows/refresh-one-notebook.yaml
.PHONY: check_refresh_notebooks_list # Check if the list of notebooks currently available hasn't change
check_refresh_notebooks_list:
poetry run python script/actions_utils/refresh_notebooks_list.py .github/workflows/refresh-one-notebook.yaml --check
.PHONY: release_docker # Build a docker release image
release_docker:
EV_FILE="$$(mktemp tmp.docker.XXXX)" && \
poetry run env bash ./script/make_utils/generate_authenticated_pip_urls.sh "$${EV_FILE}" && \
echo "" >> "$${EV_FILE}" && \
./docker/build_release_image.sh "$${EV_FILE}" && rm -f "$${EV_FILE}" || rm -f "$${EV_FILE}"
.PHONY: upgrade_py_deps # Upgrade python dependencies
upgrade_py_deps:
./script/make_utils/upgrade_deps.sh
.PHONY: pytest_codeblocks # Test code blocks using pytest in the documentation
pytest_codeblocks:
./script/make_utils/pytest_codeblocks.sh
.PHONY: pytest_codeblocks_pypi_wheel_cml # Test code blocks using the PyPI local wheel of Concrete ML
pytest_codeblocks_pypi_wheel_cml:
./script/make_utils/pytest_pypi_cml.sh --wheel "$(CP_VERSION_SPEC_FOR_RC)" --codeblocks
.PHONY: pytest_codeblocks_pip_cml # Test code blocks using PyPI Concrete ML
pytest_codeblocks_pip_cml:
./script/make_utils/pytest_pypi_cml.sh --codeblocks
.PHONY: pytest_codeblocks_one # Test code blocks using pytest in one file (TEST)
pytest_codeblocks_one:
./script/make_utils/pytest_codeblocks.sh --file "$${TEST}"
# From https://stackoverflow.com/a/63523300 for the find command
.PHONY: shell_lint # Lint all bash scripts
shell_lint:
@# grep -v "^\./\." is to avoid files in .hidden_directories
find . -type f -name "*.sh" | grep -v "^\./\." | \
xargs shellcheck
.PHONY: set_version # Generate a new version number and update all files with it accordingly
set_version:
@if [[ "$$VERSION" == "" ]]; then \
echo "VERSION env variable is empty. Please set to desired version."; \
exit 1; \
fi && \
poetry run python ./script/make_utils/version_utils.py set-version --version "$${VERSION}"
# By default, check that all files containing version have the same value. If a 'VERSION' value is
# given, check that it matches the version found in the files.
.PHONY: check_version_coherence # Check version coherence
check_version_coherence:
@if [[ "$$VERSION" == "" ]]; then \
poetry run python ./script/make_utils/version_utils.py check-version; \
else \
poetry run python ./script/make_utils/version_utils.py check-version --version "$${VERSION}"; \
fi
.PHONY: changelog # Generate a changelog
changelog: check_version_coherence
PROJECT_VER="$${poetry version --short}" && \
poetry run python ./script/make_utils/changelog_helper.py > "CHANGELOG_$${PROJECT_VER}.md"
.PHONY: show_scope # Show the accepted types and optional scopes (for git conventional commits)
show_scope:
@echo "Accepted types and optional scopes:"
@cat .github/workflows/continuous-integration.yaml | grep feat | grep pattern | cut -f 2- -d ":" | cut -f 2- -d " "
.PHONY: show_type # Show the accepted types and optional scopes (for git conventional commits)
show_type:show_scope
.PHONY: licenses # Generate the list of licenses of dependencies
licenses:
./script/make_utils/licenses.sh --cp_version "$(CP_VERSION_SPEC_FOR_RC)"
.PHONY: force_licenses # Generate the list of licenses of dependencies (force the regeneration)
force_licenses:
./script/make_utils/licenses.sh --cp_version "$(CP_VERSION_SPEC_FOR_RC)" --force_update
.PHONY: check_licenses # Check if the licenses of dependencies have changed
check_licenses:
@TMP_OUT="$$(mktemp)" && \
if ! poetry run env bash ./script/make_utils/licenses.sh --check \
--cp_version "$(CP_VERSION_SPEC_FOR_RC)" > "$${TMP_OUT}"; then \
cat "$${TMP_OUT}"; \
rm -f "$${TMP_OUT}"; \
echo "Error while checking licenses, see log above."; \
echo "Consider re-running 'make licenses'"; \
exit 1; \
else \
echo "Licenses check OK"; \
fi
.PHONY: check_licenses
.PHONY: help # Generate list of targets with descriptions
help:
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | expand -t30 | sort
.PHONY: pip_audit # Run pip-audit and check if there are known vulnerabilities in our dependencies
pip_audit:
poetry run pip-audit
.PHONY: pip_audit_use_cases # Run pip-audit and check if there are known vulnerabilities in our use-cases
pip_audit_use_cases:
@echo "Will study:"
@find ./use_case_examples -type f -name "*requirements.txt" -exec echo -r "{}" \;
@find ./use_case_examples -type f -name "*requirements.txt" -exec echo \; -exec echo "{}:" \; -exec poetry run pip-audit -r "{}" \;
.PHONY: clean_local_git # Tell the user how to delete local git branches, except main
clean_local_git:
@git fetch --all --prune
@echo "Consider doing: "
@echo
@# Don't consider deleting `main` or current branches
@git branch | grep -v "^*" | grep -v main | xargs echo "git branch -D "
@echo
@read -p "Do it now (y/N)? " -r; \
if [[ $$REPLY =~ ^[Yy] ]]; \
then \
git branch | grep -v "^*" | grep -v main | xargs git branch -D ; \
echo; \
git branch; \
fi
.PHONY: mdformat # Apply markdown formatting
# Remark we need to remove .md's in venv. Remark that we fix $$ problems with mdformat at the end
mdformat:
@# grep -v "^\./\." is to avoid files in .hidden_directories
find . -type f -name "*.md" | grep -v "^\./\." | xargs poetry run mdformat
@#Do ToC in the README
poetry run mdformat README.md
@# Because mdformat modifies $$, which GitBook really wants. Make $$ back
./script/make_utils/fix_double_dollars_issues_with_mdformat.sh docs
.PHONY: check_mdformat # Check markdown format
# Remark we need to remove .md's in venv
check_mdformat:
"$(MAKE)" mdformat
find docs -name "*.md" | grep -v docs/developer-guide/tmp.api_for_check | xargs git diff --quiet
.PHONY: benchmark # Perform benchmarks
benchmark:
rm -rf progress.json && \
for script in benchmarks/*.py; do \
poetry run python $$script; \
done
.PHONY: benchmark_one # Perform benchmark on one script file (SCRIPT)
benchmark_one:
rm -rf progress.json && \
poetry run python $${SCRIPT}; \
.PHONY: docker_publish_measurements # Run benchmarks in docker and publish results
docker_publish_measurements: docker_rebuild
docker run --volume /"$$(pwd)":/src \
--volume $(DEV_CONTAINER_VENV_VOLUME):/home/dev_user/dev_venv \
--volume $(DEV_CONTAINER_CACHE_VOLUME):/home/dev_user/.cache \
$(DEV_DOCKER_IMG) \
/bin/bash ./script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh \
"$${LAUNCH_COMMAND}"
.PHONY: nbqa_one # Call nbqa on a single notebook
nbqa_one:
./script/make_utils/nbqa.sh --notebook "$${NOTEBOOK}"
"$(MAKE)" finalize_nb
.PHONY: nbqa # Call nbqa on all notebooks
nbqa:
./script/make_utils/nbqa.sh --all_notebooks
"$(MAKE)" finalize_nb
.PHONY: check_nbqa_one # Check with nbqa a single notebook
check_nbqa_one:
./script/make_utils/nbqa.sh --notebook "$${NOTEBOOK}" --check
.PHONY: check_nbqa # Check with nbqa all notebooks
check_nbqa:
./script/make_utils/nbqa.sh --all_notebooks --check
.PHONY: determinism # Check pytest determinism
determinism:
./script/make_utils/check_pytest_determinism.sh
.PHONY: supported_ops # Update docs with supported ops
supported_ops:
poetry run python script/doc_utils/gen_supported_ops.py docs/deep-learning/onnx_support.md
.PHONY: check_supported_ops # Check supported ops (for the doc)
check_supported_ops:
poetry run python script/doc_utils/gen_supported_ops.py docs/deep-learning/onnx_support.md
git diff docs/deep-learning/onnx_support.md
git diff --quiet docs/deep-learning/onnx_support.md
.PHONY: gitleaks # Check for secrets in the repo using gitleaks
gitleaks:
gitleaks --source "$${PWD}" detect --redact -v
.PHONY: sanity_check # Sanity checks, e.g. to check that a release is viable
sanity_check:
poetry run python ./docker/release_resources/sanity_check.py
.PHONY: fast_sanity_check # Fast sanity checks, e.g. to check that a release is viable
fast_sanity_check:
poetry run python ./docker/release_resources/sanity_check.py --fast
.PHONY: check_links # Check links in the documentation
check_links:
@# It is important to understand that 'make check_links' should only be used after updating the documentation.
@# Since 'make docs' automatically calls 'check_links' at the end, there is no obvious reason to
@# manually call 'make check_links' instead of 'make docs' !
@# Check that no links target the main branch, some internal repositories (Concrete ML or Concrete) or our internal GitBook
./script/make_utils/check_internal_links.sh
@# To avoid some issues with priviledges and linkcheckmd
find docs/ -name "*.md" -type f | xargs chmod +r
@# Run linkcheck on mardown files. It is mainly used for web links and _api_doc (Sphinx)
poetry run python -m linkcheckmd docs -local
poetry run python -m linkcheckmd README.md
@# Check that relative links in mardown files are targeting existing files
poetry run python ./script/make_utils/local_link_check.py
@# Check that links to mardown headers in mardown files are targeting existing headers
poetry run python ./script/make_utils/check_headers.py
@# For weblinks and internal references
@# --ignore-url=_static/webpack-macros.html: useless file which contains wrong links
@# --ignore-url=https://www.conventionalcommits.org/en/v1.0.0/: because issues to connect to
@# the server from AWS
@# --ignore-url=https://www.openml.org: lot of time outs
@# --ignore-url=https://github.com/zama-ai/concrete-ml-internal/issues: because issues are
@# private
@# --ignore-url=.gitbook/assets : some gitbook functionalities use links to images to include
@# them in the docs. But sphinx does not copy such as images to the _build dir since
@# they are not included by image tags or sphinx image annotations. We ignore links
@# to gitbook images in the HTML checker. But the images are actually checked by the
@# markdown link checker, `local_link_check.sh`.
poetry run linkchecker docs --check-extern \
--ignore-url=_static/webpack-macros.html \
--ignore-url=https://www.conventionalcommits.org/en/v1.0.0/ \
--ignore-url=https://www.openml.org \
--ignore-url=https://github.com/zama-ai/concrete-ml-internal/issues \
--ignore-url=.gitbook/assets
.PHONY: actionlint # Linter for our github actions
actionlint:
./script/make_utils/actionlint.sh
.PHONY: check_forbidden_words # Check forbidden words
check_forbidden_words:
./script/make_utils/check_forbidden_words.sh
.PHONY: check_forbidden_words_and_open # Check forbidden words and open bad files
check_forbidden_words_and_open:
./script/make_utils/check_forbidden_words.sh --open
.PHONY: update_dependabot_prs # Update all dependabot PRs on origin
update_dependabot_prs:
/bin/bash ./script/make_utils/update_dependabot_prs.sh
.PHONY: check_unused_images # Check for unused images in the doc
check_unused_images:
./script/make_utils/check_all_images_are_used.sh
.PHONY: pytest_pypi_wheel_cml # Run tests using PyPI local wheel of Concrete ML
pytest_pypi_wheel_cml:
./script/make_utils/pytest_pypi_cml.sh --wheel "$(CP_VERSION_SPEC_FOR_RC)"
.PHONY: pytest_pypi_wheel_cml_no_flaky # Run tests (except flaky ones) using PyPI local wheel of Concrete ML
pytest_pypi_wheel_cml_no_flaky:
./script/make_utils/pytest_pypi_cml.sh --wheel "$(CP_VERSION_SPEC_FOR_RC)" --noflaky
.PHONY: pytest_pip_cml # Run tests using PyPI Concrete ML
pytest_pip_cml:
./script/make_utils/pytest_pypi_cml.sh
.PHONY: clean_pycache # Clean __pycache__ directories
clean_pycache:
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
.PHONY: clean_sklearn_cache # Clean sklearn cache directories, eg for benchmarks
clean_sklearn_cache:
rm -rf ~/scikit_learn_data
.PHONY: run_one_use_case_example # Run one use-case example (USE_CASE, eg use_case_examples/mnist)
run_one_use_case_example:
./script/make_utils/run_use_case_examples.sh
.PHONY: run_all_use_case_examples # Run all use-case examples
run_all_use_case_examples:
USE_CASE="" ./script/make_utils/run_use_case_examples.sh
.PHONY: check_utils_use_case # Check that no utils.py are found in use_case_examples
check_utils_use_case:
./script/make_utils/check_utils_in_use_case.sh