Skip to content

Commit 7b8f0c4

Browse files
committed
Use meson-python to generate sdist for Python bindings
1 parent 08c3bcf commit 7b8f0c4

File tree

8 files changed

+123
-43
lines changed

8 files changed

+123
-43
lines changed

.github/workflows/wheel.yml

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,41 @@ name: wheel
33
on: [push, workflow_dispatch]
44

55
jobs:
6+
sdist:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Reorganize repository
11+
run: |
12+
git config user.email ""
13+
git config user.name "dummy"
14+
git subtree add --prefix python/subprojects/dftd4 . HEAD
15+
git mv {assets,python/dftd4}/parameters.toml
16+
git mv python/{mesonpep517,pyproject}.toml
17+
git commit -m "Python dist"
18+
- run: |
19+
pipx run build python/ --sdist --outdir .
20+
- uses: actions/upload-artifact@v3
21+
with:
22+
name: dftd4-python-sdist
23+
path: ./*.tar.gz
24+
retention-days: 5
25+
626
manylinux:
27+
needs:
28+
- sdist
729
runs-on: ubuntu-latest
830
container: condaforge/linux-anvil-cos7-x86_64
931
strategy:
1032
fail-fast: false
1133
matrix:
12-
python: ['3.6', '3.7', '3.8', '3.9', '3.10']
34+
python: ['3.7', '3.8', '3.9', '3.10']
1335

1436
defaults:
1537
run:
1638
shell: ${{ matrix.shell || 'bash -l {0}' }}
1739

1840
steps:
19-
- uses: actions/checkout@v2
20-
- uses: actions/checkout@v2
21-
with:
22-
path: python/subprojects/dftd4
2341
- name: Create environment
2442
run: >-
2543
mamba create -n wheel
@@ -28,20 +46,33 @@ jobs:
2846
fortran-compiler
2947
python=${{ matrix.python }}
3048
auditwheel
31-
--file assets/ci/wheel-req.txt
49+
git
50+
python
51+
pip
52+
python-build
53+
pkgconfig
54+
patchelf
55+
cffi
56+
numpy
57+
meson
58+
unzip
59+
wheel
60+
- name: Download sdist
61+
uses: actions/download-artifact@v2
62+
with:
63+
name: dftd4-python-sdist
3264
- name: Build wheel
3365
run: |
3466
conda activate wheel
3567
set -ex
36-
cp ../assets/parameters.toml dftd4
37-
cp {mesonpep517,pyproject}.toml
38-
python -m build . --wheel
39-
auditwheel show dist/*.whl
40-
auditwheel repair -w dist dist/*.whl --plat ${{ env.plat }}
41-
rm dist/*-linux_x86_64.whl
68+
tar xvf dftd4-*.tar.gz
69+
python -m build dftd4-*/ --wheel
70+
auditwheel show dftd4-*/dist/*.whl
71+
auditwheel repair -w . dftd4-*/dist/*.whl --plat ${{ env.plat }}
4272
env:
4373
plat: manylinux${{ matrix.python == '3.6' && '2010' || '_2_12' }}_x86_64
44-
working-directory: python
4574
- uses: actions/upload-artifact@v3
4675
with:
47-
path: python/dist/*.whl
76+
name: dftd4-python-${{ matrix.python }}
77+
path: ./*.whl
78+
retention-days: 5

config/template.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
set("@PROJECT_NAME@_WITH_API" @WITH_API@)
44
set("@PROJECT_NAME@_WITH_API_V2" @WITH_API_V2@)
55
set("@PROJECT_NAME@_WITH_OpenMP" @WITH_OpenMP@)
6+
set(
7+
"@PROJECT_NAME@_INCLUDE_DIRS"
8+
"@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@"
9+
"@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@module-dir@"
10+
)
611
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
712

813
if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")

include/dftd4.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
#define DFTD4_API_ENTRY extern "C"
2121
#else
2222
#define DFTD4_API_ENTRY extern
23+
#ifndef DFTD4_CFFI
2324
#include <stdbool.h>
2425
#endif
26+
#endif
2527
#define DFTD4_API_CALL
2628
#define DFTD4_API_SUFFIX__V_3_0
2729
#define DFTD4_API_SUFFIX__V_3_1
2830
#define DFTD4_API_SUFFIX__V_3_2
31+
#define DFTD4_API_SUFFIX__V_3_3
32+
#define DFTD4_API_SUFFIX__V_3_4
2933

3034
/// Error handle class
3135
typedef struct _dftd4_error* dftd4_error;

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dftd4_dep = declare_dependency(
5454
link_with: dftd4_lib,
5555
include_directories: dftd4_inc,
5656
dependencies: lib_deps,
57+
variables: {'includedir': meson.current_source_dir() / 'include'},
5758
)
5859

5960
# Add applications

python/dftd4/meson.build

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ python_dep = python.dependency(required: true)
2828
# Python's CFFI is horrible in working with preprocessor statements,
2929
# therefore, we have to preprocess the header before passing it to the ffibuilder
3030
dftd4_pp = configure_file(
31-
command: [cc, '-E', '@INPUT@'],
31+
command: [
32+
cc,
33+
'-I@0@'.format(
34+
dftd4_dep.get_variable(
35+
pkgconfig: 'includedir',
36+
cmake: 'dftd4_INCLUDE_DIRS',
37+
internal: 'includedir',
38+
).split().get(0)
39+
),
40+
'-DDFTD4_CFFI',
41+
'-E',
42+
'@INPUT@',
43+
],
3244
input: dftd4_header,
3345
output: '_libdftd4.h',
3446
capture: true,
@@ -55,24 +67,29 @@ dftd4_pyext = python.extension_module(
5567
subdir: 'dftd4',
5668
)
5769

70+
pysrcs = files(
71+
'__init__.py',
72+
'ase.py',
73+
'interface.py',
74+
'library.py',
75+
'parameters.py',
76+
'pyscf.py',
77+
'qcschema.py',
78+
'test_ase.py',
79+
'test_interface.py',
80+
'test_library.py',
81+
'test_parameters.py',
82+
'test_pyscf.py',
83+
'test_qcschema.py',
84+
)
85+
fs = import('fs')
86+
if fs.exists('parameters.toml')
87+
pysrcs += files('parameters.toml')
88+
endif
89+
5890
if install
5991
python.install_sources(
60-
files(
61-
'__init__.py',
62-
'ase.py',
63-
'interface.py',
64-
'library.py',
65-
'parameters.py',
66-
'pyscf.py',
67-
'qcschema.py',
68-
'test_ase.py',
69-
'test_interface.py',
70-
'test_library.py',
71-
'test_parameters.py',
72-
'test_pyscf.py',
73-
'test_qcschema.py',
74-
'..'/'..'/'assets'/'parameters.toml',
75-
),
92+
pysrcs,
7693
subdir: 'dftd4',
7794
)
7895
endif

python/include/_dftd4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "dftd4.h"

python/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ install = true
3030

3131
dftd4_dep = dependency(
3232
'dftd4',
33-
version: '>=3.4.0',
33+
version: '>=@0@'.format(meson.project_version()),
3434
fallback: ['dftd4', 'dftd4_dep'],
3535
default_options: [
3636
'default_library=static',
3737
'api=true',
3838
'python=false',
3939
],
4040
)
41-
dftd4_header = files('..'/'include'/'dftd4.h')
41+
dftd4_header = files('include'/'_dftd4.h')
4242

4343
subdir('dftd4')

python/mesonpep517.toml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
[build-system]
2-
requires = ["mesonpep517"]
3-
build-backend = "mesonpep517.buildapi"
2+
requires = ["meson-python", "cffi"]
3+
build-backend = "mesonpy"
44

5-
[tool.mesonpep517.metadata]
6-
author = "Sebastian Ehlert"
7-
author-email = "[email protected]"
8-
summary = "Python API of the DFT-D4 project"
9-
description-file = "README.rst"
10-
home-page = "https://github.com/dftd4/dftd4"
11-
requires = [
5+
[project]
6+
name = "dftd4"
7+
version = "3.4.0"
8+
description = "Python API of the DFT-D4 project"
9+
readme = "README.rst"
10+
license.text = "LGPL-3.0-or-later"
11+
urls.repository = "https://github.com/dftd4/dftd4"
12+
classifiers = [
13+
"Intended Audience :: Science/Research",
14+
"Programming Language :: Fortran",
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3.7",
17+
"Programming Language :: Python :: 3.8",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Topic :: Scientific/Engineering :: Chemistry",
21+
"Topic :: Scientific/Engineering :: Physics",
22+
]
23+
requires-python = ">=3.7"
24+
dependencies = [
1225
"cffi",
1326
"numpy",
1427
]
15-
requires-python = ">=3.6"
28+
optional-dependencies.ase = ["ase"]
29+
optional-dependencies.qcschema = ["qcelemental"]
30+
optional-dependencies.pyscf = ["pyscf"]
31+
optional-dependencies.test = [
32+
"pytest",
33+
"pytest-cov",
34+
]

0 commit comments

Comments
 (0)