From c5d7fa6d8f6628c4e01c87f435da94bfa1881bbe Mon Sep 17 00:00:00 2001 From: Tim Arnett Date: Fri, 12 Apr 2024 14:28:35 -0400 Subject: [PATCH] Added compiled wheel push to pypi in github actions, added another job for building pure python wheel for unsupported OS versions, changed setup.py to build for each case --- .github/workflows/publish-to-pypi.yml | 47 ++++++++++++-- setup.py | 89 +++++++++++++++------------ 2 files changed, 90 insertions(+), 46 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index da1cff4..0568a6b 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -14,8 +14,15 @@ on: types: [published] jobs: - deploy: - runs-on: windows-latest + deploy-compiled-for-windows: +# runs-on: windows-latest + runs-on: ${{ matrix.builds.os }} + strategy: + fail-fast: false + matrix: + builds: [ + { os: "windows-latest", python_requires: ">=3.10.0" }, + ] steps: - uses: actions/checkout@v3 - name: Set up Python @@ -25,11 +32,39 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish to PyPI + python -m pip install setuptools wheel twine==4.0.1 cibuildwheel==2.9.0 + - name: Build wheels + env: + CIBW_PROJECT_REQUIRES_PYTHON: ${{ matrix.builds.python_requires }} + CIBW_BUILD: "cp3*" + run: | + python -m cibuildwheel --output-dir wheelhouse + - name: Publish to PyPI env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{secrets.PYPI_API_TOKEN}} run: | - python setup.py sdist bdist_wheel - twine upload dist/* +# python setup.py sdist bdist_wheel +# twine upload dist/* + twine upload --skip-existing wheelhouse/* + pure-python-wheel-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.10 + - name: Install deps + run: | + python -m pip install wheel==0.37.1 twine==4.0.1 + - name: Build pure python wheel + env: + KESSLER_SKIP_COMPILE: "1" + run: pip wheel -w wheelhouse . + - name: Publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: | + twine upload --skip-existing wheelhouse/* \ No newline at end of file diff --git a/setup.py b/setup.py index 649a70a..85affa8 100644 --- a/setup.py +++ b/setup.py @@ -3,14 +3,11 @@ # NOTICE: This file is subject to the license agreement defined in file 'LICENSE', which is part of # this source code package. -from setuptools import setup - +from setuptools import setup, find_packages +import os with open('requirements.txt') as f: requirements = f.read().splitlines() -from setuptools import setup, find_packages -from mypyc.build import mypycify - import re VERSIONFILE="src/kesslergame/_version.py" verstrline = open(VERSIONFILE, "rt").read() @@ -21,39 +18,51 @@ else: raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,)) -# List of all Python modules to compile with MyPyC -mypyc_modules = [ - "src/kesslergame/asteroid.py", - "src/kesslergame/bullet.py", - "src/kesslergame/collisions.py", - "src/kesslergame/controller.py", - "src/kesslergame/controller_gamepad.py", - "src/kesslergame/kessler_game.py", - "src/kesslergame/mines.py", - "src/kesslergame/scenario.py", - "src/kesslergame/score.py", - "src/kesslergame/ship.py", - "src/kesslergame/team.py", - "src/kesslergame/graphics/graphics_base.py", - "src/kesslergame/graphics/graphics_handler.py", - "src/kesslergame/graphics/graphics_plt.py", - "src/kesslergame/graphics/graphics_tk.py", - "src/kesslergame/graphics/graphics_ue.py", - # Add __init__.py if you have specific initialization code that needs compilation. - #"src/__init__.py", - "src/kesslergame/__init__.py", - "src/kesslergame/graphics/__init__.py", -] - -setup( - name='KesslerGame', - version=verstr, - packages=find_packages(where='src', exclude=['examples', 'src.examples', '*.examples.*', 'examples.*']), - install_requires=requirements, - ext_modules=mypycify(mypyc_modules), - package_data={ - '': ['*.png'], - }, - package_dir={'': 'src'}, -) +if not bool(int(os.getenv('KESSLER_SKIP_COMPILE', '0'))): + from mypyc.build import mypycify + + # List of all Python modules to compile with MyPyC + mypyc_modules = [ + "src/kesslergame/asteroid.py", + "src/kesslergame/bullet.py", + "src/kesslergame/collisions.py", + "src/kesslergame/controller.py", + "src/kesslergame/controller_gamepad.py", + "src/kesslergame/kessler_game.py", + "src/kesslergame/mines.py", + "src/kesslergame/scenario.py", + "src/kesslergame/score.py", + "src/kesslergame/ship.py", + "src/kesslergame/team.py", + "src/kesslergame/graphics/graphics_base.py", + "src/kesslergame/graphics/graphics_handler.py", + "src/kesslergame/graphics/graphics_plt.py", + "src/kesslergame/graphics/graphics_tk.py", + "src/kesslergame/graphics/graphics_ue.py", + # Add __init__.py if you have specific initialization code that needs compilation. + # "src/__init__.py", + "src/kesslergame/__init__.py", + "src/kesslergame/graphics/__init__.py", + ] + + setup( + name='KesslerGame', + version=verstr, + packages=find_packages(where='src', exclude=['examples', 'src.examples', '*.examples.*', 'examples.*']), + install_requires=requirements, + ext_modules=mypycify(mypyc_modules), + package_data={ + '': ['*.png'], + }, + package_dir={'': 'src'}, + ) +else: + # This branch doesn't use mypyc compilation + setup( + name='KesslerGame', + version=verstr, + install_requires=requirements, + ) + +