3
3
#
4
4
5
5
# PY[3] is the target Python interpreter. It must have pytest installed.
6
+ SHELL = /bin/bash
7
+
8
+ PY ?= python
9
+ PY2 ?= python2
10
+ 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])))))" )
11
+ PY3 ?= python3
12
+ 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 )
13
+
14
+
15
+ VERSION = $(shell $(PY3 ) -c 'exec(open("version.py") .read()); print( __version__ )')
16
+ WHEEL = dist/cpppo-$(VERSION ) -py3-none-any.whl
17
+
18
+ # TARGET=... nix-shell # CPython version targets: py27, py3{10,11,12,13}
19
+ # (py27 requires reverting to an older nixpkgs.nix)
20
+ # TARGET ?= py312
21
+ export TARGET
22
+
23
+ NIX_OPTS ?= # --pure
24
+
6
25
7
- PY =python
8
- PY2 =python2
9
- PY3 =python3
10
26
11
27
# PY[23]TEST is the desired method of invoking py.test; either as a command, or
12
28
# loading it as module, by directly invoking the target Python interpreter.
@@ -35,14 +51,31 @@ PY3=python3
35
51
# LC_ALL=en_CA.UTF-8
36
52
#
37
53
54
+ # Some tests assume the local time-zone is:
55
+ TZ =Canada/Mountain
56
+
57
+
58
+ GIT_SSH_COMMAND = ssh -o StrictHostKeyChecking=no
59
+ export GIT_SSH_COMMAND
60
+
61
+ GHUB_NAME = cpppo
62
+ GHUB_REPO =
[email protected] :pjkundert/
$(GHUB_NAME ) .git
63
+ GHUB_BRCH = $(shell git rev-parse --abbrev-ref HEAD )
64
+
65
+ # We'll agonizingly find the directory above this makefile's path
66
+ VENV_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) ) /.. )
67
+ VENV_NAME = $(GHUB_NAME ) -$(VERSION ) -$(PY3_V )
68
+ VENV = $(VENV_DIR ) /$(VENV_NAME )
69
+ VENV_OPTS =
70
+
38
71
# To see all pytest output, uncomment --capture=no
39
- PYTESTOPTS =-v # --capture=no
72
+ PYTESTOPTS =-v --capture=no --log-cli-level=WARNING # INFO 25 == NORMAL 23 == DETAIL
40
73
41
74
PY_TEST=TZ =$(TZ ) $(PY ) -m pytest $(PYTESTOPTS )
42
75
PY2TEST=TZ =$(TZ ) $(PY2 ) -m pytest $(PYTESTOPTS )
43
76
PY3TEST=TZ =$(TZ ) $(PY3 ) -m pytest $(PYTESTOPTS )
44
77
45
- .PHONY : all test clean upload
78
+ .PHONY : all test clean FORCE
46
79
all : help
47
80
48
81
help :
51
84
@echo " test Run unit tests under Python2/3 (no serial_test w/o 'make SERIAL_TEST=1 test')"
52
85
@echo " install Install in /usr/local for Python2/3"
53
86
@echo " clean Remove build artifacts"
54
- @echo " upload Upload new version to pypi (package maintainer only)"
55
87
@echo
56
88
@echo " virtualbox-* Manage VirtualBox virtual machine"
57
89
@echo " vmware-* Manage VMWare Fusion virtual machine (recommended; requires license)"
@@ -67,106 +99,101 @@ help:
67
99
@echo " vmware-debian-up Brings up Jessie VM w/ Docker capability"
68
100
@echo " vmware-debian-ssh Log in to the VM"
69
101
102
+ analyze :
103
+ $(PY3 ) -m flake8 --color never -j 1 --max-line-length=250 \
104
+ --exclude lib,bin,dist,build,signals,.git \
105
+ --ignore=W503,E201,E202,E203,E127,E211,E221,E222,E223,E225,E226,E231,E241,E242,E251,E265,E272,E274,E291 \
106
+
107
+ pylint :
108
+ pylint . --disable=W,C,R
109
+
110
+ #
111
+ # nix-...:
112
+ #
113
+ # Use a NixOS environment to execute the make target, eg.
114
+ #
115
+ # nix-venv-activate
116
+ #
117
+ # The default is the Python 3 crypto_licensing target in default.nix; choose
118
+ # TARGET=py27 to test under Python 2 (more difficult as time goes on). See default.nix for
119
+ # other Python version targets.
120
+ #
121
+ nix-% :
122
+ nix-shell $(NIX_OPTS ) --run " make $* "
123
+
124
+
125
+ #
126
+ # test...: Perform Unit Tests
127
+ #
128
+ # Assumes that the requirements.txt has been installed in the target Python environment. This
129
+ # is probably best accomplished by first creating/activating a venv, and then running the test:
130
+ #
131
+ # $ make nix-venv-activate
132
+ # (crypto-licensing-4.0.0) [perry@Perrys-MBP crypto-licensing (feature-py-3.12)]$ make test
133
+ # make[1]: Entering directory '/Users/perry/src/crypto-licensing'
134
+ # ...
135
+ #
70
136
test :
71
- $(PY_TEST )
72
- test2 :
73
- $(PY2TEST )
74
- test3 :
75
- $(PY3TEST )
76
- test23 :
77
- $(PY2TEST )
78
137
$(PY3TEST )
79
138
80
- install :
81
- $(PY ) setup.py install
82
- install2 :
83
- $(PY2 ) setup.py install
84
- install3 :
85
- $(PY3 ) setup.py install
86
- install23 :
87
- $(PY2 ) setup.py install
88
- $(PY3 ) setup.py install
139
+ doctest :
140
+ cd crypto/licensing && $(PY3TEST ) --doctest-modules
89
141
90
142
analyze :
91
- flake8 -j 1 --max-line-length=110 \
92
- --ignore=F401,E221, E201,E202,E203 ,E223,E225, E226,E231,E241, E242,E261, E272,E302, W503,E701,E702,E,W \
143
+ flake8 -j 1 --max-line-length=110 \
144
+ --ignore=F401,E201,E202,E221 ,E223,E226,E231,E242,E272,E701,E702,W191,W291, W503,W293,W391,E \
93
145
--exclude=" __init__.py" \
94
146
.
95
147
96
148
pylint :
97
149
cd .. && pylint cpppo --disable=W,C,R
98
150
99
- # Support uploading a new version of cpppo to pypi. Must:
100
- # o advance __version__ number in cpppo/version.py
101
- # o log in to your pypi account (ie. for package maintainer only)
102
- upload :
103
- python setup.py sdist upload
104
151
105
- clean :
106
- @rm -rf MANIFEST * .png build dist auto * .egg-info $(shell find . -name '* .pyc' -o -name '__pycache__' )
152
+ build-check :
153
+ @$(PY3 ) -m build --version \
154
+ || ( echo " \n*** Missing Python modules; run:\n\n $( PY3) -m pip install --upgrade -r requirements-dev.txt\n" \
155
+ && false )
107
156
108
- # Virtualization management, eg:
109
- # make {vmware,vagrant}-up/halt/ssh/destroy
110
- #
111
- # To use a different Vagrant box than precise64 (eg. raring), Vagrantfile must be altered
112
- .PHONY : vagrant vagrant_boxes \
113
- precise64_virtualbox precise64_vmware_fusion \
114
- raring_virtualbox
115
-
116
- # The vagrant/ubuntu/Vagrantfile doesn't contain a config.vm.box_url; we must
117
- # supply. The precise64 VMware image presently supports only VMware Fusion 5;
118
- # if you see an error regarding hgfs kernel modules, you may be running a
119
- # version of VMware Fusion incompatible with the VMware Tools in the image.
120
- # TODO: remove; no longer supported.
121
- vmware-ubuntu-% : precise64-vmware_fusion
122
- cd vagrant/ubuntu; vagrant $* $(if $(filter up, $* ) , --provider=vmware_fusion,)
123
-
124
- virtualbox-ubuntu-% : precise64-virtualbox
125
- cd vagrant/ubuntu; vagrant $* $(if $(filter up, $* ) , --provider=virtualbox,)
157
+ build : build-check clean wheel
126
158
127
- # The jessie64 VMware image is compatible with VMware Fusion 6, and the VirtualBox image is
128
- # compatible with VirtualBox 4.3. Obtains the box, if necessary. The packer.io generated VMware
129
- # boxes identify themselves as being for vmware_desktop; these are compatible with vmware_fusion
130
- vmware-debian-% : jessie64-vmware_desktop
131
- cd vagrant/debian; vagrant $* $(if $(filter up, $* ) , --provider=vmware_fusion,)
159
+ wheel : $(WHEEL )
132
160
133
- virtualbox-debian-% : jessie64-virtualbox
134
- cd vagrant/debian; vagrant $* $(if $(filter up, $* ) , --provider=virtualbox,)
161
+ $(WHEEL ) : FORCE
162
+ $(PY3 ) -m pip install -r requirements-dev.txt
163
+ $(PY3 ) -m build .
164
+ @ls -last dist
135
165
136
- vagrant :
137
- @vagrant --help > /dev/null || ( echo " Install vagrant: http://vagrantup.com " ; exit 1 )
166
+ install : $( WHEEL ) FORCE
167
+ $( PY3 ) -m pip install --force-reinstall $< [all]
138
168
169
+ install-% : # ...-dev, -tests
170
+ $(PY3 ) -m pip install --upgrade -r requirements-$* .txt
139
171
140
- # Check if jessie64-{virtualbox,vmware_desktop} exists in the vagrant box list.
141
- # If not, install it.
142
- jessie64-% :
143
- @if ! vagrant box list | grep -q ' ^jessie64.*($*' ; then \
144
- vagrant box add jessie64 http://box.hardconsulting.com/jessie64-$* .box --provider $* ; \
145
- fi
146
172
173
+ clean :
174
+ @rm -rf MANIFEST * .png build dist auto * .egg-info $(shell find . -name '* .pyc' -o -name '__pycache__' )
147
175
148
176
149
177
# Run only tests with a prefix containing the target string, eg test-blah
150
178
test-% :
151
- $(PY_TEST ) * $* _test.py
152
- test2-% :
153
- $(PY2TEST ) * $* _test.py
154
- test3-% :
155
- $(PY3TEST ) * $* _test.py
156
- test23-% :
157
- $(PY2TEST ) * $* _test.py
158
179
$(PY3TEST ) * $* _test.py
159
180
160
181
unit-% :
161
- $(PY_TEST ) -k $*
162
- unit2-% :
163
- $(PY2TEST ) -k $*
164
- unit3-% :
165
- $(PY3TEST ) -k $*
166
- unit23-% :
167
- $(PY2TEST ) -k $*
168
182
$(PY3TEST ) -k $*
169
183
184
+ #
185
+ # venv: Create a Virtual Env containing the installed repo
186
+ #
187
+ .PHONY : venv
188
+ venv : $(VENV )
189
+ @echo; echo " *** Activating $< VirtualEnv for Interactive $( SHELL) "
190
+ @bash --init-file $< /bin/activate -i
191
+
192
+ $(VENV ) :
193
+ @echo; echo " *** Building $@ VirtualEnv..."
194
+ @rm -rf $@ && $(PY3 ) -m venv $(VENV_OPTS ) $@ \
195
+ && source $@ /bin/activate \
196
+ && make install install-tests
170
197
171
198
#
172
199
# Target to allow the printing of 'make' variables, eg:
0 commit comments