diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2f5419da --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,223 @@ +name: Release +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + build_manylinux_x86_64_wheels: + name: Build manylinux_x86_64 + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_BUILD: "*manylinux_x86_64" + CIBW_ARCHS_LINUX: x86_64 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + - name: Upload wheels to pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + packages-dir: ./wheelhouse/ + + build_manylinux_aarch64_wheels: + name: Build manylinux_aarch64 + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_ARCHS_LINUX: aarch64 + CIBW_BUILD: "*manylinux_aarch64" + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + - name: Upload wheels to pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + packages-dir: ./wheelhouse/ + + build_musllinux_x86_64_wheels: + name: Build musllinux_x86_64 wheels + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_BUILD: "*musllinux_x86_64" + CIBW_ARCHS_LINUX: x86_64 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + - name: Upload wheels to pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + packages-dir: ./wheelhouse/ + + build_mac_wheels: + name: Build macos wheels + runs-on: macos-11 + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_ARCHS_MACOS: x86_64 arm64 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + - name: Upload wheels to pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + packages-dir: ./wheelhouse/ + + build_windows_wheels: + name: Build Windows wheels + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_ARCHS_WINDOWS: AMD64 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + - name: Upload wheels to pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + packages-dir: ./wheelhouse/ + + # Don't upload this one to pypi, otherwise it will be preferred over every compiled one + # We can host it here on github though for those that need it (re: jupyter-light). + pure_python: + name: Create pure-python wheel + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 + - name: Build pure python wheel and install + run: | + python -m pip install --user --upgrade build + python -m build + find ./dist/*.whl | xargs pip install + python -c "import geoana; geoana.show_config()" + - uses: actions/upload-artifact@v3 + with: + path: ./dist/geoana*.whl + + distribute: + name: distribute source and documentation + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + steps: + - uses: actions/checkout@v2 + - name: Setup environment + uses: mamba-org/setup-micromamba@v1 + with: + environment-name: geoana-test + create-args: >- + python=3.11 + numpy>=1.20 + scipy>=1.8 + libdlf + cython + setuptools_scm + meson-python>=0.14.0 + meson + ninja + build + discretize + numba + matplotlib + jupyter + utm + pytest + pytest-cov + sphinx + sphinx-gallery>=0.1.13 + pydata-sphinx-theme=0.13.3 + numpydoc>=1.5 + graphviz + pillow + cache-environment: true + - name: Prepare source distribution + run: | + python -m build --no-isolation --skip-dependency-check --sdist . + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + - name: Install Our Package + run: | + pip install --no-build-isolation --editable . --config-settings=setup-args="-Dwith_extensions=true" + - name: Build documentation + run: | + cd docs + make html + cd .. + - name: GitHub Pages + uses: crazy-max/ghaction-github-pages@v2.5.0 + with: + build_dir: docs/_build/html + fqdn: geoana.simpeg.xyz + jekyll: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + release: + name: Create Release + needs: [ + build_manylinux_x86_64_wheels, + build_manylinux_aarch64_wheels, + build_musllinux_x86_64_wheels, + build_mac_wheels, + build_windows_wheels, + pure_python + ] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + name: Retrieve assets + with: + name: artifact + path: dist + - name: Release to github + uses: softprops/action-gh-release@v1 + with: + files: dist/* + generate_release_notes: true + prerelease: false \ No newline at end of file diff --git a/.github/workflows/test_with_conda.yml b/.github/workflows/test_with_conda.yml index 6bf0b148..56b9ae65 100644 --- a/.github/workflows/test_with_conda.yml +++ b/.github/workflows/test_with_conda.yml @@ -1,11 +1,9 @@ -name: TestingWithConda +name: Testing With Conda on: push: branches: - '*' - tags: - - 'v*' pull_request: branches: - '*' @@ -70,91 +68,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true - distribute: - name: Publish Source to Pypi - needs: build_and_test - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} - steps: - - uses: actions/checkout@v2 - - name: Setup environment - uses: mamba-org/setup-micromamba@v1 - with: - environment-name: geoana-test - create-args: >- - python=3.10 - numpy>=1.20 - scipy>=1.8 - libdlf - cython - setuptools_scm - meson-python>=0.14.0 - meson - ninja - build - discretize - matplotlib - jupyter - utm - numba - pytest - pytest-cov - sphinx - sphinx-gallery>=0.1.13 - pydata-sphinx-theme=0.13.3 - numpydoc>=1.5 - graphviz - pillow - cache-environment: true - - name: Prepare source distribution - run: | - python -m build --no-isolation --skip-dependency-check --sdist . --config-settings=setup-args="-Dwith_extensions=true" - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - skip_existing: true - - name: Install package - run: | - pip install --no-build-isolation --editable . --config-settings=setup-args="-Dwith_extensions=true" - - name: Build documentation - run: | - cd docs - make html - cd .. - - name: GitHub Pages - # You may pin to the exact commit or the version. - uses: crazy-max/ghaction-github-pages@v2.5.0 - with: - # Git domain (default github.com) - # domain: # optional, default is github.com - # GitHub repository where assets will be deployed (default $GITHUB_REPOSITORY) - # repo: # optional - # Git branch where assets will be deployed - # target_branch: # optional, default is gh-pages - # Create incremental commit instead of doing push force - # keep_history: # optional, default is false - # Allow an empty commit to be created - # allow_empty_commit: # optional, default is true - # Build directory to deploy - build_dir: docs/_build/html - # The committer name and email address - # committer: # optional - # The author name and email address - # author: # optional - # Commit message - # commit_message: # optional - # Write the given domain name to the CNAME file - fqdn: geoana.simpeg.xyz - # Allow Jekyll to build your site - jekyll: false # optional, default is true - # If enabled, nothing will be pushed - # dry_run: true # optional, default is false - # Enable verbose output - # verbose: true # optional, default is false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/geoana/__init__.py b/geoana/__init__.py index 5f0357b1..0506bd98 100644 --- a/geoana/__init__.py +++ b/geoana/__init__.py @@ -21,3 +21,18 @@ from datetime import datetime __version__ = "unknown-" + datetime.today().strftime("%Y%m%d") + + +try: + import geoana.kernels._extensions.rTE + import geoana.kernels._extensions.potential_field_prism + compiled = True +except ImportError: + compiled = False +def show_config(): + info_dict = { + 'version': __version__, + 'compiled': compiled, + } + print(info_dict) + return info_dict \ No newline at end of file diff --git a/geoana/kernels/meson.build b/geoana/kernels/meson.build index ee3892a2..a0ba5bf8 100644 --- a/geoana/kernels/meson.build +++ b/geoana/kernels/meson.build @@ -10,7 +10,7 @@ py.install_sources( subdir: 'geoana/kernels' ) -with_extensions = get_option('with_extensions') + if with_extensions subdir('_extensions') endif \ No newline at end of file diff --git a/meson.build b/meson.build index 6d2e34a5..b217447a 100644 --- a/meson.build +++ b/meson.build @@ -21,31 +21,35 @@ print(get_version())''' ], ) +with_extensions = get_option('with_extensions') + # https://mesonbuild.com/Python-module.html py_mod = import('python') -py = py_mod.find_installation(pure: false) +py = py_mod.find_installation(pure: not with_extensions) py_dep = py.dependency() -cc = meson.get_compiler('c') -cpp = meson.get_compiler('cpp') -cy = meson.get_compiler('cython') -# generator() doesn't accept compilers, only found programs - cast it. -cython = find_program(cy.cmd_array()[0]) +if with_extensions + cc = meson.get_compiler('c') + cpp = meson.get_compiler('cpp') + cy = meson.get_compiler('cython') + # generator() doesn't accept compilers, only found programs - cast it. + cython = find_program(cy.cmd_array()[0]) -_global_c_args = cc.get_supported_arguments( - '-Wno-unused-but-set-variable', - '-Wno-unused-function', - '-Wno-conversion', - '-Wno-misleading-indentation', -) -add_project_arguments(_global_c_args, language : 'c') + _global_c_args = cc.get_supported_arguments( + '-Wno-unused-but-set-variable', + '-Wno-unused-function', + '-Wno-conversion', + '-Wno-misleading-indentation', + ) + add_project_arguments(_global_c_args, language : 'c') -# We need -lm for all C code (assuming it uses math functions, which is safe to -# assume for SciPy). For C++ it isn't needed, because libstdc++/libc++ is -# guaranteed to depend on it. -m_dep = cc.find_library('m', required : false) -if m_dep.found() - add_project_link_arguments('-lm', language : 'c') + # We need -lm for all C code (assuming it uses math functions, which is safe to + # assume for SciPy). For C++ it isn't needed, because libstdc++/libc++ is + # guaranteed to depend on it. + m_dep = cc.find_library('m', required : false) + if m_dep.found() + add_project_link_arguments('-lm', language : 'c') + endif endif subdir('geoana') \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 63d31039..fb119ce1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,8 +95,18 @@ Repository = 'https://github.com/simpeg/geoana.git' # skip building wheels for python 3.6, 3.7, all pypy versions, and specialty linux # processors (still does arm builds though). # skip windows 32bit -skip = "cp36-* cp37-* pp* *_ppc64le *_i686 *_s390x *-win32 cp38-musllinux_x86_64" +skip = "cp36-* cp37-* pp* *_ppc64le *_i686 *_s390x *-win32 cp38-musllinux_* *-musllinux_aarch64" build-verbosity = "3" -# test importing discretize to make sure externals are loadable. -test-command = 'python -c "import geoana; print(geoana.__version__)"' \ No newline at end of file +# test importing geoana to make sure externals are loadable. +test-command = 'python -c "import geoana; geoana.show_config()"' + +[tool.cibuildwheel.config-settings] +setup-args = '-Dwith_extensions=true' + +# use the visual studio compilers +[tool.cibuildwheel.windows.config-settings] +setup-args = [ + '-Dwith_extensions=true', + '--vsenv' +] diff --git a/tests/test_utils.py b/tests/test_utils.py index 4a3a98d5..bba5c81b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,8 +1,14 @@ import numpy as np +import geoana from geoana.utils import check_xyz_dim, mkvc, ndgrid import pytest +def test_config_info(): + info = geoana.show_config() + assert info['version'] == geoana.__version__ + + def test_mkvc(): x = np.random.rand(3, 2) x_test = np.concatenate((x[:, 0], x[:, 1]), axis=None)