diff --git a/frontends/concrete-python/Makefile b/frontends/concrete-python/Makefile index c82480deec..ee37288504 100644 --- a/frontends/concrete-python/Makefile +++ b/frontends/concrete-python/Makefile @@ -2,9 +2,14 @@ PYTHON=python PIP=$(PYTHON) -m pip COMPILER_BUILD_DIRECTORY ?= $(PWD)/../../compilers/concrete-compiler/compiler/build -NEW_PYTHON_PATH="${COMPILER_BUILD_DIRECTORY}/tools/concretelang/python_packages/concretelang_core/:$(PWD)" +BINDINGS_DIRECTORY=${COMPILER_BUILD_DIRECTORY}/tools/concretelang/python_packages/concretelang_core/ RUNTIME_LIBRARY=${COMPILER_BUILD_DIRECTORY}/lib/libConcretelangRuntime.so +CONCRETE_VERSION?="" # empty mean latest +# E.g. to use a previous version: `make CONCRETE_VERSION="<2.7.0" venv` +# E.g. to use a nightly: `make CONCRETE_VERSION="==2.7.0dev20240801` +# see https://pypi.zama.ai/cpu/concrete-python/index.html for available versions + .ONESHELL: .PHONY: .SILENT: @@ -16,7 +21,9 @@ RUNTIME_LIBRARY=${COMPILER_BUILD_DIRECTORY}/lib/libConcretelangRuntime.so venv: $(PYTHON) -m venv .venv . .venv/bin/activate - +ifeq (,$(wildcard ${RUNTIME_LIBRARY})) + $(PIP) install --extra-index-url https://pypi.zama.ai/cpu "concrete-python$(CONCRETE_VERSION)" +endif $(PIP) install -r requirements.dev.txt $(PIP) install -r requirements.extra-full.txt $(PIP) install -r requirements.txt @@ -26,11 +33,17 @@ venv: @echo "You can have the same activation in a terminal using:" @echo 'eval $$(make cp_activate)' -cp_activate: +cp_activate: silent_cp_activate @echo "echo 'Activating virtual env and local concrete-python and local compiler bindings' ;" + +silent_cp_activate: @echo "export PATH=$(PWD)/.venv/bin:$$PATH;" +ifeq (,$(wildcard ${RUNTIME_LIBRARY})) + @echo "export PYTHONPATH=$(PWD);" +else @echo "export LD_PRELOAD=$(RUNTIME_LIBRARY);" - @echo "export PYTHONPATH=$(NEW_PYTHON_PATH);" + @echo "export PYTHONPATH=${BINDINGS_DIRECTORY}:$(PWD);" +endif licenses: bash scripts/versioning/summary.sh @@ -42,8 +55,7 @@ licenses: pytest: pytest-default pytest-default: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) + eval $(shell make silent_cp_activate) pytest tests -svv -n auto \ --cov=concrete.fhe \ --cov-fail-under=95 \ @@ -52,9 +64,7 @@ pytest-default: -m "${PYTEST_MARKERS}" pytest-single: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) - + eval $(shell make silent_cp_activate) # test single precision, mono params pytest tests -svv -n auto \ --precision=single \ @@ -63,9 +73,7 @@ pytest-single: -m "${PYTEST_MARKERS}" pytest-multi: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) - + eval $(shell make silent_cp_activate) # test multi precision, multi params pytest tests -svv -n auto \ --precision=multi \ @@ -77,9 +85,7 @@ pytest-multi: -m "${PYTEST_MARKERS}" pytest-gpu: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) - + eval $(shell make silent_cp_activate) # test single precision pytest tests -svv -n0 --use_gpu \ --key-cache "${KEY_CACHE_DIRECTORY}" \ @@ -95,9 +101,7 @@ pytest-gpu: -m "${PYTEST_MARKERS}" benchmark: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) - + eval $(shell make silent_cp_activate) export PROGRESS_SAMPLES=3 export PROGRESS_OUTPUT_INDENT=2 @@ -105,9 +109,7 @@ benchmark: find ./benchmarks/ -name "*.py" | xargs python process-benchmark-results-for-grafana: - export LD_PRELOAD=$(RUNTIME_LIBRARY) - export PYTHONPATH=$(NEW_PYTHON_PATH) - + eval $(shell make silent_cp_activate) python scripts/benchmark/postprocessor.py \ --source progress.json \ --target progress.processed.json \ @@ -118,6 +120,7 @@ process-benchmark-results-for-grafana: # ========== format: + eval $(shell make silent_cp_activate) bash scripts/format/formatter.sh \ --dir concrete \ --dir examples \ @@ -126,6 +129,7 @@ format: --dir benchmarks sanitize-notebooks: + eval $(shell make silent_cp_activate) $(PYTHON) scripts/notebook/sanitizer.py docs conformance: format sanitize-notebooks @@ -135,6 +139,7 @@ conformance: format sanitize-notebooks # ======= check-format: + eval $(shell make silent_cp_activate) bash scripts/format/formatter.sh --check \ --dir concrete \ --dir examples \ @@ -143,15 +148,19 @@ check-format: --dir benchmarks check-sanitize-notebooks: + eval $(shell make silent_cp_activate) $(PYTHON) scripts/notebook/sanitizer.py docs --check mypy: + eval $(shell make silent_cp_activate) mypy concrete examples scripts tests benchmarks --ignore-missing-imports pydocstyle: + eval $(shell make silent_cp_activate) pydocstyle concrete --convention google --add-ignore=D1,D200,D202,D212,D402 --add-select=D401 pylint: + eval $(shell make silent_cp_activate) pylint --rcfile=.pylintrc concrete pylint --rcfile=.pylintrc examples --disable=C0103,C0114,C0115,C0116,E0401,R1721 pylint --rcfile=.pylintrc scripts @@ -159,6 +168,7 @@ pylint: pylint --rcfile=.pylintrc benchmarks ruff: + eval $(shell make silent_cp_activate) ruff concrete/ examples/ scripts/ tests/ benchmarks/ pcc: check-format check-sanitize-notebooks mypy pydocstyle pylint ruff