Skip to content

Commit 87a9c20

Browse files
committed
Setup and use a virtual env for Python in makefiles
Signed-off-by: hemildesai <[email protected]>
1 parent 65d5712 commit 87a9c20

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
ENVIRONMENT := development
2+
ROOTDIR=./
3+
VENV=$(ROOTDIR)venv/bin/
4+
5+
.PHONY: venv
6+
venv:
7+
test -d venv || python -m venv $(ROOTDIR)venv
28

39
OS := $(shell uname -s)
410

511
.PHONY: build
6-
build: verify-dev-env
12+
build: verify-dev-env venv
713
cd go && $(MAKE) build-all ENVIRONMENT=$(ENVIRONMENT)
814
cd python && $(MAKE) build
915

@@ -18,14 +24,16 @@ else
1824
endif
1925

2026
.PHONY: develop
21-
develop: verify-dev-env
27+
develop: verify-dev-env venv
2228
cd go && $(MAKE) build
2329
cd go && $(MAKE) install
24-
cd python && python setup.py develop
30+
cd python && $(MAKE) develop
31+
@printf "\nPython venv created at $(ROOTDIR)venv. Run `tput bold`source $(ROOTDIR)venv/bin/activate`tput sgr0` to activate the venv in your shell.\n"
32+
@printf "If you're using vscode, select this venv as the Python interpretor in the bottom left.\n"
2533

2634
.PHONY: install-test-dependencies
27-
install-test-dependencies:
28-
pip install -r requirements-test.txt
35+
install-test-dependencies: venv
36+
$(VENV)pip install -r requirements-test.txt
2937

3038
.PHONY: test
3139
test: install-test-dependencies develop

end-to-end-test/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
ROOTDIR=../
2+
VENV=$(ROOTDIR)venv/bin/
3+
14
.PHONY: test
25
test:
3-
pytest -m "not external"
6+
$(VENV)pytest -m "not external"
47

58
.PHONY: test-external
69
test-external:
7-
pytest
10+
$(VENV)pytest

python/Makefile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1+
ROOTDIR=../
2+
VENV=$(ROOTDIR)venv/bin/
3+
14
.PHONY: pre-commit
25
pre-commit: lint
36

47
.PHONY: fmt
58
fmt:
6-
black .
9+
$(VENV)black .
10+
11+
.PHONY: develop
12+
develop:
13+
$(VENV)python setup.py develop
714

815
# --import-mode makes pytest import from globally installed package by default instead of local replicate/ module.
916
# This assumes you've run `make develop` before running tests
1017
# https://docs.pytest.org/en/stable/pythonpath.html#pythonpath
1118
.PHONY: test
1219
test: lint
13-
pytest --import-mode=importlib -m "not external"
20+
$(VENV)pytest --import-mode=importlib -m "not external"
1421

1522
.PHONY: test-external
1623
test-external: lint
17-
pytest --import-mode=importlib
24+
$(VENV)pytest --import-mode=importlib
1825

1926
.PHONY: lint
2027
lint:
21-
mypy .
22-
black --check .
28+
$(VENV)mypy .
29+
$(VENV)black --check .
2330

2431
.PHONY: clean
2532
clean:
@@ -42,15 +49,15 @@ clean:
4249
# https://docs.python.org/3/distutils/apiref.html#distutils.util.get_platform
4350
.PHONY: build
4451
build: clean
45-
pip install wheel
46-
python setup.py bdist_wheel --plat-name manylinux1_x86_64
47-
python setup.py bdist_wheel --plat-name macosx_10_9_x86_64
52+
$(VENV)pip install wheel
53+
$(VENV)python setup.py bdist_wheel --plat-name manylinux1_x86_64
54+
$(VENV)python setup.py bdist_wheel --plat-name macosx_10_9_x86_64
4855

4956
.PHONY: targets
5057
targets:
5158
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
5259

5360
.PHONY: vendor
5461
vendor:
55-
pip install vendoring
56-
vendoring sync -v .
62+
$(VENV)pip install vendoring
63+
$(VENV)vendoring sync -v .

0 commit comments

Comments
 (0)