@@ -49,12 +49,13 @@ SIGNTOOL ?= "c:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\signtoo
4949
5050NIX_OPTS ?= # --pure
5151
52- # PY[3] is the target Python interpreter; require 3.11+. Detect if it is named python3 or python.
53- PY3 ?= $(shell python3 --version >/dev/null 2>&1 && echo python3 || echo python )
54- 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 )
55- VERSION = $(shell $(PY3 ) -c 'exec(open("slip39/version.py") .read()); print( __version__ )')
52+ # PY[3] is the target Python interpreter; require 3.11+. Detect if it is named python3 or python, and if system, nix or venv-supplied.
53+ PYTHON ?= $(shell python3 --version >/dev/null 2>&1 && echo python3 || echo python )
54+ PYTHON_P = $(shell which $(PYTHON ) )
55+ PYTHON_V = $(shell $(PYTHON ) -c "import sys; print('-'.join((('venv' if sys.prefix != sys.base_prefix else next(iter(filter(None,sys.base_prefix.split('/') )))),sys.platform,sys.implementation.cache_tag)))" 2>/dev/null )
56+ VERSION = $(shell $(PYTHON ) -c 'exec(open("slip39/version.py") .read()); print( __version__ )')
5657WHEEL = dist/slip39-$(VERSION ) -py3-none-any.whl
57- PLATFORM ?= $(shell $(PY3 ) -c "import sys; print( sys.platform ) " )
58+ PLATFORM ?= $(shell $(PYTHON ) -c "import sys; print( sys.platform ) " )
5859ifeq ($(PLATFORM ) ,darwin)
5960 INSTALLER := pkg
6061else ifeq ($(PLATFORM),win32)
6465endif
6566
6667# To see all pytest output, uncomment --capture=no, ...
67- PYTESTOPTS = -v --log-cli-level=WARNING # --capture=no # --doctest-modules
68+ PYTEST_OPTS ? = -v --log-cli-level=WARNING # --capture=no # --doctest-modules
6869
69- PY3TEST = $(PY3 ) -m pytest $(PYTESTOPTS )
70+ PYTEST = $(PYTHON ) -m pytest $(PYTEST_OPTS )
7071
7172# VirtualEnv: Build them in eg. ~/src/python-slip39-1.2.3/
7273# o Will use the *current* git branch when creating a venv and populating it
7374
7475GHUB_NAME = python-slip39
7576
7677VENV_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) ) /.. )
77- VENV_NAME = $(GHUB_NAME ) -$(VERSION ) -$(PY3_V )
78+ VENV_NAME = $(GHUB_NAME ) -$(VERSION ) -$(PYTHON_V )
7879VENV = $(VENV_DIR ) /$(VENV_NAME )
7980VENV_OPTS = # --copies # Doesn't help; still references some system libs.
8081
8182
8283.PHONY : all help test doctest analyze pylint build install upload clean FORCE
8384
84- all : help
85+ all : help
8586
8687help :
8788 @echo " GNUmakefile for cpppo. Targets:"
@@ -95,11 +96,19 @@ help:
9596 @echo " installer Build the .dmg, .msi, as appropriate for PLATFORM"
9697 @echo " print-PLATFORM prints the detected PLATFORM"
9798
98- test :
99- $(PY3TEST )
99+ test : deps-test
100+ $(PYTEST ) $(PYTEST_OPTS )
101+
102+ # Run only tests with a prefix containing the target string, eg test-api
103+ test-% : deps-test
104+ $(PYTEST ) $(PYTEST_OPTS ) $(shell find slip39 -name '* $* * _test.py')
105+
106+ # Run all tests with names matching the target string
107+ unit-% : deps-test
108+ $(PYTEST ) $(PYTEST_OPTS ) -k $*
100109
101110analyze :
102- $(PY3 ) -m flake8 --color never -j 1 --max-line-length=250 \
111+ $(PYTHON ) -m flake8 --color never -j 1 --max-line-length=250 \
103112 --exclude slip39/tabulate \
104113 --ignore=W503,E201,E202,E203,E127,E221,E223,E226,E231,E241,E242,E251,E265,E272,E274 \
105114 slip39
@@ -113,6 +122,24 @@ signing-check:
113122
114123build : clean wheel
115124
125+ nix-% :
126+ @if [ -r flake.nix ]; then \
127+ nix develop $(NIX_OPTS ) --command make $* ; \
128+ else \
129+ nix-shell $(NIX_OPTS) --run "make $*"; \
130+ fi
131+
132+ #
133+ # Target to allow the printing of 'make' variables, eg:
134+ #
135+ # make print-CXXFLAGS
136+ #
137+ print-% :
138+ @echo $* = $($* )
139+ @echo $* \' s origin is $(origin $* )
140+
141+
142+
116143#
117144# org-mode products.
118145#
@@ -319,14 +346,22 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
319346}}"
320347
321348
349+ .PHONY : deps-test
350+ deps-test : slip39/payments_test/slip-39-app.crypto-license
351+
352+ # Try to copy the generated slip-39-app.crypto-license, if it exists, but no worries if it doesn't
353+ slip39/payments_test/slip-39-app.crypto-license : FORCE
354+ cp $(SLIP-39-LIC ) $@ 2> /dev/null || echo " Missing $( SLIP-39-LIC) ; ignoring..."
355+
356+
322357
323358# Preserve all "secondary" intermediate files (eg. the .crypto-keypair generated)
324359.SECONDARY :
325360
326361# Create .crypto-keypair from seed; note: if the make rule fails, intermediate files are deleted.
327362# We expect any password to be transmitted in CRYPTO_LIC_PASSWORD env. var.
328363% .crypto-keypair : % .crypto-seed
329- $(PY3 ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
364+ $(PYTHON ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
330365 --name $(KEYNAME ) \
331366 --extra $(dir $(basename $@ ) ) --reverse-save \
332367 registered \
@@ -335,7 +370,7 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
335370
336371# Create .crypto-license, signed by .crypto-keypair
337372% .crypto-license : % .crypto-keypair
338- $(PY3 ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
373+ $(PYTHON ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
339374 --name $(KEYNAME ) \
340375 --extra $(dir $(basename $@ ) ) --reverse-save \
341376 license \
@@ -348,31 +383,41 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
348383#
349384# VirtualEnv build, install and activate
350385#
386+ # Create, start and run commands in "interactive" shell with a python venv's activate init-file.
387+ # Doesn't allow recursive creation of a venv with a venv-supplied python. Alters the bin/activate
388+ # to include the user's .bashrc (eg. Git prompts, aliases, ...)
389+ #
390+
391+ venv-% : $(VENV )
392+ @echo; echo " *** Running in $< VirtualEnv: make $* "
393+ @bash --init-file $< /bin/activate -ic " make $* "
351394
352395venv : $(VENV )
353396 @echo; echo " *** Activating $< VirtualEnv for Interactive $( SHELL) "
354397 @bash --init-file $< /bin/activate -i
355398
356399$(VENV ) :
400+ @[[ " $( PYTHON_V) " =~ " ^venv" ]] && ( echo -e " \n\n!!! $@ Cannot start a venv within a venv" ; false ) || true
357401 @echo; echo " *** Building $@ VirtualEnv..."
358- @rm -rf $@ && $(PY3 ) -m venv $(VENV_OPTS ) $@ \
402+ @rm -rf $@ && $(PYTHON ) -m venv $(VENV_OPTS ) $@ && sed -i -e ' 1s:^:. $$HOME/.bashrc\n: ' $@ /bin/activate \
359403 && source $@ /bin/activate \
360- && make install install -tests
404+ && make install-tests install
361405
362406
363407wheel : deps $(WHEEL )
364408
365409$(WHEEL ) : FORCE
366- $(PY3 ) -m pip install -r requirements-tests.txt
367- $(PY3 ) -m build
410+ $(PYTHON ) -m pip install -r requirements-tests.txt
411+ $(PYTHON ) -m build
368412 @ls -last dist
369413
370414# Install from wheel, including all optional extra dependencies (except dev)
371415install : $(WHEEL ) FORCE
372- $(PY3 ) -m pip install --force-reinstall $< [all]
416+ $(PYTHON ) -m pip install --force-reinstall $< [all]
373417
374418install-% : # ...-dev, -tests
375- $(PY3 ) -m pip install --upgrade -r requirements-$* .txt
419+ $(PYTHON ) -m pip install --upgrade -r requirements-$* .txt
420+
376421
377422# Building / Signing / Notarizing and Uploading the macOS or win32 App
378423# o TODO: no signed and notarized package yet accepted for upload by macOS App Store
@@ -412,7 +457,7 @@ app-pkg-upload: dist/SLIP-39-$(VERSION).pkg.upload-package
412457#
413458build/exe.$(CXFREEZE_EXT ) /SLIP-39.exe :
414459 @echo -e " \n\n*** Building $@ "
415- @$(PY3 ) setup.py build_exe > cx_Freeze.build_exe.log \
460+ @$(PYTHON ) setup.py build_exe > cx_Freeze.build_exe.log \
416461 && echo -e " \n\n*** $@ Build successfully:" \
417462 || ( echo -e " \n\n!!! $@ Build failed:" ; tail -20 cx_Freeze.build_exe.log; false )
418463
@@ -423,7 +468,7 @@ dist/slip39-$(VERSION)-win64.msi: build/exe.$(CXFREEZE_EXT)/SLIP-39.exe # signin
423468 # /n "$(DEVID)" \
424469 # $<
425470 @echo -e " \n\n*** Package $@ "
426- @$(PY3 ) setup.py bdist_msi > $cx_Freeze .bdist_msi.log \
471+ @$(PYTHON ) setup.py bdist_msi > $cx_Freeze .bdist_msi.log \
427472 && echo -e " \n\n*** $@ Build successfully:" \
428473 || ( echo -e " \n\n!!! $@ Build failed:" ; tail -20 cx_Freeze.bdist_msi.log; false )
429474
@@ -865,47 +910,3 @@ images/SLIP-39.iconset: images/SLIP-39.png
865910 sips -z 512 512
$< --out
$@ /
[email protected] 866911 sips -z 512 512 $< --out $@ /icon_512x512.png
867912 sips -z 1024 1024
$< --out
$@ /
[email protected] 868-
869-
870- #
871- # Pypi pip packaging
872- #
873- # Support uploading a new version of slip39 to pypi. Must:
874- # o advance __version__ number in slip39/version.py
875- # o log in to your pypi account (ie. for package maintainer only)
876- #
877- upload-check :
878- @$(PY3 ) -m twine --version \
879- || ( echo -e " \n\n*** Missing Python modules; run:\n\n $( PY3) -m pip install --upgrade twine\n" \
880- && false )
881- upload : upload-check wheel
882- $(PY3 ) -m twine upload --repository pypi dist/slip39-$(VERSION ) *
883-
884- clean :
885- @rm -rf MANIFEST * .png build dist auto * .egg-info $(shell find . -name '__pycache__' )
886-
887- .PHONY : deps-test
888- deps-test : slip39/payments_test/slip-39-app.crypto-license
889-
890- slip39/payments_test/slip-39-app.crypto-license : $(SLIP-39-LIC )
891- cp $< $@
892-
893- # Run only tests with a prefix containing the target string, eg test-api
894- test-% : deps-test
895- $(PY3TEST ) $(shell find slip39 -name '* $* * _test.py')
896-
897- # Run all tests with names matching the target string
898- unit-% : deps-test
899- $(PY3TEST ) -k $*
900-
901- nix-% :
902- nix-shell $(NIX_OPTS ) --run " make $* "
903-
904- #
905- # Target to allow the printing of 'make' variables, eg:
906- #
907- # make print-CXXFLAGS
908- #
909- print-% :
910- @echo $* = $($* )
911- @echo $* \' s origin is $(origin $* )
0 commit comments