From a93a9e103ef2a46d86fb3dab6c93de870fe7ead3 Mon Sep 17 00:00:00 2001 From: Erich Focht Date: Thu, 16 Nov 2023 14:54:16 +0100 Subject: [PATCH] Changed Makefile to restart itself if not in venv (when needed). Simplifies building. --- Makefile | 47 +++++++++++++++++++++++++++++++++-------------- requirements.txt | 3 +++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 requirements.txt diff --git a/Makefile b/Makefile index 8800620..827f4b8 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,25 @@ -# -# install cython in a virtualenv named cython -# workon cython -# ... -# +# Most targets are expected to be built inside a virtualenv, +# its building as well as restarting make in it is automated. -veosinfo/_veosinfo.so: veosinfo/_veosinfo.pyx - python setup.py build_ext -i --use-cython +ifeq ($(VIRTUAL_ENV),) -test: - PATHONPATH=. python test_veosinfo.py +# If virtual environment is not active, restart within virtual environment +SELF := $(MAKE) -f $(lastword $(MAKEFILE_LIST)) +MAKE := $(shell echo $$MAKE) -clean: - rm -f veosinfo/*.so veosinfo/_veosinfo.c veosinfo/*.pyc +in_venv: | venv + @echo "Virtual environment not active. Restarting within virtual environment..." + @echo "MAKECMDGOALS = $(MAKECMDGOALS)" + . venv/bin/activate && $(SELF) $(MAKEFLAGS) $(MAKECMDGOALS) -install: veosinfo/_veosinfo.so - python setup.py install +sdist rpm srpm upload: in_venv + +else + +veosinfo/_veosinfo.so: in_venv veosinfo/_veosinfo.pyx + python setup.py build_ext -i --use-cython +.PHONY: sdist upload sdist: python setup.py sdist --use-cython @@ -31,5 +35,20 @@ rpm: veosinfo/_veosinfo.so srpm: veosinfo/_veosinfo.so python setup.py bdist_rpm --source-only -.PHONY: test clean install sdist rpm +endif + +.PHONY: test clean install +test: + PYTHONPATH=. python test_veosinfo.py + +clean: + rm -f veosinfo/*.so veosinfo/_veosinfo.c veosinfo/*.pyc + +install: veosinfo/_veosinfo.so + python setup.py install +venv: + python3 -m venv venv && \ + . venv/bin/activate && \ + pip install -U pip && \ + pip install -r requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9a56527 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +cython +twine +wheel