From 7bc1adcc2a32d66baabd514e57cd0610c3a98558 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Sat, 16 Sep 2023 12:35:15 +0200 Subject: [PATCH] build: Fix Makefile targets to match GNU coding standards - Rename target clean-all to distclean - Add uninstall target - Install target has to run tests Signed-off-by: Sven Sager --- Makefile | 51 +++++++++++++++++++++++++++---------- src/revpipyload/__main__.py | 15 +++-------- src/revpipyload/proginit.py | 7 +++++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index be32e00..7db12da 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ MAKEFLAGS = --no-print-directory --no-builtin-rules # Variables PACKAGE = revpipyload +APP_NAME = RevPiPyLoad +APP_IDENT = org.revpimodio.revpipyload # Set path to create the virtual environment with package name ifdef PYTHON3_VENV @@ -16,39 +18,60 @@ endif SYSTEM_PYTHON = python3 PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON)) -all: build +APP_VERSION = $(shell "$(PYTHON)" src/$(PACKAGE) --version | cut -d ' ' -f 2) + +all: test build .PHONY: all ## Environment venv-info: - echo Using path: "$(VENV_PATH)" + @echo Environment for $(APP_NAME) $(APP_VERSION) + @echo Using path: "$(VENV_PATH)" exit 0 venv: - $(SYSTEM_PYTHON) -m venv "$(VENV_PATH)" - source $(VENV_PATH)/bin/activate && \ + # Start with empty environment + "$(SYSTEM_PYTHON)" -m venv "$(VENV_PATH)" + source "$(VENV_PATH)/bin/activate" && \ python3 -m pip install --upgrade pip && \ python3 -m pip install -r requirements.txt exit 0 -.PHONY: venv-info venv +venv-ssp: + # Include system installed site-packages and add just missing modules + "$(SYSTEM_PYTHON)" -m venv --system-site-packages "$(VENV_PATH)" + source "$(VENV_PATH)/bin/activate" && \ + python3 -m pip install --upgrade pip && \ + python3 -m pip install -r requirements.txt + exit 0 -## Build, install +.PHONY: venv-info venv venv-ssp + +## Build steps build: - $(PYTHON) -m setup sdist - $(PYTHON) -m setup bdist_wheel + "$(PYTHON)" -m setup sdist + "$(PYTHON)" -m setup bdist_wheel install: build - $(PYTHON) -m pip install dist/$(PACKAGE)-*.whl + "$(PYTHON)" -m pip install dist/$(PACKAGE)-$(APP_VERSION)-*.whl -.PHONY: build install +uninstall: + "$(PYTHON)" -m pip uninstall --yes $(PACKAGE) + +.PHONY: test build install uninstall ## Clean clean: - rm -rf build dist src/*.egg-info *.spec + # PyTest caches + rm -rf .pytest_cache + # Build artifacts + rm -rf build dist src/*.egg-info + # PyInstaller created files + rm -rf *.spec -clean-all: clean - rm -R $(VENV_PATH) +distclean: clean + # Virtual environment + rm -rf "$(VENV_PATH)" -.PHONY: clean clean-all +.PHONY: clean distclean diff --git a/src/revpipyload/__main__.py b/src/revpipyload/__main__.py index 6c040c1..f7e6e08 100644 --- a/src/revpipyload/__main__.py +++ b/src/revpipyload/__main__.py @@ -17,15 +17,8 @@ if __package__ == "": if __name__ == "__main__": import sys - if len(sys.argv) == 2 and "--version" in sys.argv: - # Catch --version, if this is the only argument (sys.argv[0] is always the script name) - from revpipyload import __version__ + # Use absolut import in the __main__ module + from revpipyload.revpipyload import main - print(__version__) - sys.exit(0) - - else: - from revpipyload.revpipyload import main - - # Run the main application of this package - sys.exit(main()) + # Run the main application of this package + sys.exit(main()) diff --git a/src/revpipyload/proginit.py b/src/revpipyload/proginit.py index 79cebe0..d508627 100644 --- a/src/revpipyload/proginit.py +++ b/src/revpipyload/proginit.py @@ -10,6 +10,8 @@ import sys from argparse import ArgumentParser from configparser import ConfigParser +from . import __version__ + conf = ConfigParser() forked = False globalconffile = None @@ -42,6 +44,11 @@ def configure(): parser = ArgumentParser( description="RevolutionPi Python Loader" ) + parser.add_argument( + "--version", + action="version", + version="%(prog)s {0}".format(__version__) + ) parser.add_argument( "-d", "--daemon", action="store_true", dest="daemon", help="Run program as a daemon in background"