Skip to content

Commit c79a845

Browse files
authored
Meson (#627)
- changes the repository structure to COSMIC/src/cosmic instead of COSMIC/cosmic - changes the build from numpy.distutils since we cannot compile modern fortran with distutils - updated the action yaml accordingly. For new installs we recommend: python -m pip install .
1 parent 2af0f5b commit c79a845

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+169
-266
lines changed

.github/workflows/python-package.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
name: Unit Test COSMIC
55

6-
on: [pull_request, push]
6+
on: [pull_request]
77

88
jobs:
99
build:
10-
10+
1111
runs-on: ubuntu-latest
1212
strategy:
1313
fail-fast: false
@@ -30,23 +30,25 @@ jobs:
3030
restore-keys: |
3131
${{ runner.os }}-pip-
3232
${{ runner.os }}-
33-
- name: Install dependencies
33+
- name: Install dependencies and package
3434
run: |
3535
sudo apt-get update
36-
sudo apt-get install gfortran swig libhdf5-serial-dev
37-
pip install numpy
36+
sudo apt-get install gfortran swig libhdf5-serial-dev meson python3-dev
37+
pip install numpy ninja pytest
3838
pip install -r requirements.txt
39-
pip install .
39+
python -m pip install .
40+
4041
- name: Lint with flake8
4142
run: |
4243
# stop the build if there are Python syntax errors or undefined names
4344
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude docs
4445
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4546
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude docs,versioneer.py,cosmic/_version.py,cosmic/tests,cosmic/*/__init__.py
47+
4648
- name: Test with pytest
4749
run: |
4850
bash ci/compile_benchmark.sh
49-
export PYTHONPATH=$(meson introspect --install-dir)
50-
pytest --cov=./cosmic --cov-report=xml
51+
pytest --cov=./src/cosmic --cov-report=xml
52+
5153
- name: Upload coverage to Codecov
5254
uses: codecov/codecov-action@v1

ci/compile_benchmark.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
gfortran -coverage -fprofile-arcs -ftest-coverage -O0 ./cosmic/src/assign_remnant.f ./cosmic/src/benchmarkevolv2.f ./cosmic/src/comenv.f ./cosmic/src/corerd.f ./cosmic/src/deltat.f ./cosmic/src/dgcore.f ./cosmic/src/evolv2.f ./cosmic/src/gntage.f ./cosmic/src/hrdiag.f ./cosmic/src/hrdiag_remnant.f ./cosmic/src/instar.f ./cosmic/src/kick.f ./cosmic/src/mix.f ./cosmic/src/mlwind.f ./cosmic/src/mrenv.f ./cosmic/src/ran3.f ./cosmic/src/rl.f ./cosmic/src/star.f ./cosmic/src/zcnsts.f ./cosmic/src/zfuncs.f ./cosmic/src/concatkstars.f ./cosmic/src/bpp_array.f ./cosmic/src/checkstate.f -o benchmarkevolv2.exe -I cosmic/src -Wl,-rpath,${CONDA_PREFIX}/lib
1+
gfortran -coverage -fprofile-arcs -ftest-coverage -O0 src/cosmic/src/assign_remnant.f src/cosmic/src/benchmarkevolv2.f src/cosmic/src/comenv.f src/cosmic/src/corerd.f src/cosmic/src/deltat.f src/cosmic/src/dgcore.f src/cosmic/src/evolv2.f src/cosmic/src/gntage.f src/cosmic/src/hrdiag.f src/cosmic/src/hrdiag_remnant.f src/cosmic/src/instar.f src/cosmic/src/kick.f src/cosmic/src/mix.f src/cosmic/src/mlwind.f src/cosmic/src/mrenv.f src/cosmic/src/ran3.f src/cosmic/src/rl.f src/cosmic/src/star.f src/cosmic/src/zcnsts.f src/cosmic/src/zfuncs.f src/cosmic/src/concatkstars.f src/cosmic/src/bpp_array.f src/cosmic/src/checkstate.f -o benchmarkevolv2.exe -I src/cosmic/src -Wl,-rpath,${CONDA_PREFIX}/lib
22
./benchmarkevolv2.exe

cosmic/tests/__init__.py

-18
This file was deleted.

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ pseudoxml:
225225

226226
.PHONY: apidoc
227227
apidoc:
228-
sphinx-apidoc -o api/ ../cosmic ../cosmic/tests --no-toc --separate --no-headings --force
228+
sphinx-apidoc -o api/ ../src/cosmic ../src/cosmic/tests --no-toc --separate --no-headings --force
229229
@echo
230230
@echo "APIdoc run is complete."

docs/install/index.rst

-12
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,3 @@ Installation Notes/FAQ
4545

4646
``pip install jupyter ipython``
4747

48-
.. note::
49-
50-
USING COMSIC WHEN BUILT FROM SOURCE
51-
52-
If you want import the fortran wrapped library
53-
from the GITHUB folder itself, i.e.
54-
55-
``from cosmic import _evolvebin``
56-
57-
then you must build the extension locally
58-
59-
``python setup.py build_ext --inplace``

meson.build

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
project('cosmic',
2+
'c',
3+
'fortran',
4+
version : '3.4.10',
5+
default_options: ['warning_level=0', 'optimization=3'],
6+
)
7+
8+
# Enable fortran and check arguments
9+
# add_languages('fortran', native: false)
10+
ff = meson.get_compiler('fortran')
11+
f_args = ff.get_supported_arguments('-fPIC')
12+
add_project_arguments(f_args, language: 'fortran')
13+
14+
py3 = import('python').find_installation()
15+
16+
numpy_include_dir = run_command(py3, ['-c', 'import numpy; print(numpy.get_include())'], check: true).stdout().strip()
17+
f2py_include_dir = run_command(py3, ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], check: true).stdout().strip()
18+
inc_np = include_directories(numpy_include_dir, f2py_include_dir)
19+
20+
f2py_source = custom_target(
21+
'evolvebin-target',
22+
input : ['src/cosmic/src/evolv2.f', 'src/cosmic/src/comprad.f'],
23+
output : ['_evolvebinmodule.c', '_evolvebin-f2pywrappers.f'],
24+
command : [py3, '-m', 'numpy.f2py', '@INPUT@', '-m', '_evolvebin', '--lower', '@OUTDIR']
25+
)
26+
27+
lib_source = [
28+
'src/cosmic/src/hrdiag_remnant.f',
29+
'src/cosmic/src/assign_remnant.f',
30+
'src/cosmic/src/benchmarkevolv2.f',
31+
'src/cosmic/src/corerd.f',
32+
'src/cosmic/src/comenv.f',
33+
'src/cosmic/src/dgcore.f',
34+
'src/cosmic/src/evolv2.f',
35+
'src/cosmic/src/gntage.f',
36+
'src/cosmic/src/instar.f',
37+
'src/cosmic/src/kick.f',
38+
'src/cosmic/src/mix.f',
39+
'src/cosmic/src/mrenv.f',
40+
'src/cosmic/src/ran3.f',
41+
'src/cosmic/src/rl.f',
42+
'src/cosmic/src/concatkstars.f',
43+
'src/cosmic/src/comprad.f',
44+
'src/cosmic/src/bpp_array.f',
45+
'src/cosmic/src/checkstate.f',
46+
'src/cosmic/src/deltat.f',
47+
'src/cosmic/src/mlwind.f',
48+
'src/cosmic/src/hrdiag.f',
49+
'src/cosmic/src/star.f',
50+
'src/cosmic/src/zcnsts.f',
51+
'src/cosmic/src/deltat.f',
52+
'src/cosmic/src/mlwind.f',
53+
'src/cosmic/src/hrdiag.f',
54+
'src/cosmic/src/star.f',
55+
'src/cosmic/src/zcnsts.f',
56+
'src/cosmic/src/zfuncs.f',]
57+
58+
# Detect operating system and set appropriate linker flags
59+
host_system = host_machine.system()
60+
61+
if host_system == 'darwin'
62+
ldflags = ['-Wl,-no_compact_unwind']
63+
else
64+
ldflags = [] # No special flags for other systems
65+
endif
66+
67+
evolvebin_module = py3.extension_module('_evolvebin',
68+
f2py_source,
69+
lib_source,
70+
f2py_include_dir / 'fortranobject.c',
71+
include_directories: inc_np,
72+
link_args: ldflags,
73+
install : true,
74+
install_dir : py3.get_install_dir() / 'cosmic'
75+
)
76+
77+
78+
module_dirs = ['src/cosmic', 'src/cosmic/bse_utils',
79+
'src/cosmic/sample', 'src/cosmic/tests']
80+
81+
# Install modules
82+
foreach mod_dir: module_dirs
83+
install_subdir(mod_dir,
84+
install_dir: py3.get_install_dir())
85+
endforeach
86+
87+
88+
python_script = 'bin/cosmic-pop'
89+
install_data(python_script, install_dir: get_option('bindir'))

pyproject.toml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[project]
2+
name = "cosmic"
3+
distname = "cosmic-popsynth"
4+
description = "a Python-interfaced binary population synthesis suite"
5+
authors = [
6+
{ name="Katelyn Breivik", email="katie.breivik@gmail.com" },
7+
{ name="Scott Coughlin" },
8+
{ name="Michael Zevin" },
9+
{ name="Carl L. Rodriguez" },
10+
]
11+
readme = "README.md"
12+
13+
14+
requires-python = ">=3.7"
15+
license = { text = "MIT License" }
16+
classifiers = [
17+
"Development Status :: 5 - Production/Stable",
18+
"Intended Audience :: Developers",
19+
"Intended Audience :: Science/Research",
20+
"License :: OSI Approved :: MIT License",
21+
"Operating System :: OS Independent",
22+
"Programming Language :: Python",
23+
]
24+
dynamic = ["version"]
25+
dependencies = ["numpy", "scipy", "astropy", "configparser",
26+
"tqdm", "pandas", "tables", "h5py", "schwimmbad",
27+
"matplotlib", "importlib-metadata"]
28+
29+
30+
[project.optional-dependencies]
31+
test = ["pytest", "pytest-xdist", "pytest-cov", "flake8", "coverage"]
32+
docs = ["sphinx", "numpydoc", "sphinx-bootstrap-theme",
33+
"sphinxcontrib-programoutput", "sphinx-automodapi",
34+
"ipython", "sphinx_rtd_theme", "pickleshare"]
35+
36+
37+
38+
[build-system]
39+
requires = ["meson", "meson-python", "wheel", "numpy", "setuptools"]
40+
build-backend = 'mesonpy'
41+
42+
43+
# pyproject.toml
44+
[tool.setuptools]
45+
write_to = "src/cosmic/_version.py"

setup.cfg

-19
This file was deleted.

0 commit comments

Comments
 (0)