44
55# PY[3] is the target Python interpreter. It must have pytest installed.
66
7- PY =python
8- PY2 =python2
9- PY3 =python3
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 )
12+
1013
1114VERSION =$(shell $(PY3 ) -c 'exec(open("version.py") .read()); print( __version__ )')
1215
16+ # TARGET=... nix-shell # CPython version targets: py2, py3{10,11,12,13}
17+ TARGET ?= cpppo_py312
18+ export TARGET
19+
20+
21+
1322# PY[23]TEST is the desired method of invoking py.test; either as a command, or
1423# loading it as module, by directly invoking the target Python interpreter.
1524#
@@ -40,8 +49,22 @@ VERSION=$(shell $(PY3) -c 'exec(open("version.py").read()); print( __version__ )
4049# Some tests assume the local time-zone is:
4150TZ =Canada/Mountain
4251
52+
53+ GIT_SSH_COMMAND = ssh -o StrictHostKeyChecking=no
54+ export GIT_SSH_COMMAND
55+
56+ GHUB_NAME = cpppo
57+ GHUB_REPO =
[email protected] :pjkundert/
$(GHUB_NAME ) .git
58+ GHUB_BRCH = $(shell git rev-parse --abbrev-ref HEAD )
59+
60+ # We'll agonizingly find the directory above this makefile's path
61+ VENV_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) ) /.. )
62+ VENV_NAME = $(GHUB_NAME ) -$(VERSION ) -$(PY3_V )
63+ VENV = $(VENV_DIR ) /$(VENV_NAME )
64+ VENV_OPTS =
65+
4366# To see all pytest output, uncomment --capture=no
44- PYTESTOPTS =-vv # --capture=no --log-cli-level=25 # INFO # 25 == NORMAL 23 == DETAIL
67+ PYTESTOPTS =-vv --capture=no --log-cli-level=WARNING # INFO # 25 == NORMAL 23 == DETAIL
4568
4669PY_TEST=TZ =$(TZ ) $(PY ) -m pytest $(PYTESTOPTS )
4770PY2TEST=TZ =$(TZ ) $(PY2 ) -m pytest $(PYTESTOPTS )
7295 @echo " vmware-debian-up Brings up Jessie VM w/ Docker capability"
7396 @echo " vmware-debian-ssh Log in to the VM"
7497
98+ analyze :
99+ $(PY3 ) -m flake8 --color never -j 1 --max-line-length=250 \
100+ --exclude lib,bin,dist,build,signals,.git \
101+ --ignore=W503,E201,E202,E203,E127,E211,E221,E222,E223,E225,E226,E231,E241,E242,E251,E265,E272,E274,E291 \
102+
103+ pylint :
104+ pylint . --disable=W,C,R
105+
106+ #
107+ # nix-...:
108+ #
109+ # Use a NixOS environment to execute the make target, eg.
110+ #
111+ # nix-venv-activate
112+ #
113+ # The default is the Python 3 crypto_licensing target in default.nix; choose
114+ # TARGET=cpppo_py2 to test under Python 2 (more difficult as time goes on). See default.nix for
115+ # other Python version targets.
116+ #
117+
118+ nix-% :
119+ nix-shell --pure --run " make $* "
120+
121+
122+ #
123+ # test...: Perform Unit Tests
124+ #
125+ # Assumes that the requirements.txt has been installed in the target Python environment. This
126+ # is probably best accomplished by first creating/activating a venv, and then running the test:
127+ #
128+ # $ make nix-venv-activate
129+ # (crypto-licensing-4.0.0) [perry@Perrys-MBP crypto-licensing (feature-py-3.12)]$ make test
130+ # make[1]: Entering directory '/Users/perry/src/crypto-licensing'
131+ # ...
132+ #
75133test :
76134 $(PY_TEST )
77135test2 :
@@ -101,7 +159,7 @@ pylint:
101159
102160build3-check :
103161 @$(PY3 ) -m build --version \
104- || ( echo " \n*** Missing Python modules; run:\n\n $( PY3) -m pip install --upgrade pip setuptools build \n" \
162+ || ( echo " \n*** Missing Python modules; run:\n\n $( PY3) -m pip install --upgrade -r requirements-dev.txt \n" \
105163 && false )
106164
107165build3 : build3-check clean
@@ -119,6 +177,8 @@ install3: dist/cpppo-$(VERSION)-py3-none-any.whl
119177install23 : install2 install3
120178install : install3
121179
180+ install-% : # ...-dev, -tests
181+ $(PY3 ) -m pip install --upgrade -r requirements-$* .txt
122182
123183# Support uploading a new version of cpppo to pypi. Must:
124184# o advance __version__ number in cpppo/version.py
@@ -130,45 +190,6 @@ upload: clean
130190clean :
131191 @rm -rf MANIFEST * .png build dist auto * .egg-info $(shell find . -name '* .pyc' -o -name '__pycache__' )
132192
133- # Virtualization management, eg:
134- # make {vmware,vagrant}-up/halt/ssh/destroy
135- #
136- # To use a different Vagrant box than precise64 (eg. raring), Vagrantfile must be altered
137- .PHONY : vagrant vagrant_boxes \
138- precise64_virtualbox precise64_vmware_fusion \
139- raring_virtualbox
140-
141- # The vagrant/ubuntu/Vagrantfile doesn't contain a config.vm.box_url; we must
142- # supply. The precise64 VMware image presently supports only VMware Fusion 5;
143- # if you see an error regarding hgfs kernel modules, you may be running a
144- # version of VMware Fusion incompatible with the VMware Tools in the image.
145- # TODO: remove; no longer supported.
146- vmware-ubuntu-% : precise64-vmware_fusion
147- cd vagrant/ubuntu; vagrant $* $(if $(filter up, $* ) , --provider=vmware_fusion,)
148-
149- virtualbox-ubuntu-% : precise64-virtualbox
150- cd vagrant/ubuntu; vagrant $* $(if $(filter up, $* ) , --provider=virtualbox,)
151-
152- # The jessie64 VMware image is compatible with VMware Fusion 6, and the VirtualBox image is
153- # compatible with VirtualBox 4.3. Obtains the box, if necessary. The packer.io generated VMware
154- # boxes identify themselves as being for vmware_desktop; these are compatible with vmware_fusion
155- vmware-debian-% : jessie64-vmware_desktop
156- cd vagrant/debian; vagrant $* $(if $(filter up, $* ) , --provider=vmware_fusion,)
157-
158- virtualbox-debian-% : jessie64-virtualbox
159- cd vagrant/debian; vagrant $* $(if $(filter up, $* ) , --provider=virtualbox,)
160-
161- vagrant :
162- @vagrant --help > /dev/null || ( echo " Install vagrant: http://vagrantup.com" ; exit 1 )
163-
164-
165- # Check if jessie64-{virtualbox,vmware_desktop} exists in the vagrant box list.
166- # If not, install it.
167- jessie64-% :
168- @if ! vagrant box list | grep -q ' ^jessie64.*($*' ; then \
169- vagrant box add jessie64 http://box.hardconsulting.com/jessie64-$* .box --provider $* ; \
170- fi
171-
172193
173194# Run only tests with a prefix containing the target string, eg test-blah
174195test-% :
@@ -192,6 +213,34 @@ unit23-%:
192213 $(PY3TEST ) -k $*
193214
194215
216+ #
217+ # venv: Create a Virtual Env containing the installed repo
218+ #
219+ .PHONY : venv venv-activate.sh venv-activate
220+ venv : $(VENV )
221+ venv-activate.sh : $(VENV ) /venv-activate.sh
222+ venv-activate : $(VENV ) /venv-activate.sh
223+ @echo; echo " *** Activating $< VirtualEnv for Interactive $( SHELL) "
224+ @bash --init-file $< -i
225+ # Create the venv, and then install cpppo from the current directory
226+ $(VENV ) :
227+ @echo; echo " *** Building $@ VirtualEnv..."
228+ @rm -rf $@ && $(PY3 ) -m venv $(VENV_OPTS ) $@ \
229+ && 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+
243+
195244#
196245# Target to allow the printing of 'make' variables, eg:
197246#
0 commit comments