diff --git a/.github/workflows/build-necpp-wheels.yml b/.github/workflows/build-necpp-wheels.yml new file mode 100644 index 0000000..b1255a2 --- /dev/null +++ b/.github/workflows/build-necpp-wheels.yml @@ -0,0 +1,126 @@ +name: Build and upload necpp to PyPI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + release: + types: + - published + +jobs: + build_wheels: + name: Build necpp wheels on ${{ matrix.os }} + runs-on: ${{ matrix.runs-on }} + permissions: + contents: read + strategy: + matrix: + include: + - os: linux + runs-on: ubuntu-latest + - os: macos-intel + runs-on: macos-15 + - os: macos-arm + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install build dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y swig autoconf automake libtool + + - name: Install build dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew install swig autoconf automake libtool + + - name: Configure necpp_src + shell: bash + run: | + cd necpp_src + make -f Makefile.git + ./configure + + - name: Setup package directory and generate SWIG wrapper + shell: bash + run: | + cd necpp + ln -s ../necpp_src . + swig -I../necpp_src/src/ -python necpp.i + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.5 + env: + CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-*" + CIBW_SKIP: "*-musllinux_*" + CIBW_BUILD_VERBOSITY: 1 + with: + package-dir: necpp + output-dir: wheelhouse + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-necpp-${{ matrix.os }} + path: ./wheelhouse/*.whl + + build_sdist: + name: Build necpp source distribution + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y swig autoconf automake libtool + + - name: Configure necpp_src + run: | + cd necpp_src + make -f Makefile.git + ./configure + + - name: Setup package directory and generate SWIG wrapper + run: | + cd necpp + ln -s ../necpp_src . + swig -I../necpp_src/src/ -python necpp.i + + - name: Build sdist + run: | + cd necpp + pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist-necpp + path: necpp/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' + 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 diff --git a/.github/workflows/build-pynec-wheels.yml b/.github/workflows/build-pynec-wheels.yml new file mode 100644 index 0000000..bb89d90 --- /dev/null +++ b/.github/workflows/build-pynec-wheels.yml @@ -0,0 +1,126 @@ +name: Build and upload PyNEC to PyPI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + release: + types: + - published + +jobs: + build_wheels: + name: Build PyNEC wheels on ${{ matrix.os }} + runs-on: ${{ matrix.runs-on }} + permissions: + contents: read + strategy: + matrix: + include: + - os: linux + runs-on: ubuntu-latest + - os: macos-intel + runs-on: macos-15 + - os: macos-arm + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install build dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y swig autoconf automake libtool + + - name: Install build dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew install swig autoconf automake libtool + + - name: Configure necpp_src + shell: bash + run: | + cd necpp_src + make -f Makefile.git + ./configure + + - name: Setup package directory and generate SWIG wrapper + shell: bash + run: | + cd PyNEC + ln -s ../necpp_src . + swig -Wall -c++ -python PyNEC.i + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.5 + env: + CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-*" + CIBW_SKIP: "*-musllinux_*" + CIBW_BUILD_VERBOSITY: 1 + with: + package-dir: PyNEC + output-dir: wheelhouse + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-pynec-${{ matrix.os }} + path: ./wheelhouse/*.whl + + build_sdist: + name: Build PyNEC source distribution + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y swig autoconf automake libtool + + - name: Configure necpp_src + run: | + cd necpp_src + make -f Makefile.git + ./configure + + - name: Setup package directory and generate SWIG wrapper + run: | + cd PyNEC + ln -s ../necpp_src . + swig -Wall -c++ -python PyNEC.i + + - name: Build sdist + run: | + cd PyNEC + pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist-pynec + path: PyNEC/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' + 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 diff --git a/Makefile b/Makefile index 7442de6..dd1eb58 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -PLAT=manylinux1_x86_64 -DOCKER_IMAGE=quay.io/pypa/manylinux2010_x86_64 +PLAT=manylinux2_x86_28 +DOCKER_IMAGE=quay.io/pypa/manylinux2014_x86_64 PRE_CMD= docker-wheels: docker run --rm -e PLAT=${PLAT} -v `pwd`:/io ${DOCKER_IMAGE} ${PRE_CMD} /io/build_wheels.sh auditwheel repair /output/mylibrary*whl -w /output - + install: docker pull ${DOCKER_IMAGE} diff --git a/PyNEC/build.sh b/PyNEC/build.sh index 728e305..4785138 100755 --- a/PyNEC/build.sh +++ b/PyNEC/build.sh @@ -14,5 +14,5 @@ make -f Makefile.git cd ${DIR} # Build PyNEC -swig3.0 -Wall -v -c++ -python PyNEC.i +swig -Wall -v -c++ -python PyNEC.i python3 setup.py build diff --git a/PyNEC/pyproject.toml b/PyNEC/pyproject.toml new file mode 100644 index 0000000..4973c84 --- /dev/null +++ b/PyNEC/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel", "numpy"] +build-backend = "setuptools.build_meta" diff --git a/PyNEC/setup.py b/PyNEC/setup.py index 6d2a6ed..bc33761 100644 --- a/PyNEC/setup.py +++ b/PyNEC/setup.py @@ -7,24 +7,30 @@ """ import distutils.sysconfig -from glob import glob import os +from glob import glob + import numpy as np import setuptools # Remove silly flags from the compilation to avoid warnings. -#cfg_vars = distutils.sysconfig.get_config_vars() -#for key, value in cfg_vars.items(): +# cfg_vars = distutils.sysconfig.get_config_vars() +# for key, value in cfg_vars.items(): # if type(value) == str: # cfg_vars[key] = value.replace("-Wstrict-prototypes", "") -# Generate a list of the sources. +# Generate a list of the sources. nec_sources = [] -nec_sources.extend([fn for fn in glob('necpp_src/src/*.cpp') - if not os.path.basename(fn).endswith('_tb.cpp') - if not os.path.basename(fn).startswith('net_solve.cpp') - if not os.path.basename(fn).startswith('nec2cpp.cpp') - if not os.path.basename(fn).startswith('necDiff.cpp')]) +nec_sources.extend( + [ + fn + for fn in glob("necpp_src/src/*.cpp") + if not os.path.basename(fn).endswith("_tb.cpp") + if not os.path.basename(fn).startswith("net_solve.cpp") + if not os.path.basename(fn).startswith("nec2cpp.cpp") + if not os.path.basename(fn).startswith("necDiff.cpp") + ] +) nec_sources.extend(glob("PyNEC_wrap.cxx")) nec_headers = [] @@ -35,39 +41,44 @@ # At the moment, the config.h file is needed, and this should be generated from the ./configure # command in the parent directory. Use ./configure --without-lapack to avoid dependance on LAPACK # -necpp_module = setuptools.Extension('_PyNEC', +necpp_module = setuptools.Extension( + "_PyNEC", sources=nec_sources, - - include_dirs=[np.get_include(), 'necpp_src/src', 'necpp_src/', 'necpp_src/win32/'], - extra_compile_args = ['-fPIC'], - extra_link_args = ['-lstdc++'], + include_dirs=[np.get_include(), "necpp_src/src", "necpp_src/", "necpp_src/win32/"], + extra_compile_args=["-fPIC"], + extra_link_args=["-lstdc++"], depends=nec_headers, - define_macros=[('BUILD_PYTHON', '1'), ('NPY_NO_DEPRECATED_API','NPY_1_7_API_VERSION')] - ) + define_macros=[ + ("BUILD_PYTHON", "1"), + ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), + ], +) with open("README.md", "r") as fh: long_description = fh.read() - -setuptools.setup (name = 'PyNEC', - version = '1.7.3.6', - author = "Tim Molteno", - author_email = "tim@physics.otago.ac.nz", - url = "http://github.com/tmolteno/python-necpp", - keywords = "nec2 nec2++ antenna electromagnetism radio", - description = "Python Antenna Simulation Module (nec2++) object-oriented interface", + +setuptools.setup( + name="PyNEC", + version="1.7.4", + author="Tim Molteno", + author_email="tim@physics.otago.ac.nz", + url="http://github.com/tmolteno/python-necpp", + keywords="nec2 nec2++ antenna electromagnetism radio", + description="Python Antenna Simulation Module (nec2++) object-oriented interface", long_description=long_description, long_description_content_type="text/markdown", include_package_data=True, - data_files=[('examples', ['example/test_rp.py'])], - ext_modules = [necpp_module], - requires = ['numpy'], - py_modules = ["PyNEC"], - license='GPLv2', + data_files=[("examples", ["example/test_rp.py"])], + ext_modules=[necpp_module], + requires=["numpy"], + py_modules=["PyNEC"], + license="GPLv2", classifiers=[ "Development Status :: 5 - Production/Stable", "Topic :: Scientific/Engineering", "Topic :: Communications :: Ham Radio", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", - 'Programming Language :: Python :: 3', - "Intended Audience :: Science/Research"] + "Programming Language :: Python :: 3", + "Intended Audience :: Science/Research", + ], ) diff --git a/necpp/pyproject.toml b/necpp/pyproject.toml new file mode 100644 index 0000000..9787c3b --- /dev/null +++ b/necpp/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/necpp/setup.py b/necpp/setup.py index f410e43..896ed98 100644 --- a/necpp/setup.py +++ b/necpp/setup.py @@ -1,19 +1,25 @@ #!/usr/bin/env python """ -setup.py file for necpp Python module. +setup.py file for necpp Python module. """ -from setuptools import setup, Extension -from glob import glob import os +from glob import glob + +from setuptools import Extension, setup nec_sources = [] -nec_sources.extend([fn for fn in glob('necpp_src/src/*.cpp') - if not os.path.basename(fn).endswith('_tb.cpp') - if not os.path.basename(fn).startswith('net_solve.cpp') - if not os.path.basename(fn).startswith('nec2cpp.cpp') - if not os.path.basename(fn).startswith('necDiff.cpp')]) +nec_sources.extend( + [ + fn + for fn in glob("necpp_src/src/*.cpp") + if not os.path.basename(fn).endswith("_tb.cpp") + if not os.path.basename(fn).startswith("net_solve.cpp") + if not os.path.basename(fn).startswith("nec2cpp.cpp") + if not os.path.basename(fn).startswith("necDiff.cpp") + ] +) nec_sources.extend(glob("necpp_wrap.c")) nec_headers = [] @@ -24,40 +30,43 @@ # At the moment, the config.h file is needed, and this should be generated from the ./configure # command in the parent directory. Use ./configure --without-lapack to avoid dependance on LAPACK # -necpp_module = Extension('_necpp', +necpp_module = Extension( + "_necpp", sources=nec_sources, - include_dirs=['necpp_src/src/', 'necpp_src/'], + include_dirs=["necpp_src/src/", "necpp_src/"], depends=nec_headers, - define_macros=[('BUILD_PYTHON', '1')] - ) + define_macros=[("BUILD_PYTHON", "1")], +) -with open('README.md') as f: +with open("README.md") as f: readme = f.read() -setup (name = 'necpp', - version = '1.7.3.5', - author = "Tim Molteno", - author_email = "tim@physics.otago.ac.nz", - url = "http://github.com/tmolteno/necpp", - keywords = "nec2 nec2++ antenna electromagnetism radio", - description = "Python Antenna Simulation Module (nec2++) C-style interface", +setup( + name="necpp", + version="1.7.4", + author="Tim Molteno", + author_email="tim@physics.otago.ac.nz", + url="http://github.com/tmolteno/necpp", + keywords="nec2 nec2++ antenna electromagnetism radio", + description="Python Antenna Simulation Module (nec2++) C-style interface", long_description=readme, long_description_content_type="text/markdown", include_package_data=True, - data_files=[('examples', ['necpp_src/example/test.py'])], - ext_modules = [necpp_module], - py_modules = ["necpp"], - license='GPLv2', + data_files=[("examples", ["necpp_src/example/test.py"])], + ext_modules=[necpp_module], + py_modules=["necpp"], + license="GPLv2", classifiers=[ - "Development Status :: 5 - Production/Stable", - "Topic :: Scientific/Engineering", - "Topic :: Communications :: Ham Radio", - "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - "Intended Audience :: Science/Research"] + "Development Status :: 5 - Production/Stable", + "Topic :: Scientific/Engineering", + "Topic :: Communications :: Ham Radio", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Intended Audience :: Science/Research", + ], ) diff --git a/necpp_src b/necpp_src index 0af22b1..049c556 160000 --- a/necpp_src +++ b/necpp_src @@ -1 +1 @@ -Subproject commit 0af22b10d5b8e96da412009ef1178f1b4131cbb8 +Subproject commit 049c556cb10769410b760dcea7ef341a3e08f78b