@@ -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
@@ -96,10 +97,10 @@ help:
9697 @echo " print-PLATFORM prints the detected PLATFORM"
9798
9899test :
99- $(PY3TEST )
100+ $(PYTEST ) $( PYTEST_OPTS )
100101
101102analyze :
102- $(PY3 ) -m flake8 --color never -j 1 --max-line-length=250 \
103+ $(PYTHON ) -m flake8 --color never -j 1 --max-line-length=250 \
103104 --exclude slip39/tabulate \
104105 --ignore=W503,E201,E202,E203,E127,E221,E223,E226,E231,E241,E242,E251,E265,E272,E274 \
105106 slip39
@@ -326,7 +327,7 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
326327# Create .crypto-keypair from seed; note: if the make rule fails, intermediate files are deleted.
327328# We expect any password to be transmitted in CRYPTO_LIC_PASSWORD env. var.
328329% .crypto-keypair : % .crypto-seed
329- $(PY3 ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
330+ $(PYTHON ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
330331 --name $(KEYNAME ) \
331332 --extra $(dir $(basename $@ ) ) --reverse-save \
332333 registered \
@@ -335,7 +336,7 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
335336
336337# Create .crypto-license, signed by .crypto-keypair
337338% .crypto-license : % .crypto-keypair
338- $(PY3 ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
339+ $(PYTHON ) -m crypto_licensing $(GLOBAL_OPTIONS ) \
339340 --name $(KEYNAME ) \
340341 --extra $(dir $(basename $@ ) ) --reverse-save \
341342 license \
@@ -348,31 +349,41 @@ $(PAY-TEST-LIC): GRANTS="{\"crypto-licensing-server\": {\
348349#
349350# VirtualEnv build, install and activate
350351#
352+ # Create, start and run commands in "interactive" shell with a python venv's activate init-file.
353+ # Doesn't allow recursive creation of a venv with a venv-supplied python. Alters the bin/activate
354+ # to include the user's .bashrc (eg. Git prompts, aliases, ...)
355+ #
356+
357+ venv-% : $(VENV )
358+ @echo; echo " *** Running in $< VirtualEnv: make $* "
359+ @bash --init-file $< /bin/activate -ic " make $* "
351360
352361venv : $(VENV )
353362 @echo; echo " *** Activating $< VirtualEnv for Interactive $( SHELL) "
354363 @bash --init-file $< /bin/activate -i
355364
356365$(VENV ) :
366+ @[[ " $( PYTHON_V) " =~ " ^venv" ]] && ( echo -e " \n\n!!! $@ Cannot start a venv within a venv" ; false ) || true
357367 @echo; echo " *** Building $@ VirtualEnv..."
358- @rm -rf $@ && $(PY3 ) -m venv $(VENV_OPTS ) $@ \
368+ @rm -rf $@ && $(PYTHON ) -m venv $(VENV_OPTS ) $@ && sed -i -e ' 1s:^:. $$HOME/.bashrc\n: ' $@ /bin/activate \
359369 && source $@ /bin/activate \
360- && make install install -tests
370+ && make install-tests install
361371
362372
363373wheel : deps $(WHEEL )
364374
365375$(WHEEL ) : FORCE
366- $(PY3 ) -m pip install -r requirements-tests.txt
367- $(PY3 ) -m build
376+ $(PYTHON ) -m pip install -r requirements-tests.txt
377+ $(PYTHON ) -m build
368378 @ls -last dist
369379
370380# Install from wheel, including all optional extra dependencies (except dev)
371381install : $(WHEEL ) FORCE
372- $(PY3 ) -m pip install --force-reinstall $< [all]
382+ $(PYTHON ) -m pip install --force-reinstall $< [all]
373383
374384install-% : # ...-dev, -tests
375- $(PY3 ) -m pip install --upgrade -r requirements-$* .txt
385+ $(PYTHON ) -m pip install --upgrade -r requirements-$* .txt
386+
376387
377388# Building / Signing / Notarizing and Uploading the macOS or win32 App
378389# o TODO: no signed and notarized package yet accepted for upload by macOS App Store
@@ -412,7 +423,7 @@ app-pkg-upload: dist/SLIP-39-$(VERSION).pkg.upload-package
412423#
413424build/exe.$(CXFREEZE_EXT ) /SLIP-39.exe :
414425 @echo -e " \n\n*** Building $@ "
415- @$(PY3 ) setup.py build_exe > cx_Freeze.build_exe.log \
426+ @$(PYTHON ) setup.py build_exe > cx_Freeze.build_exe.log \
416427 && echo -e " \n\n*** $@ Build successfully:" \
417428 || ( echo -e " \n\n!!! $@ Build failed:" ; tail -20 cx_Freeze.build_exe.log; false )
418429
@@ -423,7 +434,7 @@ dist/slip39-$(VERSION)-win64.msi: build/exe.$(CXFREEZE_EXT)/SLIP-39.exe # signin
423434 # /n "$(DEVID)" \
424435 # $<
425436 @echo -e " \n\n*** Package $@ "
426- @$(PY3 ) setup.py bdist_msi > $cx_Freeze .bdist_msi.log \
437+ @$(PYTHON ) setup.py bdist_msi > $cx_Freeze .bdist_msi.log \
427438 && echo -e " \n\n*** $@ Build successfully:" \
428439 || ( echo -e " \n\n!!! $@ Build failed:" ; tail -20 cx_Freeze.bdist_msi.log; false )
429440
@@ -875,11 +886,11 @@ images/SLIP-39.iconset: images/SLIP-39.png
875886# o log in to your pypi account (ie. for package maintainer only)
876887#
877888upload-check :
878- @$(PY3 ) -m twine --version \
879- || ( echo -e " \n\n*** Missing Python modules; run:\n\n $( PY3 ) -m pip install --upgrade twine\n" \
889+ @$(PYTHON ) -m twine --version \
890+ || ( echo -e " \n\n*** Missing Python modules; run:\n\n $( PYTHON ) -m pip install --upgrade twine\n" \
880891 && false )
881892upload : upload-check wheel
882- $(PY3 ) -m twine upload --repository pypi dist/slip39-$(VERSION ) *
893+ $(PYTHON ) -m twine upload --repository pypi dist/slip39-$(VERSION ) *
883894
884895clean :
885896 @rm -rf MANIFEST * .png build dist auto * .egg-info $(shell find . -name '__pycache__' )
@@ -892,14 +903,18 @@ slip39/payments_test/slip-39-app.crypto-license: $(SLIP-39-LIC)
892903
893904# Run only tests with a prefix containing the target string, eg test-api
894905test-% : deps-test
895- $(PY3TEST ) $(shell find slip39 -name '* $* * _test.py')
906+ $(PYTEST ) $( PYTEST_OPTS ) $(shell find slip39 -name '* $* * _test.py')
896907
897908# Run all tests with names matching the target string
898909unit-% : deps-test
899- $(PY3TEST ) -k $*
910+ $(PYTEST ) $( PYTEST_OPTS ) -k $*
900911
901912nix-% :
902- nix-shell $(NIX_OPTS ) --run " make $* "
913+ @if [ -r flake.nix ]; then \
914+ nix develop $(NIX_OPTS ) --command make $* ; \
915+ else \
916+ nix-shell $(NIX_OPTS) --run "make $*"; \
917+ fi
903918
904919#
905920# Target to allow the printing of 'make' variables, eg:
0 commit comments