From 5f8eafe93cb04c956124f90dd325d2b5452f2c95 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 14 Nov 2025 19:37:43 +0100 Subject: [PATCH] Move build to PEP 517 This update ensures compatibility with modern tools like pip, build, and pyproject.toml, and helps avoid deprecation issues with legacy setup.py-based builds. It also improves reproducibility and security by enabling isolated builds, which is increasingly important for CI/CD pipelines and downstream packaging systems. --- .github/workflows/publish.yml | 20 ++++---------------- .github/workflows/test.yml | 6 +++--- gwh/__main__.py | 16 +++++++++++----- gwh/__version__.py | 3 --- pyproject.toml | 32 ++++++++++++++++++++++++++++++++ setup.py | 24 ------------------------ 6 files changed, 50 insertions(+), 51 deletions(-) delete mode 100644 gwh/__version__.py create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e52625a..f1209b5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,19 +8,7 @@ jobs: name: build and publish to pypi runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Set version from tag - if: startsWith(github.ref, 'refs/tags') - run: | - # from refs/tags/1.2.3 get 1.2.3 - VERSION=$( basename $GITHUB_REF ) - PLACEHOLDER='__version__ = "0.0.0"' - VERSION_FILE='gwh/__version__.py' - # fail out if placeholder not found - grep "$PLACEHOLDER" "$VERSION_FILE" - sed -i "s/$PLACEHOLDER/__version__ = \"${VERSION}\"/" "$VERSION_FILE" - shell: bash + - uses: actions/checkout@v5 - name: install, test cli run: | @@ -29,12 +17,12 @@ jobs: - name: install dependencies & build run: | - pip3 install setuptools wheel - python3 setup.py sdist bdist_wheel + pip3 install build + python3 -m build - name: publish to PyPi if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ - password: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe399da..af4f628 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: name: build and publish to testpypi runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: install, test cli run: | @@ -14,8 +14,8 @@ jobs: - name: install dependencies & build run: | - pip3 install setuptools wheel - python3 setup.py sdist bdist_wheel + pip3 install build + python3 -m build - name: publish to Test PyPi uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/gwh/__main__.py b/gwh/__main__.py index d47c20c..f86e4b1 100644 --- a/gwh/__main__.py +++ b/gwh/__main__.py @@ -1,14 +1,17 @@ import argparse import json -from .__version__ import ( - __package__, - __version__ -) +from importlib.metadata import version, PackageNotFoundError + +try: + __version__ = version("gwh") +except PackageNotFoundError: + __version__ = "unknown" + from gwh import app import gwh -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser(prog="python -m gwh", description="GitLab webhook handler") parser.add_argument("config", help="path to repos configuration") parser.add_argument("--version", action="version", version=__package__ + " " + __version__) @@ -30,3 +33,6 @@ app.debug = args.debug app.run(host=args.host, port=args.port) + +if __name__ == "__main__": + main() diff --git a/gwh/__version__.py b/gwh/__version__.py deleted file mode 100644 index e84cfd0..0000000 --- a/gwh/__version__.py +++ /dev/null @@ -1,3 +0,0 @@ -__package__ = "gwh" -# version is injected at build, do not change here -__version__ = "0.0.0" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..be74cce --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[build-system] +requires = ["setuptools>=40.6.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "gwh" +version = "1.1.0" +description = "Webhook Handler for GitLab" +readme = "README.md" +authors = [ + { name = "Andy Hebrank", email = "ahebrank@gmail.com" } +] +license = "Apache-2.0" +requires-python = ">=3.8" +dependencies = [ + "Flask>=1.0", + "requests>=2.19.0" +] + +[project.urls] +Homepage = "https://github.com/ahebrank/gitlab-webhook-handler" +Repository = "https://github.com/ahebrank/gitlab-webhook-handler.git" +Issues = "https://github.com/ahebrank/gitlab-webhook-handler/issues" + +[tool.setuptools] +packages = ["gwh"] + +[tool.setuptools.package-data] +gwh = ["repos.json.example"] + +[project.scripts] +gwh = "gwh.__main__:main" diff --git a/setup.py b/setup.py deleted file mode 100644 index 56e426a..0000000 --- a/setup.py +++ /dev/null @@ -1,24 +0,0 @@ -import os -from setuptools import setup - -about = {} -here = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(here, 'gwh', '__version__.py'), encoding='utf-8') as f: - exec(f.read(), about) - -setup( - name=about['__package__'], - version=about['__version__'], - author='Andy Hebrank', - author_email='ahebrank@gmail.com', - packages=['gwh'], - url='https://github.com/ahebrank/gitlab-webhook-handler', - description='Webhook Handler for GitLab', - license='Apache License, Version 2.0', - long_description=open('README.md', encoding='utf-8').read(), - long_description_content_type='text/markdown', - install_requires=[ - 'Flask>=1.0', - 'requests>=2.19.0' - ] -)