44
55# PY[3] is the target Python interpreter. It must have pytest installed.
66
7- PY ?= python
8- PY2 ?= python2
9- PY2_V = $(shell $(PY2 ) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/') ))),sys.platform,sys.subversion[0].lower(),''.join(map(str,sys.version_info[:2])))))" )
10- PY3 ?= python3
11- PY3_V = $(shell $(PY3 ) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/') ))),sys.platform,sys.implementation.cache_tag)))" 2>/dev/null )
7+ PY ?= python
8+ PY2 ?= python2
9+ PY2_V = $(shell $(PY2 ) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/') ))),sys.platform,sys.subversion[0].lower(),''.join(map(str,sys.version_info[:2])))))" )
10+ PY3 ?= python3
11+ PY3_V = $(shell $(PY3 ) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/') ))),sys.platform,sys.implementation.cache_tag)))" 2>/dev/null )
1212
1313
14- VERSION =$(shell $(PY3 ) -c 'exec(open("version.py") .read()); print( __version__ )')
14+ VERSION = $(shell $(PY3 ) -c 'exec(open("version.py") .read()); print( __version__ )')
15+ WHEEL = dist/cpppo-$(VERSION ) -py3-none-any.whl
1516
16- # TARGET=... nix-shell # CPython version targets: py2, py3{10,11,12,13}
17- TARGET ?= cpppo_py312
17+ # TARGET=... nix-shell # CPython version targets: py27, py3{10,11,12,13}
18+ # (py27 requires reverting to an older nixpkgs.nix)
19+ # TARGET ?= py312
1820export TARGET
1921
22+ NIX_OPTS ?= # --pure
23+
2024
2125
2226# PY[23]TEST is the desired method of invoking py.test; either as a command, or
@@ -70,7 +74,7 @@ PY_TEST=TZ=$(TZ) $(PY) -m pytest $(PYTESTOPTS)
7074PY2TEST=TZ =$(TZ ) $(PY2 ) -m pytest $(PYTESTOPTS )
7175PY3TEST=TZ =$(TZ ) $(PY3 ) -m pytest $(PYTESTOPTS )
7276
73- .PHONY : all test clean upload
77+ .PHONY : all test clean upload FORCE
7478all : help
7579
7680help :
@@ -114,9 +118,8 @@ pylint:
114118# TARGET=cpppo_py2 to test under Python 2 (more difficult as time goes on). See default.nix for
115119# other Python version targets.
116120#
117-
118121nix-% :
119- nix-shell --pure --run " make $* "
122+ nix-shell $( NIX_OPTS ) --run " make $* "
120123
121124
122125#
@@ -131,21 +134,10 @@ nix-%:
131134# ...
132135#
133136test :
134- $(PY_TEST )
135- test2 :
136- $(PY2TEST )
137- test3 :
138137 $(PY3TEST )
139- test23 : test2 test3
140-
141138
142139doctest :
143- cd crypto/licensing && $(PY_TEST ) --doctest-modules
144- doctest2 :
145- cd crypto/licensing && $(PY2TEST ) --doctest-modules
146- doctest3 :
147140 cd crypto/licensing && $(PY3TEST ) --doctest-modules
148- doctest23 : doctest2 doctest3
149141
150142analyze :
151143 flake8 -j 1 --max-line-length=110 \
@@ -157,25 +149,22 @@ pylint:
157149 cd .. && pylint cpppo --disable=W,C,R
158150
159151
160- build3 -check :
152+ build -check :
161153 @$(PY3 ) -m build --version \
162154 || ( echo " \n*** Missing Python modules; run:\n\n $( PY3) -m pip install --upgrade -r requirements-dev.txt\n" \
163155 && false )
164156
165- build3 : build3-check clean
166- $(PY3 ) -m build
167- @ls -last dist
168- build : build3
157+ build : build-check clean wheel
169158
170- dist/cpppo- $( VERSION ) -py3-none-any.whl : build3
159+ wheel : $( WHEEL )
171160
172- install2 :
173- $(PY2 ) setup.py install
174- install3 : dist/cpppo- $( VERSION ) -py3-none-any.whl
175- $( PY3 ) -m pip install --force-reinstall $^
161+ $( WHEEL ) : FORCE
162+ $(PY3 ) -m pip install -r requirements-dev.txt
163+ $( PY3 ) -m build .
164+ @ls -last dist
176165
177- install23 : install2 install3
178- install : install3
166+ install : $( WHEEL ) FORCE
167+ $( PY3 ) -m pip install --force-reinstall $< [all]
179168
180169install-% : # ...-dev, -tests
181170 $(PY3 ) -m pip install --upgrade -r requirements-$* .txt
@@ -193,53 +182,24 @@ clean:
193182
194183# Run only tests with a prefix containing the target string, eg test-blah
195184test-% :
196- $(PY_TEST ) * $* _test.py
197- test2-% :
198- $(PY2TEST ) * $* _test.py
199- test3-% :
200- $(PY3TEST ) * $* _test.py
201- test23-% :
202- $(PY2TEST ) * $* _test.py
203185 $(PY3TEST ) * $* _test.py
204186
205187unit-% :
206- $(PY_TEST ) -k $*
207- unit2-% :
208- $(PY2TEST ) -k $*
209- unit3-% :
210- $(PY3TEST ) -k $*
211- unit23-% :
212- $(PY2TEST ) -k $*
213188 $(PY3TEST ) -k $*
214189
215-
216190#
217191# venv: Create a Virtual Env containing the installed repo
218192#
219193.PHONY : venv venv-activate.sh venv-activate
220194venv : $(VENV )
221- venv-activate.sh : $(VENV ) /venv-activate.sh
222- venv-activate : $(VENV ) /venv-activate.sh
223195 @echo; echo " *** Activating $< VirtualEnv for Interactive $( SHELL) "
224- @bash --init-file $< -i
225- # Create the venv, and then install cpppo from the current directory
196+ @bash --init-file $< /bin/activate -i
197+
226198$(VENV ) :
227199 @echo; echo " *** Building $@ VirtualEnv..."
228200 @rm -rf $@ && $(PY3 ) -m venv $(VENV_OPTS ) $@ \
229201 && source $@ /bin/activate \
230- && make install-dev install
231-
232- # Activate a given VirtualEnv, and go to its routeros_ssh installation
233- # o Creates a custom venv-activate.sh script in the venv, and uses it start
234- # start a sub-shell in that venv, with a CWD in the contained routeros_ssh installation
235- $(VENV ) /venv-activate.sh : $(VENV )
236- ( \
237- echo " PS1='[\u@\h \W)]\\ $$ '" ; \
238- echo " [ -r ~/.git-completion.bash ] && source ~/.git-completion.bash" ; \
239- echo " [ -r ~/.git-prompt.sh ] && source ~/.git-prompt.sh && PS1='[\u@\h \W\$ $( __git_ps1 \" (%s)\" ) ]\\ $$ '" ; \
240- echo " source $</bin/activate" ; \
241- ) > $@
242-
202+ && make install install-tests
243203
244204#
245205# Target to allow the printing of 'make' variables, eg:
0 commit comments