From 4d667f1e2bddfb11b8304434093e1b9d9a5376cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Mon, 18 Mar 2024 15:54:30 +0100 Subject: [PATCH 1/2] pyproject.toml: Move the project away from setup.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Leonard Göhrs --- Makefile | 15 +++-- REQUIREMENTS.packaging.txt | 2 - REQUIREMENTS.txt | 2 - fastentrypoints.py | 110 ------------------------------------- pyproject.toml | 40 +++++++++++++- setup.cfg | 7 --- setup.py | 29 ---------- 7 files changed, 47 insertions(+), 158 deletions(-) delete mode 100644 REQUIREMENTS.packaging.txt delete mode 100644 REQUIREMENTS.txt delete mode 100644 fastentrypoints.py delete mode 100644 setup.cfg delete mode 100755 setup.py diff --git a/Makefile b/Makefile index 30b38da..abd94cf 100644 --- a/Makefile +++ b/Makefile @@ -6,25 +6,28 @@ PYTHON_TESTING_ENV=$(PYTHON_ENV_ROOT)/$(PYTHON)-qa-env .PHONY: clean # packaging environment ####################################################### -$(PYTHON_PACKAGING_VENV)/.created: REQUIREMENTS.packaging.txt +$(PYTHON_PACKAGING_VENV)/.created: rm -rf $(PYTHON_PACKAGING_VENV) && \ $(PYTHON) -m venv $(PYTHON_PACKAGING_VENV) && \ . $(PYTHON_PACKAGING_VENV)/bin/activate && \ - pip install --upgrade pip && \ - pip install -r REQUIREMENTS.packaging.txt + python3 -m pip install --upgrade pip && \ + python3 -m pip install build twine && \ date > $(PYTHON_PACKAGING_VENV)/.created +.PHONY: packaging-env build _release + packaging-env: $(PYTHON_PACKAGING_VENV)/.created -sdist: packaging-env +build: packaging-env . $(PYTHON_PACKAGING_VENV)/bin/activate && \ rm -rf dist *.egg-info && \ - ./setup.py sdist + python3 -m build -_release: sdist +_release: build . $(PYTHON_PACKAGING_VENV)/bin/activate && \ twine upload dist/* + # helper ###################################################################### clean: rm -rf $(PYTHON_ENV_ROOT) diff --git a/REQUIREMENTS.packaging.txt b/REQUIREMENTS.packaging.txt deleted file mode 100644 index 69c408a..0000000 --- a/REQUIREMENTS.packaging.txt +++ /dev/null @@ -1,2 +0,0 @@ -setuptools>=36.5.0 -twine diff --git a/REQUIREMENTS.txt b/REQUIREMENTS.txt deleted file mode 100644 index 01f818e..0000000 --- a/REQUIREMENTS.txt +++ /dev/null @@ -1,2 +0,0 @@ -pyusb -termcolor diff --git a/fastentrypoints.py b/fastentrypoints.py deleted file mode 100644 index a4bd942..0000000 --- a/fastentrypoints.py +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright (c) 2016, Aaron Christianson -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -""" -Monkey patch setuptools to write faster console_scripts with this format: - - import sys - from mymodule import entry_function - sys.exit(entry_function()) - -This is better. - -(c) 2016, Aaron Christianson -http://github.com/ninjaaron/fast-entry_points -""" - -import re - -from setuptools.command import easy_install - -TEMPLATE = """\ -# -*- coding: utf-8 -*- -import re -import sys - -from {0} import {1} - -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) - sys.exit({2}())""" - - -@classmethod -def get_args(cls, dist, header=None): - """ - Yield write_script() argument tuples for a distribution's - console_scripts and gui_scripts entry points. - """ - if header is None: - header = cls.get_header() - spec = str(dist.as_requirement()) - for type_ in "console", "gui": - group = type_ + "_scripts" - for name, ep in dist.get_entry_map(group).items(): - # ensure_safe_name - if re.search(r"[\\/]", name): - raise ValueError("Path separators not allowed in script names") - script_text = TEMPLATE.format(ep.module_name, ep.attrs[0], ".".join(ep.attrs)) - args = cls._get_script_args(type_, name, header, script_text) - for res in args: - yield res - - -easy_install.ScriptWriter.get_args = get_args - - -def main(): - import os - import re - import shutil - import sys - - dests = sys.argv[1:] or ["."] - filename = re.sub("\.pyc$", ".py", __file__) - - for dst in dests: - shutil.copy(filename, dst) - manifest_path = os.path.join(dst, "MANIFEST.in") - setup_path = os.path.join(dst, "setup.py") - - # Insert the include statement to MANIFEST.in if not present - with open(manifest_path, "a+") as manifest: - manifest.seek(0) - manifest_content = manifest.read() - if "include fastentrypoints.py" not in manifest_content: - manifest.write(("\n" if manifest_content else "") + "include fastentrypoints.py") - - # Insert the import statement to setup.py if not present - with open(setup_path, "a+") as setup: - setup.seek(0) - setup_content = setup.read() - if "import fastentrypoints" not in setup_content: - setup.seek(0) - setup.truncate() - setup.write("import fastentrypoints\n" + setup_content) - - -print(__name__) diff --git a/pyproject.toml b/pyproject.toml index df4b5cd..44a3a9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,44 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "usbmuxctl" +description = "Tool to control an USB-Mux from the command line" +version = "0.1.3" +authors = [ + { name = "Chris Fiege", email = "python@pengutronix.de" }, +] +readme = "README.rst" +license = { "text" = "LGPL-2.1-or-later" } +dependencies = [ + "pyusb", + "termcolor" +] +classifiers = [ + "Environment :: Console", + "Natural Language :: English", + "Operating System :: Unix", + "Programming Language :: Python :: 3 :: Only" +] + +[project.urls] +homepage="https://github.com/linux-automation/usbmuxctl" +documentation="https://linux-automation.com/umx-M01/" + +[project.scripts] +usbmuxctl = "usbmuxctl.__main__:main" + +[tool.setuptools] +packages = [ + "usbmuxctl", + "usbmuxctl.firmware" +] +include-package-data = true + [tool.ruff] line-length = 119 exclude = [ - "fastentrypoints.py", "__pycache__", "usbmuxctl.egg-info", ".pybuild", @@ -9,7 +46,6 @@ exclude = [ "debian", "env", "venv", - "setup.py", "envs", "dist", ] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 00f8daf..0000000 --- a/setup.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[metadata] -long_description = file: README.rst -classifiers = - Environment :: Console - Natural Language :: English - Operating System :: Unix - Programming Language :: Python :: 3 :: Only diff --git a/setup.py b/setup.py deleted file mode 100755 index 9fd2655..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 - - -from setuptools import setup - -setup( - include_package_data=True, - name="usbmuxctl", - version="0.1.3", - author="Chris Fiege", - author_email="python@pengutronix.de", - license="LGPL-2.1-or-later", - url="https://github.com/linux-automation/usbmuxctl", - description="Tool to control an USB-Mux from the command line", - packages=[ - "usbmuxctl", - "usbmuxctl.firmware", - ], - install_requires=[ - "pyusb", - "termcolor", - ], - entry_points={ - "console_scripts": [ - "usbmuxctl = usbmuxctl.__main__:main", - ], - }, - classifiers=["License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)"], -) From 20095301c5a9fe38762b235013afc395ed1b2192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Mon, 18 Mar 2024 16:42:52 +0100 Subject: [PATCH 2/2] CI: add build GitHub action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is mostly to make sure that the `make build` target keeps working, but the generated source distribution and wheel may also come in handy. Signed-off-by: Leonard Göhrs --- .github/workflows/build.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..02df019 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,14 @@ +name: Build + +on: [push, pull_request] + +jobs: + build: + name: Source Distribution and Wheel + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: make build + - uses: actions/upload-artifact@v4 + with: + path: dist