From 92666f117d4a016c6aa2f6c1120a3a9409563811 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Tue, 3 Oct 2023 09:02:51 +0200 Subject: [PATCH] build: Add all necessary files for the build system All basic files for testing, building and distributing the project are added here. The Makefile can set up the virtual environment and create different package types from the project. --- MANIFEST.in | 10 ++++ Makefile | 119 +++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 + requirements.txt | 8 ++++ setup.py | 50 ++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b730d6b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,10 @@ +recursive-include .reuse * +recursive-include data * +recursive-include LICENSES * +include Makefile +include MANIFEST.in +include pyproject.toml +include README.md +include requirements.txt +include setup.py +recursive-include tests * diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4e68bb0 --- /dev/null +++ b/Makefile @@ -0,0 +1,119 @@ +SHELL := bash +MAKEFLAGS = --no-print-directory --no-builtin-rules +.DEFAULT_GOAL = all + +# Variables +PACKAGE = revpi_middleware +APP_NAME = RevPiMiddleware +APP_IDENT = com.revolutionpi.revpi-middleware + +# Python interpreter to use for venv creation +SYSTEM_PYTHON = python3 + +# Set path to create the virtual environment with package name +ifdef PYTHON3_VENV +VENV_PATH = $(PYTHON3_VENV)/$(PACKAGE) +else +VENV_PATH = venv +endif + +# Set targets for "all"-target +all: test build +.PHONY: all + +## Virtual environment creation with SYSTEM_PYTHON +venv: + # Start with empty environment + "$(SYSTEM_PYTHON)" -m venv "$(VENV_PATH)" + "$(VENV_PATH)/bin/pip" install --upgrade pip + "$(VENV_PATH)/bin/pip" install --upgrade -r requirements.txt + +venv-ssp: + # Include system installed site-packages and add just missing modules + "$(SYSTEM_PYTHON)" -m venv --system-site-packages "$(VENV_PATH)" + "$(VENV_PATH)/bin/pip" install --upgrade pip + "$(VENV_PATH)/bin/pip" install --upgrade -r requirements.txt + +.PHONY: venv venv-ssp + +# Choose python interpreter from venv or system +PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON)) + +# Read app version from program +APP_VERSION = $(shell "$(PYTHON)" src/$(PACKAGE) --version | cut -d ' ' -f 2) + +# Environment info +venv-info: + @echo Environment for $(APP_NAME) $(APP_VERSION) + @echo Using path: "$(VENV_PATH)" + +.PHONY: venv-info + +## Build steps +test: + PYTHONPATH=src "$(PYTHON)" -m pytest + +build: + "$(PYTHON)" -m setup sdist + "$(PYTHON)" -m setup bdist_wheel + +install: build + "$(PYTHON)" -m pip install dist/$(PACKAGE)-$(APP_VERSION)-*.whl + +uninstall: + "$(PYTHON)" -m pip uninstall --yes $(PACKAGE) + +.PHONY: test build install uninstall + +## PyInstaller +app-licenses: + mkdir -p dist + # Create a list of all installed libraries, their versions and licenses + "$(PYTHON)" -m piplicenses \ + --format=markdown \ + --output-file dist/bundled-libraries.md + # Create a list of installed libraries with complete project information + "$(PYTHON)" -m piplicenses \ + --with-authors \ + --with-urls \ + --with-description \ + --with-license-file \ + --no-license-path \ + --format=json \ + --output-file dist/open-source-licenses.json + "$(PYTHON)" -m piplicenses \ + --with-authors \ + --with-urls \ + --with-description \ + --with-license-file \ + --no-license-path \ + --format=plain-vertical \ + --output-file dist/open-source-licenses.txt + +app: app-licenses + "$(PYTHON)" -m PyInstaller -n $(APP_NAME) \ + --add-data="dist/bundled-libraries.md:$(PACKAGE)/open-source-licenses" \ + --add-data="dist/open-source-licenses.*:$(PACKAGE)/open-source-licenses" \ + --noconfirm \ + --clean \ + --onefile \ + src/$(PACKAGE)/__main__.py + +.PHONY: app-licenses app + +## Clean +clean: + # PyTest caches + rm -rf .pytest_cache + # Build artifacts + rm -rf build dist src/*.egg-info + # PyInstaller created files + rm -rf *.spec + # Pycaches + find . -type d -name '__pycache__' -exec rm -r {} \+ + +distclean: clean + # Virtual environment + rm -rf "$(VENV_PATH)" + +.PHONY: clean distclean diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..aa4949a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 100 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5caf05f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +# Build dependencies +pip-licenses +Pyinstaller +pytest-cov +setuptools +wheel + +# Runtime dependencies, must match install_requires in setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b8f085f --- /dev/null +++ b/setup.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +"""Setup-script for revpi-middleware package.""" +# SPDX-FileCopyrightText: 2025 KUNBUS GmbH +# SPDX-License-Identifier: GPL-2.0-or-later + +from setuptools import find_namespace_packages, setup + +from src.revpi_middleware.__about__ import __version__ + +with open("README.md") as fh: + # Load long description from readme file + long_description = fh.read() + +setup( + name="revpi_middleware", + version=__version__, + packages=find_namespace_packages("src"), + package_dir={"": "src"}, + include_package_data=True, + python_requires=">= 3.7", + install_requires=[ + # todo: Set Dependencies of this project + ], + entry_points={ + "console_scripts": [ + "revpi-middleware = revpi_middleware.main_application:main", + ], + }, + platforms=["revolution pi"], + url="https://revolutionpi.com/", + license="GPLv2", + license_files=["LICENSES/*"], + author="Sven Sager", + author_email="s.sager@kunbus.com", + maintainer="KUNBUS GmbH", + maintainer_email="support@kunbus.com", + description="Example projekt for a python project", + long_description=long_description, + long_description_content_type="text/markdown", + keywords=["revpi", "revolution pi", "plc", "automation"], + classifiers=[ + # A list of all classifiers: https://pypi.org/pypi?%3Aaction=list_classifiers + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Manufacturing", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", + "Operating System :: POSIX", + "Topic :: System :: Operating System", + ], +)