diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f173b3fe..9880cad4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -22,3 +22,7 @@ replace = version = '{new_version}' [bumpversion:file:xraylib.spec] search = Version: {current_version} replace = Version: {new_version} + +[bumpversion:file:pyproject.toml] +search = version = "{current_version}" +replace = version = "{new_version}" diff --git a/.github/workflows/build-publish-pypi.yml b/.github/workflows/build-publish-pypi.yml new file mode 100644 index 00000000..57303ee0 --- /dev/null +++ b/.github/workflows/build-publish-pypi.yml @@ -0,0 +1,71 @@ +name: Build and upload to PyPI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + tags: + - v* + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + 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 + + # https://github.com/actions/runner-images/issues/3342#issuecomment-2206538745 + - name: Install swig on macOS + if: startsWith(matrix.os, 'macos') + run: brew install swig + - name: Build wheels + uses: pypa/cibuildwheel@v2.19.2 + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl + retention-days: 1 + + 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 + retention-days: 1 + + upload_pypi: + name: Upload to pypi + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write + 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: + # To test: repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d5bb504..9c2e6311 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,33 +11,6 @@ on: - master jobs: - pip: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest] - python-version: ['3.9', '3.10', '3.11', '3.12'] - name: Pip install with Python ${{ matrix.python-version }} on ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - # https://github.com/actions/runner-images/issues/3342#issuecomment-2206538745 - - name: Install swig on macOS - run: brew install swig - if: ${{ matrix.os == 'macos-latest' }} - - name: Install xraylib with pip - run: | - python -m pip install -U numpy pip - python -m pip install . -vv - - name: Test importing xraylib - run: | - python -c "import xraylib" - python -c "import xraylib_np" - visual-studio: timeout-minutes: 60 runs-on: windows-latest @@ -61,7 +34,7 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1 - name: Build with meson run: | - meson setup meson-build --buildtype=release -Dpython=python -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled + meson setup meson-build --buildtype=release -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled meson compile -C meson-build meson test -C meson-build || (cat meson-build\meson-logs\testlog.txt) # ninja -v -C meson-build dist @@ -221,7 +194,7 @@ jobs: if: matrix.buildsystem == 'meson' run: | set -ex - meson setup meson-build -Dpython=/opt/homebrew/bin/python3 -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled + meson setup meson-build -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled meson compile -C meson-build meson test -C meson-build meson dist -C meson-build @@ -298,14 +271,13 @@ jobs: TARBALL=$(ls *.tar.gz) tar xfz $TARBALL cd ${TARBALL%.tar.gz} - meson setup meson-build -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled -Dpython=${XRL_PYTHON3} + meson setup meson-build -Dpython-bindings=enabled -Dpython-numpy-bindings=enabled meson compile -C meson-build set +ex env: CC: ${{matrix.cc}} CXX: ${{matrix.cxx}} LDFLAGS: ${{matrix.ldflags}} - XRL_PYTHON3: /opt/homebrew/bin/python3 linux: timeout-minutes: 60 @@ -315,7 +287,6 @@ jobs: image: - ubuntu:jammy - debian:bookworm - - rockylinux:8 - rockylinux:9 - fedora:latest cc: diff --git a/meson.build b/meson.build index fa56c51a..691f38bf 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('xraylib', 'c', - meson_version: '>= 0.56.0', + meson_version: '>= 0.60.0', version: '4.1.4', license: 'BSD', default_options: ['cpp_std=c++11',] @@ -104,7 +104,7 @@ subdir('cplusplus') if not (get_option('python-bindings').disabled() and get_option('python-numpy-bindings').disabled()) pymod = import('python') - python = pymod.find_installation(get_option('python'), required: false, modules: ['numpy',]) + python = pymod.find_installation(required: false, modules: ['numpy',]) if not python.found() or python.language_version().version_compare('< 3.6') if get_option('python-bindings').enabled() or get_option('python-numpy-bindings').enabled() diff --git a/meson_options.txt b/meson_options.txt index e5e4d7d7..93bf0334 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,4 +2,3 @@ option('fortran-bindings', type: 'feature', value: 'auto', description: 'Build F option('python-bindings', type: 'feature', value: 'auto', description: 'Build classic Python bindings') option('python-numpy-bindings', type: 'feature', value: 'auto', description: 'Build numpy Python bindings') option('swig', type : 'string', value : 'swig', description: 'Path to swig executable') -option('python', type : 'string', value : 'python3', description: 'Python interpreter to compile bindings for') diff --git a/pyproject.toml b/pyproject.toml index 6d34f721..ca059236 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,10 @@ [project] +name = "xraylib" authors = [ {name="Tom Schoonjans", email="Tom.Schoonjans@gmail.com"} ] description = "pip-installable xraylib" -requires-python = "~=3.7" +requires-python = "~=3.8" readme = "README.md" classifiers = [ "Intended Audience :: Developers", @@ -14,20 +15,31 @@ classifiers = [ dependencies = [ "numpy" ] +version = "4.1.4" [project.urls] repository = "https://github.com/tschoonj/xraylib" documentation = "https://github.com/tschoonj/xraylib" [build-system] -requires = ["mesonpep517", "ninja", "Cython", "numpy"] -build-backend = "mesonpep517.buildapi" +build-backend = 'mesonpy' +requires = ['meson-python', 'Cython', 'ninja', 'numpy'] -[tool.mesonpep517.metadata] -meson-python-option-name = "python" -meson-options = [ +[tool.meson-python.args] +setup = [ "-Ddefault_library=static", "-Dpython-bindings=enabled", - "-Dpython-numpy-bindings=enabled" + "-Dpython-numpy-bindings=enabled", + "-Dfortran-bindings=disabled", + "--vsenv" ] -summary = "pip-installable xraylib" \ No newline at end of file +install = ['--tags=python-runtime'] + +[tool.cibuildwheel] +skip = ["*-win32", "*-manylinux_i686", "pp*", "*musllinux*"] +build-verbosity = 1 +test-command = [ + 'python -c "import xraylib"', + 'python -c "import xraylib_np"', +] +test-skip = "cp38-macosx_*:arm64" \ No newline at end of file diff --git a/python/meson.build b/python/meson.build index 9c12dd34..e4811eb7 100644 --- a/python/meson.build +++ b/python/meson.build @@ -4,7 +4,7 @@ import numpy print(numpy.get_include()) ''' -rv = run_command(get_option('python'), '-c', numpy_include_script, check: false) +rv = run_command(python, '-c', numpy_include_script, check: false) if rv.returncode() != 0 error('Could not retrieve numpy include location. Please check that numpy has been installed.') endif @@ -43,6 +43,8 @@ if not get_option('python-bindings').disabled() ], install_dir: [false, python.get_install_dir(pure: false)], install: true, + install_tag: [false, 'python-runtime'] + ) xraylib_ext = python.extension_module('_xraylib', xraylib_wrap_c[0], dependencies : [python_dep, xraylib_lib_dep], @@ -50,6 +52,7 @@ if not get_option('python-bindings').disabled() install: true, install_dir: python.get_install_dir(pure: false), c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags, + install_tag: ['python-runtime'] ) subdir('tests') endif @@ -83,6 +86,7 @@ if not get_option('python-numpy-bindings').disabled() install: true, install_dir: python.get_install_dir(pure: false), c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags, + install_tag: ['python-runtime'], ) endif