Skip to content

Commit 4102356

Browse files
authored
Use meson build in place of numpy distutils (#12)
* first attempt at meson building * include mkl-devel in build requirements * change version * relax version a bit * use examples from numpy * update github workflow, reenable thread locks * update meson build file for mkl linkage parameters * remove print outs * remove setup.py file * install setuptools * add option to force sdl usage * do not fail fast on tests * move thread lock allocation * update some meta information * ignore pycharm files * be a bit more accurate about the argument types * Be a little safer about free the lock * split __dealloc__ into a dealloc and a __del__ method for safety * determine initialization status dynamically * make _initialized a function * just use if self.handle[i] * use mamba * cache the environment * fix indices and indptr * stop overwriting dtype * undo some types * more type resetting * unsetting some more * make call type a little more accurate * switch back to conda (with defaults) * reset some build scripts * switch back to mamba, but don't use mkl 2024 * ensure cleared cache * retry this * dynamic initialized (again) * be explicit about initializing handle and iparm * don't cache * generate c sources in tree for cython coverage * enable coverage build option * have meson conditionally generate c file in source directory when doing coverage. * add coverage configuration to pyproject.toml * remove all pytest-cov related options to pytest * fix coverage determination, split long lines * generate coverage.xml * fix command * add comments to meson build file * update distribution script * update gitignore * add a test for mkl=2024 * update test name * fix matrix variable name * add test for windows and mac on mkl 2024 * mkl-2024 is not on macos
1 parent c48ea7e commit 4102356

16 files changed

+462
-225
lines changed

.bumpversion.cfg

-3
This file was deleted.

.coveragerc

-5
This file was deleted.

.git_archival.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
4+
ref-names: $Format:%D$

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git_archival.txt export-subst
2+
# Excluding files from an sdist generated by meson-python
3+
4+
.azure-pipelines/* export-ignore
5+
.ci/* export-ignore
6+
tests/* export-ignore
7+
8+
.flake8 export-ignore
9+
.git* export-ignore
10+
*.yml export-ignore
11+
*.yaml export-ignore

.github/workflows/python-package-conda.yml

+47-35
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,71 @@ on:
1414

1515
jobs:
1616
build-and-test:
17-
name: Testing (${{ matrix.python-version }}, ${{ matrix.os }})
17+
name: Testing (Python ${{ matrix.python-version }}, on ${{ matrix.os }}, with MKL ${{ matrix.mkl-version }})
1818
runs-on: ${{ matrix.os }}
1919
defaults:
2020
run:
2121
shell: bash -l {0}
2222
strategy:
23-
fail-fast: True
23+
fail-fast: False
2424
matrix:
25-
os: [ubuntu-latest, macOS-latest, windows-latest]
26-
python-version: ["3.8", "3.9", "3.10", "3.11"]
25+
os: [ubuntu-latest, macos-latest, windows-latest]
26+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
27+
mkl-version: ['2023'] # currently 2024 fails building for some reason...
28+
include:
29+
- os: ubuntu-latest
30+
python-version: "3.12"
31+
coverage: ${{ true }}
32+
- os: ubuntu-latest
33+
python-version: "3.12"
34+
mkl-version: '2024'
35+
- os: windows-latest
36+
python-version: "3.12"
37+
mkl-version: '2024'
2738

2839
steps:
29-
- uses: actions/checkout@v2
40+
- uses: actions/checkout@v4
3041
- name: Setup Conda
31-
uses: conda-incubator/setup-miniconda@v2
42+
uses: conda-incubator/setup-miniconda@v3
3243
with:
33-
auto-update-conda: true
34-
activate-environment: dev
3544
python-version: ${{ matrix.python-version }}
36-
- name: Install Env
45+
mamba-version: '*'
46+
channels: conda-forge, defaults
47+
channel-priority: true
48+
activate-environment: dev
49+
50+
- name: Conda information
3751
run: |
3852
conda info
3953
conda list
4054
conda config --show
41-
conda install --quiet --yes pip numpy scipy cython mkl pytest pytest-cov mkl-devel
4255
43-
- name: Install Our Package
44-
if: ${{ matrix.os != 'windows-latest' }}
56+
- name: Create environment
4557
run: |
46-
echo $CONDA_PREFIX
47-
export TEST_COV=1
48-
pip install -v -e .
49-
conda list
58+
mamba install --quiet --yes pip numpy scipy cython mkl=${{ matrix.mkl-version }} pytest \
59+
mkl-devel pkg-config meson-python meson ninja setuptools_scm \
60+
${{ matrix.coverage && 'coverage' || ''}}
5061
51-
- name: Install Our Package on Windows
52-
if: ${{ matrix.os == 'windows-latest' }}
62+
- name: Install Our Package
5363
run: |
54-
echo $CONDA_PREFIX
55-
export MKLROOT="$CONDA_PREFIX\Library"
56-
echo $MKLROOT
57-
pip install -v -e .
64+
python -m pip install --no-build-isolation --verbose --editable . \
65+
--config-setting=compile-args=-v \
66+
${{ matrix.coverage && '--config-settings=setup-args="-Dcy_coverage=true"' || ''}}
5867
conda list
5968
6069
- name: Run Tests
6170
run: |
62-
pytest --cov-config=.coveragerc --cov-report=xml --cov=pydiso -s -v
71+
${{ matrix.coverage && 'coverage run -m' || '' }} pytest -s -v
72+
${{ matrix.coverage && 'coverage xml' || '' }}
6373
6474
- name: Upload coverage
65-
if: ${{ matrix.os == 'ubuntu-latest' }} and {{ matrix.python-version == '3.8' }}
66-
uses: codecov/codecov-action@v2
75+
if: ${{ matrix.coverage }}
76+
uses: codecov/codecov-action@v4
6777
with:
6878
verbose: true # optional (default = false)
6979

7080
distribute:
71-
name: Distributing from 3.8
81+
name: Distributing from 3.11
7282
needs: build-and-test
7383
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
7484
runs-on: ubuntu-latest
@@ -77,29 +87,31 @@ jobs:
7787
shell: bash -l {0}
7888

7989
steps:
80-
- uses: actions/checkout@v2
90+
- uses: actions/checkout@v4
8191
- name: Setup Conda
82-
uses: conda-incubator/setup-miniconda@v2
92+
uses: conda-incubator/setup-miniconda@v3
8393
with:
84-
auto-update-conda: true
94+
python-version: 3.11
95+
mamba-version: '*'
96+
channels: conda-forge, defaults
97+
channel-priority: true
8598
activate-environment: dev
86-
python-version: 3.8
8799

88100
- name: Install Env
89101
run: |
90102
conda info
91103
conda list
92104
conda config --show
93-
conda install --quiet --yes pip numpy scipy cython mkl mkl-devel
94105
95-
- name: Install Our Package
106+
- name: Create environment
96107
run: |
97-
echo $CONDA_PREFIX
98-
pip install -v -e .
108+
mamba install --quiet --yes pip numpy scipy cython mkl=2023 \
109+
mkl-devel pkg-config meson-python meson ninja setuptools_scm \
110+
python-build
99111
100112
- name: Generate Source Distribution
101113
run: |
102-
python setup.py sdist
114+
python -m build --no-isolation --skip-dependency-check --sdist .
103115
104116
- name: pypi-publish
105117
uses: pypa/[email protected]

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
build
2+
dist
3+
coverage_html_report
24
*.so
35
pydiso.egg-info
46
__pycache__
57
mkl_solver.c
8+
mkl_solver.c.dep
69
.coverage
710
coverage.xml
11+
12+
.idea/

MANIFEST.in

-3
This file was deleted.

README.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
# pydiso
22

33
Pydiso is a python wrapper for the pardiso solver. It is currently implemented for the
4-
Intel MKL's version of pardiso. It's goal is to expose the full functionality of pardiso
4+
Intel MKL's version of pardiso. Its goal is to expose the full functionality of pardiso
55
to python, allowing the user to customize it as necessary for their use cases.
66

77
# Installation
88

99

10-
### Installing from source
10+
## Installing from source
1111

1212
The wrapper is written in cython and links to the mkl libraries dynamically. Therefore,
1313
it needs to find the necessary header files associated with the MKL installation to compile.
14-
For conda users, these headers can be installed with `mkl-devel` package that is available
15-
on the default channel, conda-forge channel, the intel channel, or others, e.g.
14+
The meson build backend uses pkg-config to identify the locations of the mkl header files
15+
and library dynamic libraries. Most development installations of MKL should provide the
16+
necessary pkg-config files for this. For example, conda users can be install the necessary
17+
configuration information with `mkl-devel` package that is available on the default channel,
18+
conda-forge channel, the intel channel, or others, e.g.
1619

1720
`conda install mkl-devel`
1821

19-
Most of the time, your respective numpy installations will then be intelligent enough to
20-
identify the location of the installed MKL. However if you run into issues automatically
21-
finding the library headers, you will need to set the `MKLROOT` environment variable to
22-
point to the correct location. On Linux and MacOS the `mkl-rt` library and `mkl.h` are
23-
usually in the same folder, and thus the root should point to that directory. On Windows
24-
the `mkl-rt.h` and `mkl-rt.lib` are not in the same folder but seperated a level into
25-
`Library` and `Include` directories, and in this case `MKLROOT` would point to the folder
26-
containing them.
22+
If you have installed the configuration files to a non-standard location, you will need to set
23+
`PKG_CONFIG_PATH` to point to that location.
2724

28-
After the necessary MKL files are accessible, you should be able to do the standard install
29-
script common to python packages by running either
3025

31-
`python setup.py install`
32-
33-
or, equivalently
26+
After the necessary MKL files are accessible, you should be able to install by running
3427

3528
`pip install .`
3629

meson.build

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
project(
2+
'pydiso',
3+
'c', 'cython',
4+
# Note that the git commit hash cannot be added dynamically here
5+
# (it is dynamically generated though setuptools_scm)
6+
version: run_command('python',
7+
[
8+
'-c',
9+
'''
10+
from setuptools_scm import get_version
11+
print(get_version())'''
12+
],
13+
check: true
14+
).stdout().strip(),
15+
16+
license: 'MIT',
17+
meson_version: '>= 1.1.0',
18+
default_options: [
19+
'buildtype=debugoptimized',
20+
'b_ndebug=if-release',
21+
],
22+
)
23+
24+
# https://mesonbuild.com/Python-module.html
25+
py_mod = import('python')
26+
py = py_mod.find_installation(pure: false)
27+
py_dep = py.dependency()
28+
29+
cc = meson.get_compiler('c')
30+
cy = meson.get_compiler('cython')
31+
# generator() doesn't accept compilers, only found programs - cast it.
32+
cython = find_program(cy.cmd_array()[0])
33+
34+
_global_c_args = cc.get_supported_arguments(
35+
'-Wno-unused-but-set-variable',
36+
'-Wno-unused-function',
37+
'-Wno-conversion',
38+
'-Wno-misleading-indentation',
39+
)
40+
add_project_arguments(_global_c_args, language : 'c')
41+
42+
# We need -lm for all C code (assuming it uses math functions, which is safe to
43+
# assume for SciPy). For C++ it isn't needed, because libstdc++/libc++ is
44+
# guaranteed to depend on it.
45+
m_dep = cc.find_library('m', required : false)
46+
if m_dep.found()
47+
add_project_link_arguments('-lm', language : 'c')
48+
endif
49+
50+
subdir('pydiso')

meson.options

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
option('cy_coverage', type : 'boolean', value : false)
2+
3+
option('use-sdl', type: 'boolean', value: true,
4+
description: 'Use the single dynamic library.')
5+
6+
option('use-ilp64', type: 'boolean', value: false,
7+
description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces')
8+
9+
option('mkl-threading', type: 'string', value: 'auto',
10+
description: 'MKL threading method, one of: `seq`, `iomp`, `gomp`, `tbb`')

pydiso/__init__.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
__version__ = "0.0.3"
21
__author__ = "SimPEG Team"
32
__license__ = "MIT"
43
__copyright__ = "2021, SimPEG Developers, http://simpeg.xyz"
4+
5+
from importlib.metadata import version, PackageNotFoundError
6+
7+
# Version
8+
try:
9+
# - Released versions just tags: 0.8.0
10+
# - GitHub commits add .dev#+hash: 0.8.1.dev4+g2785721
11+
# - Uncommitted changes add timestamp: 0.8.1.dev4+g2785721.d20191022
12+
__version__ = version("pydiso")
13+
except PackageNotFoundError:
14+
# If it was not installed, then we don't know the version. We could throw a
15+
# warning here, but this case *should* be rare. discretize should be
16+
# installed properly!
17+
from datetime import datetime
18+
19+
__version__ = "unknown-" + datetime.today().strftime("%Y%m%d")

0 commit comments

Comments
 (0)