From 4ea8b3b0e34e4b110e6bab4ef611f9834fb13758 Mon Sep 17 00:00:00 2001 From: Joost Ellerbroek Date: Tue, 17 Dec 2024 16:16:46 +0100 Subject: [PATCH] hatch build and corresponding GH action --- .github/workflows/build_wheels.yml | 72 ++++++++++++++++++ hatch_build.py | 34 +++++++++ packaging/bluesky-guidata/pyproject.toml | 36 +++++++++ pyproject.toml | 95 ++++++++++++++++++++++++ requirements-gui.txt | 13 ---- requirements.txt | 7 -- setup.cfg | 26 ------- setup.py | 83 --------------------- setup_guidata.py | 50 ------------- setup_simdata.py | 49 ------------ 10 files changed, 237 insertions(+), 228 deletions(-) create mode 100644 .github/workflows/build_wheels.yml create mode 100644 hatch_build.py create mode 100644 packaging/bluesky-guidata/pyproject.toml create mode 100644 pyproject.toml delete mode 100644 requirements-gui.txt delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 setup_guidata.py delete mode 100644 setup_simdata.py diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 0000000000..f6a804ac33 --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,72 @@ +name: Build and upload to PyPI + +on: + workflow_dispatch: + # pull_request: + # push: + # branches: + # - main + release: + types: + - published + +env: + CIBW_BUILD: cp310* cp311* cp312* cp313* + CIBW_ARCHS_MACOS: auto universal2 + CIBW_TEST_SKIP: "*universal2:arm64" + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # macos-13 is an intel runner, macos-14 is apple silicon + os: [ubuntu-latest, windows-latest, macos-13, macos-14] + + steps: + - uses: actions/checkout@v4 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.22.0 + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + upload_pypi: + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write + if: github.event_name == 'release' && github.event.action == 'published' + # or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this) + # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/download-artifact@v4 + with: + # unpacks all CIBW artifacts into dist/ + pattern: cibw-* + path: dist + merge-multiple: true + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_BLUESKY }} \ No newline at end of file diff --git a/hatch_build.py b/hatch_build.py new file mode 100644 index 0000000000..1288e8c2bd --- /dev/null +++ b/hatch_build.py @@ -0,0 +1,34 @@ +from pathlib import Path +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + +from setuptools import Distribution, Extension +from setuptools.command import build_ext + +def get_numpy_include(): + import numpy + return [numpy.get_include()] + + +class CustomHook(BuildHookInterface): + def initialize(self, version, build_data): + print(version, build_data) + extensions = [ + Extension('bluesky.tools.geo._cgeo', ['bluesky/tools/geo/src_cpp/_cgeo.cpp']), + Extension('bluesky.traffic.asas.cstatebased', ['bluesky/traffic/asas/src_cpp/cstatebased.cpp'], include_dirs=['bluesky/tools/geo/src_cpp'])] + + dist = Distribution(dict(name='extended', include_dirs=get_numpy_include(), + ext_modules=extensions)) + dist.package_dir = "extended" + cmd = build_ext.build_ext(dist) + cmd.verbose = True # type: ignore + cmd.ensure_finalized() # type: ignore + cmd.run() + buildpath = Path(cmd.build_lib) + + # Provide locations of compiled modules + force_include = {(buildpath / cmd.get_ext_filename('bluesky.tools.geo._cgeo')).as_posix(): cmd.get_ext_filename('bluesky.tools.geo._cgeo'), + (buildpath / cmd.get_ext_filename('bluesky.traffic.asas.cstatebased')).as_posix(): cmd.get_ext_filename('bluesky.traffic.asas.cstatebased')} + + build_data['pure_python'] = False + build_data['infer_tag'] = True + build_data['force_include'].update(force_include) \ No newline at end of file diff --git a/packaging/bluesky-guidata/pyproject.toml b/packaging/bluesky-guidata/pyproject.toml new file mode 100644 index 0000000000..db707e2717 --- /dev/null +++ b/packaging/bluesky-guidata/pyproject.toml @@ -0,0 +1,36 @@ +[project] +name = "bluesky-guidata" +version = "1.0.0" + +authors = [ + { name="Joost Ellerbroek", email="j.ellerbroek@tudelft.nl" }, + { name="Jacco Hoekstra", email="j.m.hoekstra@tudelft.nl" } +] + +description = "Resources for the BlueSky Open ATM Simulator GUI" +readme = "../../README.md" +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python :: 3", + "Development Status :: 4 - Beta", + + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", + + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + + "Operating System :: OS Independent", +] +keywords = ['ATM', 'transport', 'simulation', 'aviation', 'aircraft'] + +[project.urls] +Homepage = "https://github.com/TUDelft-CNS-ATM/bluesky" +Issues = "https://github.com/TUDelft-CNS-ATM/bluesky/issues" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.sdist.force-include] +"../../bluesky/resources/graphics" = "bluesky/resources/graphics" +"../../bluesky/resources/html" = "bluesky/resources/html" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..d85ce7eb36 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,95 @@ +[project] +name = "bluesky-simulator" +# dynamic = ["version"] +version = "1.0.0" +dependencies = [ + "numpy >= 2.0.0", + "scipy >= 1.13.0", + "matplotlib >= 3.9.0", + "pandas >= 2.2.0", + "msgpack >= 1.0.0", + "zmq" +] + +authors = [ + { name="Joost Ellerbroek", email="j.ellerbroek@tudelft.nl" }, + { name="Jacco Hoekstra", email="j.m.hoekstra@tudelft.nl" } +] + +description = "The Open Air Traffic Simulator." +readme = "README.md" +license = {file = "LICENSE"} +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python :: 3", + "Development Status :: 4 - Beta", + + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", + + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + + "Operating System :: OS Independent", +] +keywords = ['ATM', 'transport', 'simulation', 'aviation', 'aircraft'] + +[project.optional-dependencies] +pygame = ["pygame"] +qt6 = [ + "pyopengl", + "PyQt6", + "PyQt6-WebEngine", + "bluesky-guidata" +] +console = ["textual"] +full =[ + "pygame", + "pyopengl", + "PyQt6", + "PyQt6-WebEngine", + "textual", + "bluesky-guidata", +] +# For headless (server-only) bluesky environment: pip install bluesky-simulator[headless] +headless = [ + # no extra dependencies +] + +[project.scripts] +bluesky = "bluesky.__main__:main" + +[project.urls] +Homepage = "https://github.com/TUDelft-CNS-ATM/bluesky" +Issues = "https://github.com/TUDelft-CNS-ATM/bluesky/issues" +Documentation = "https://github.com/TUDelft-CNS-ATM/bluesky/wiki" +Repository = "https://github.com/TUDelft-CNS-ATM/bluesky" +# Changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build] +include = [ + "bluesky/*", +] +exclude = [ + 'docs', + 'utils', + 'bluesky/test', + 'bluesky/resources/graphics', + 'bluesky/resources/html' +] + + +[tool.hatch.build.targets.wheel.hooks.custom] +dependencies = ["setuptools>=69.1.1", "numpy"] + +# [tool.hatch.build.targets.wheel.hooks.cython] +# dependencies = ["hatch-cython"] + +# [tool.hatch.build.targets.wheel.hooks.cython.options] +# # include .h or .cpp directories +# includes = [] +# # include numpy headers +# include_numpy = true \ No newline at end of file diff --git a/requirements-gui.txt b/requirements-gui.txt deleted file mode 100644 index 60a088138f..0000000000 --- a/requirements-gui.txt +++ /dev/null @@ -1,13 +0,0 @@ -PyQt6 -PyQt6-WebEngine -pygame -pyopengl -numpy >= 2.0.0 -scipy >= 1.13.0 -matplotlib >= 3.9.0 -pandas >= 2.2.0 -msgpack >= 1.0.0 -zmq -textual -bluesky-simdata -bluesky-guidata \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1724b36e8b..0000000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -numpy >= 2.0.0 -scipy >= 1.13.0 -matplotlib >= 3.9.0 -msgpack >= 1.0.0 -zmq -pandas >= 2.2.0 -bluesky-simdata \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e0c4a12a72..0000000000 --- a/setup.cfg +++ /dev/null @@ -1,26 +0,0 @@ -[extras] -pygame = - pygame -qt5 = - pyopengl - PyQt5 - PyQtWebEngine-Qt5 - bluesky-guidata -qt6 = - pyopengl - PyQt6 - PyQt6-WebEngine - bluesky-guidata -console = - textual -full = - pygame - pyopengl - PyQt6 - PyQt6-WebEngine - textual - bluesky-guidata -# For headless (server-only) bluesky environment: pip install bluesky-simulator[headless] -headless = - # already defined in requirements.txt - \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index f929001051..0000000000 --- a/setup.py +++ /dev/null @@ -1,83 +0,0 @@ -# Always prefer setuptools over distutils -import os -import sys -from setuptools import setup, find_packages, Extension -import configparser - - -def get_numpy_include(): - import numpy - return numpy.get_include() - -here = os.path.abspath(os.path.dirname(__file__)) - -# Get the long description from the README file -with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - -# Get base requirements from requirements.txt -with open(os.path.join(here, 'requirements.txt'), encoding='utf-8') as f: - install_requires = f.readlines() - -# get extra requirements from setup.cfg -parser = configparser.ConfigParser() -parser.read('%s/setup.cfg' % here) -extras_requirements = {k: [vi.strip().split('#') for vi in v.split('\n') if vi] - for (k, v) in dict(parser['extras']).items()} -extras_requirements.update({ - 'dev': ['check-manifest'], - 'test': ['coverage', 'flake8', 'radon', 'nose'], -}) - -setup( - name='bluesky-simulator', # 'bluesky' package name already taken in PyPI - use_calver=True, - setup_requires=['calver', 'numpy'], - install_requires=install_requires, - extras_require=extras_requirements, - author='The BlueSky community', - license='GNU General Public License v3 (GPLv3)', - maintainer='Jacco Hoekstra and Joost Ellerbroek', - description='The Open Air Traffic Simulator', - long_description=long_description, - long_description_content_type="text/markdown", - url='https://github.com/TUDelft-CNS-ATM/bluesky', - classifiers=[ - 'Development Status :: 4 - Beta', - - # Indicate who your project is intended for - 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering', - - # Pick your license as you wish - 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - - # Specify the Python versions you support here. In particular, ensure - # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10' - ], - - # This field adds keywords for your project which will appear on the - keywords='atm transport simulation aviation aircraft', - packages=find_packages(exclude=['contrib', 'docs', 'tests', 'bluesky.resources.graphics', 'bluesky.resources.html', 'bluesky.resources.navdata', 'bluesky.resources.performance']),# Required - include_package_data=True, - exclude_package_data={'bluesky': ['resources/graphics/*', 'resources/html/*', 'resources/navdata/*', 'resources/performance/*']}, - package_data={ - 'bluesky': ['resources/*'] - }, - entry_points={ - 'console_scripts': [ - 'bluesky=bluesky.__main__:main', - ], - }, - - project_urls={ - 'Source': 'https://github.com/TUDelft-CNS-ATM/bluesky', - }, - include_dirs=[get_numpy_include()], - ext_modules=[Extension('bluesky.tools.geo._cgeo', ['bluesky/tools/geo/src_cpp/_cgeo.cpp']), - Extension('bluesky.traffic.asas.cstatebased', ['bluesky/traffic/asas/src_cpp/cstatebased.cpp'], include_dirs=['bluesky/tools/src_cpp'])] -) diff --git a/setup_guidata.py b/setup_guidata.py deleted file mode 100644 index db2b24ba11..0000000000 --- a/setup_guidata.py +++ /dev/null @@ -1,50 +0,0 @@ -from setuptools import setup, findall -from os import path - - -# Get the long description from the README file -here = path.abspath(path.dirname(__file__)) -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - - -setup( - name='bluesky-guidata', - use_calver=True, - setup_requires=['calver'], - author='The BlueSky community', - license='GNU General Public License v3 (GPLv3)', - maintainer='Jacco Hoekstra and Joost Ellerbroek', - description='The Open Air Traffic Simulator - GUI resources', - long_description=long_description, - long_description_content_type="text/markdown", - url='https://github.com/TUDelft-CNS-ATM/bluesky', - classifiers=[ - 'Development Status :: 4 - Beta', - - # Indicate who your project is intended for - 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering', - - # Pick your license as you wish - 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - - # Specify the Python versions you support here. In particular, ensure - # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10' - ], - - # This field adds keywords for your project which will appear on the - keywords='atm transport simulation aviation aircraft', - packages=['bluesky.resources.graphics', 'bluesky.resources.html'], # Required - package_data={'bluesky.resources.graphics': [f.replace('bluesky/resources/graphics/', '', 1) for f in findall('bluesky/resources/graphics')], - 'bluesky.resources.html': [f.replace('bluesky/resources/html/', '', 1) for f in findall('bluesky/resources/html')]}, - exclude_package_data={'bluesky.resources.graphics': ['world.jpg']}, - project_urls={ - 'Source': 'https://github.com/TUDelft-CNS-ATM/bluesky', - }, - zip_safe=False -) \ No newline at end of file diff --git a/setup_simdata.py b/setup_simdata.py deleted file mode 100644 index a241ccbba1..0000000000 --- a/setup_simdata.py +++ /dev/null @@ -1,49 +0,0 @@ -from setuptools import setup, findall -from os import path - - -# Get the long description from the README file -here = path.abspath(path.dirname(__file__)) -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - - -setup( - name='bluesky-simdata', - use_calver=True, - setup_requires=['calver'], - author='The BlueSky community', - license='GNU General Public License v3 (GPLv3)', - maintainer='Jacco Hoekstra and Joost Ellerbroek', - description='The Open Air Traffic Simulator - simulation resources', - long_description=long_description, - long_description_content_type="text/markdown", - url='https://github.com/TUDelft-CNS-ATM/bluesky', - classifiers=[ - 'Development Status :: 4 - Beta', - - # Indicate who your project is intended for - 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering', - - # Pick your license as you wish - 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - - # Specify the Python versions you support here. In particular, ensure - # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10' - ], - - # This field adds keywords for your project which will appear on the - keywords='atm transport simulation aviation aircraft', - packages=['bluesky.resources.performance', 'bluesky.resources.navdata'], # Required - package_data={'bluesky.resources.performance': [f.replace('bluesky/resources/performance/', '', 1) for f in findall('bluesky/resources/performance')], - 'bluesky.resources.navdata': [f.replace('bluesky/resources/navdata/', '', 1) for f in findall('bluesky/resources/navdata')]}, - project_urls={ - 'Source': 'https://github.com/TUDelft-CNS-ATM/bluesky', - }, - zip_safe=False -) \ No newline at end of file