Skip to content

Commit

Permalink
Merge pull request #117 from libAtoms/22_meson
Browse files Browse the repository at this point in the history
BUILD: Switch to Meson for building
  • Loading branch information
pastewka committed Dec 20, 2022
2 parents b4f1b13 + 5c3ee47 commit 36aeec0
Show file tree
Hide file tree
Showing 49 changed files with 731 additions and 2,861 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
matscipy/_version.py export-subst
*.fs -linguist-detectable
.gitattributes text eol=lf
*.py text eol=lf
Expand Down
59 changes: 29 additions & 30 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This is partially adopted from scipy.
# See: https://github.com/scipy/scipy/blob/main/.github/workflows/wheels.yml
# License: 3-clause BSD, https://github.com/scipy/scipy/blob/main/LICENSE.txt

name: Build wheels

# Controls when the action will run.
Expand All @@ -15,49 +19,42 @@ on:

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }} ${{ matrix.buildplat[2] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
buildplat:
- [ubuntu-20.04, manylinux, x86_64]
- [macos-10.15, macosx, x86_64]
- [windows-2019, win, AMD64]

python: ["cp38", "cp39", "cp310", "cp311"]
fail-fast: false

env:
IS_32_BIT: ${{ matrix.buildplat[2] == 'x86' }}

steps:
- uses: actions/checkout@v2

- uses: ilammy/msvc-dev-cmd@v1
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v2

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.9.0
with:
python-version: '3.8'

- name: Build wheels
run: |
if [[ $RUNNER_OS == "Linux" ]]; then
for image in manylinux2010 manylinux2014; do
export CIBW_MANYLINUX_X86_64_IMAGE=$image
python -m cibuildwheel --output-dir wheelhouse
done
else
python -m cibuildwheel --output-dir wheelhouse
fi
uses: pypa/cibuildwheel@v2.11.3
env:
CIBW_SKIP: cp27-* cp35-* cp36-* cp311-* pp* *musllinux*
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_BEFORE_BUILD: "pip install oldest-supported-numpy"
CIBW_TEST_COMMAND: "cd {project}/tests; pip install -r ../requirements.txt; pytest"
CIBW_TEST_SKIP: "*"

# Uncomment to get SSH access for testing
# - name: Setup tmate session
# if: failure()
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 15
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}*
CIBW_ARCHS: ${{ matrix.buildplat[2] }}
CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_OS
CIBW_TEST_COMMAND: python {project}/tests/test_ffi.py

- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
name: ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}

- name: Release wheels
uses: softprops/action-gh-release@v1
Expand All @@ -73,7 +70,8 @@ jobs:
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ::set-output name=match::true
fi
shell: bash

- name: Deploy to PyPI
if: steps.check-tag.outputs.match == 'true'
run: |
Expand All @@ -82,3 +80,4 @@ jobs:
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
shell: bash
102 changes: 52 additions & 50 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test compilation and publish documentation

on:
push:
branches:
branches:
- master
tags:
- '*'
Expand All @@ -13,59 +13,61 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: install_python
run: |
sudo apt-get update -qy
sudo apt-get install -y python3-dev python3-pip libxml2-dev libxslt-dev zlib1g-dev
sudo pip3 install -r requirements.txt
- name: install_python
run: |
sudo apt-get update -qy
sudo apt-get install -y python3-dev python3-pip libxml2-dev libxslt-dev zlib1g-dev
sudo pip install --upgrade sphinxcontrib-napoleon sphinx_rtd_theme
- name: build
run: |
python3 setup.py build
sudo python3 setup.py install
- name: pytest
run: |
cd tests
pytest -s --verbose
- name: build
run: |
sudo pip install .[test]
- name: package_dist
run: |
sudo python3 setup.py sdist
- name: pytest
run: |
cd tests
pytest -s --verbose
# Standard drop-in approach that should work for most people.
- name: build_doc
run: |
cd docs
make html
cd ..
- name: package_dist
run: |
sudo pip install build
sudo python3 -m build . -s
# Publish built docs to gh-pages branch.
# ===============================
- name: Commit documentation changes
run: |
git clone https://github.com/libAtoms/matscipy.git --branch gh-pages --single-branch gh-pages
cp -r docs/_build/html/* gh-pages/
cd gh-pages
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update documentation" -a || true
# The above command will fail if no changes were present, so we ignore
# that.
# Standard drop-in approach that should work for most people.
- name: build_doc
run: |
cd docs
make html
cd ..
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
# Publish built docs to gh-pages branch.
# ===============================
- name: Commit documentation changes
run: |
git clone https://github.com/libAtoms/matscipy.git --branch gh-pages --single-branch gh-pages
cp -r docs/_build/html/* gh-pages/
cd gh-pages
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update documentation" -a || true
# The above command will fail if no changes were present, so we ignore
# that.
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
46 changes: 23 additions & 23 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: install_python
run: |
sudo apt-get update -qy
sudo apt-get install -y python3-dev python3-pip libxml2-dev libxslt-dev zlib1g-dev
sudo pip3 install -r requirements.txt
- name: build_c
run: |
python3 setup.py build
sudo python3 setup.py install
- name: pytest
run: |
cd tests
pytest -v --junitxml=report.xml --durations=20
- name: report
uses: mikepenz/action-junit-report@v2
if: always()
with:
report_paths: "**/report.xml"
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: install_python
run: |
sudo apt-get update -qy
sudo apt-get install -y python3-dev python3-pip python3-venv libxml2-dev libxslt-dev zlib1g-dev meson
- name: build_c
run: |
sudo pip install .[test]
- name: pytest
run: |
cd tests
pytest -v --junitxml=report.xml --durations=20
- name: report
uses: mikepenz/action-junit-report@v2
if: always()
with:
report_paths: "**/report.xml"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.gitignore
.idea

