Skip to content

Commit b9b0d63

Browse files
authored
Merge pull request #497 from ax3l/setup.py-install-variants
setup.py/PyPI: Environment Variant Control
2 parents 55c6e29 + 9597461 commit b9b0d63

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Other
4242
- NLohmann-JSON: updated to 3.5.0+ #467
4343
- Docs:
4444

45-
- PyPI install method #450 #451
45+
- PyPI install method #450 #451 #497
4646
- more info on MPI #449
4747
- new "first steps" section #473 #478
4848
- update invasive test info #474

README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ Optional language bindings:
120120

121121
[![Spack Package](https://img.shields.io/badge/spack.io-openpmd--api-brightgreen.svg)](https://spack.io)
122122
[![Conda Package](https://img.shields.io/badge/conda.io-openpmd--api-brightgreen.svg)](https://anaconda.org/conda-forge/openpmd-api)
123-
[![PyPI Package](https://img.shields.io/badge/pypi.org-openPMD--api-yellow.svg)](https://pypi.org/project/openPMD-api)
123+
[![PyPI Package](https://img.shields.io/badge/pypi.org-openpmd--api-yellow.svg)](https://pypi.org/project/openPMD-api)
124+
[![From Source](https://img.shields.io/badge/from_source-CMake-brightgreen.svg)](https://cmake.org)
124125

125126
Choose *one* of the install methods below to get started:
126127

127128
### [Spack](https://spack.io)
128129

130+
[![Spack Status](https://img.shields.io/badge/method-recommended-brightgreen.svg)](https://spack.io)
131+
129132
```bash
130133
# optional: +python +adios1 -mpi
131134
spack install openpmd-api
@@ -135,6 +138,7 @@ spack load -r openpmd-api
135138
### [Conda](https://conda.io)
136139

137140
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/openpmd-api.svg)](https://anaconda.org/conda-forge/openpmd-api)
141+
[![Conda Status](https://img.shields.io/badge/method-recommended-brightgreen.svg)](https://anaconda.org/conda-forge/openpmd-api)
138142
[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/openpmd-api.svg)](https://anaconda.org/conda-forge/openpmd-api)
139143

140144
```bash
@@ -146,16 +150,28 @@ conda install -c conda-forge openpmd-api
146150

147151
[![PyPI Version](https://img.shields.io/pypi/v/openPMD-api.svg)](https://pypi.org/project/openPMD-api)
148152
[![PyPI Format](https://img.shields.io/pypi/format/openPMD-api.svg)](https://pypi.org/project/openPMD-api)
149-
[![PyPI Status](https://img.shields.io/badge/status-experimental-yellow.svg)](https://pypi.org/project/openPMD-api)
153+
[![PyPI Status](https://img.shields.io/badge/method-experimental-yellow.svg)](https://pypi.org/project/openPMD-api)
150154
[![PyPI Downloads](https://img.shields.io/pypi/dm/openPMD-api.svg)](https://pypi.org/project/openPMD-api)
151155

156+
Behind the scenes, this install method *compiles from source* against the found installations of HDF5, ADIOS and/or MPI (in system paths, from other package managers, or loaded via a module system, ...).
157+
The current status for this install method is *experimental*.
158+
Please feel free to [report](https://github.com/openPMD/openPMD-api/issues/new/choose) how this works for you.
159+
160+
```bash
161+
# optional: --user
162+
pip install openpmd-api
163+
```
164+
165+
or with MPI support:
152166
```bash
153-
# optional: [mpi] --user
154-
pip install openPMD-api
167+
# optional: --user
168+
openPMD_USE_MPI=ON pip install openpmd-api
155169
```
156170

157171
### From Source
158172

173+
[![Source Status](https://img.shields.io/badge/method-advanced-brightgreen.svg)](https://cmake.org)
174+
159175
openPMD can then be installed using [CMake](https://cmake.org/):
160176

161177
```bash

docs/source/install/install.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ Please feel free to `report <https://github.com/openPMD/openPMD-api/issues/new/c
6767

6868
.. code-block:: bash
6969
70-
# optional: [mpi] --user
71-
pip install openPMD-api
70+
# optional: --user
71+
pip install openpmd-api
72+
73+
or with MPI support:
74+
75+
.. code-block:: bash
76+
77+
# optional: --user
78+
openPMD_USE_MPI=ON pip install openpmd-api
7279
7380
.. _install-cmake:
7481

setup.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def build_extension(self, ext):
4747
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
4848
'-DCMAKE_PYTHON_OUTPUT_DIRECTORY=' + extdir,
4949
'-DPYTHON_EXECUTABLE=' + sys.executable,
50+
# variants
51+
'-DopenPMD_USE_MPI:BOOL=' + openPMD_USE_MPI,
5052
# skip building tests & examples
5153
'-DBUILD_TESTING:BOOL=OFF',
5254
'-DBUILD_EXAMPLES:BOOL=OFF',
@@ -95,9 +97,22 @@ def build_extension(self, ext):
9597
with open('./README.md', encoding='utf-8') as f:
9698
long_description = f.read()
9799

100+
# Allow to control options via environment vars.
101+
# Work-around for https://github.com/pypa/setuptools/issues/1712
102+
# note: changed default for MPI
103+
openPMD_USE_MPI = os.environ.get('openPMD_USE_MPI', 'OFF')
104+
105+
# https://cmake.org/cmake/help/v3.0/command/if.html
106+
if openPMD_USE_MPI.upper() in ['1', 'ON', 'YES', 'TRUE', 'YES']:
107+
openPMD_USE_MPI = "ON"
108+
else:
109+
openPMD_USE_MPI = "OFF"
110+
98111
# Get the package requirements from the requirements.txt file
99112
with open('./requirements.txt') as f:
100113
install_requires = [line.strip('\n') for line in f.readlines()]
114+
if openPMD_USE_MPI == "ON":
115+
install_requires.append('mpi4py>=2.1.0')
101116

102117
# keyword reference:
103118
# https://packaging.python.org/guides/distributing-packages-using-setuptools
@@ -128,9 +143,13 @@ def build_extension(self, ext):
128143
python_requires='>=3.5, <3.8',
129144
# tests_require=['pytest'],
130145
install_requires=install_requires,
131-
extras_require={
132-
'mpi': ['mpi4py'],
133-
},
146+
# we would like to use this mechanism, but pip / setuptools do not
147+
# influence the build and build_ext with it.
148+
# therefore, we use environment vars to control.
149+
# ref: https://github.com/pypa/setuptools/issues/1712
150+
# extras_require={
151+
# 'mpi': ['mpi4py>=2.1.0'],
152+
# },
134153
# cmdclass={'test': PyTest},
135154
# platforms='any',
136155
classifiers=[

0 commit comments

Comments
 (0)