# Meson files
.mesonpy-native-file.ini

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ work in 2018, the branch could be called "18_line_scans".
Commits
-------
Prepend you commits with a shortcut indicating the type of changes they contain:
* API: changes to the user exposed API
* BUG: Bug fix
* BUILD: Changes to the build system
* CI: Changes to the CI configuration
* DOC: Changes to documentation strings or documentation in general (not only typos)
* ENH: Enhancement (e.g. a new feature)
* MAINT: Maintenance (e.g. fixing a typo)
* MAINT: Maintenance (e.g. fixing a typo, or changing code without affecting function)
* TST: Changes to the unit test environment
* WIP: Work in progress
* API: changes to the user exposed API

The changelog will be based on the content of the commits with tag BUG, API and ENH.

Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ v0.8.0 (not yet released)
- Calculator for traditional Ewald summation
- Analytic computation of Hessian and zero-temperature elastic constants for potentials with electrostatic interaction
- Writing and reading inhomogenous (and non numeric) data with savetbl/readtbl
- Changed build system to Meson

v0.7.0 (29Jul21)
----------------
Expand Down
15 changes: 10 additions & 5 deletions c/angle_distribution.c → c/angle_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
#define NPY_NO_DEPRECATED_API NPY_1_5_API_VERSION
#include <numpy/arrayobject.h>

#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#include <cmath>
#endif

#include "angle_distribution.h"

/*
Expand Down Expand Up @@ -72,11 +77,11 @@ py_angle_distribution(PyObject *self, PyObject *args)
PyObject *h_arr = PyArray_ZEROS(1, &dim, NPY_INT, 1);
PyObject *tmp_arr = PyArray_ZEROS(1, &dim, NPY_INT, 1);

npy_int *i = PyArray_DATA(i_arr);
npy_int *j = PyArray_DATA(j_arr);
double *r = PyArray_DATA(r_arr);
npy_int *h = PyArray_DATA(h_arr);
npy_int *tmp = PyArray_DATA(tmp_arr);
npy_int *i = (npy_int*)PyArray_DATA(i_arr);
npy_int *j = (npy_int*)PyArray_DATA(j_arr);
double *r = (double*)PyArray_DATA(r_arr);
npy_int *h = (npy_int*)PyArray_DATA(h_arr);
npy_int *tmp = (npy_int*)PyArray_DATA(tmp_arr);

npy_int last_i = i[0], i_start = 0;
memset(tmp, 0, nbins*sizeof(npy_int));
Expand Down
33 changes: 33 additions & 0 deletions c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Find numpy include directory
include_numpy = run_command(python,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()

link_args = []

# Statically linking gcc components if on windows
if build_machine.system() == 'windows'
link_args = ['-static-libstdc++', '-static-libgcc', '-static']
endif


# Build and install the extension module
module = python.extension_module(
'_matscipy', # Name of the module
[ # List of sources
'angle_distribution.cpp',
'islands.cpp',
'neighbours.c',
'ring_statistics.cpp',
'tools.c',
'matscipymodule.c'
],
install: true, # Install it
subdir: 'matscipy',
include_directories: include_directories(include_numpy),
dependencies: [ # List of dependencies
python.dependency(), # Add Python.h as dependency
],
link_args: link_args,
)
Loading

0 comments on commit 36aeec0

Please sign in to comment.