Skip to content

Commit

Permalink
Add eups build support
Browse files Browse the repository at this point in the history
  • Loading branch information
taranu committed Nov 3, 2023
1 parent 365b826 commit 53818ab
Show file tree
Hide file tree
Showing 26 changed files with 230 additions and 166 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Meson/build
build
builddir
build-debug
build-release
python/build
python/build-release
python/builddir
python/gauss2dfit.egg-info/

# IDE folders and files
.cache/
Expand Down
1 change: 1 addition & 0 deletions build-cc-debug.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Compile and test C++ debug library
meson compile -C build-debug && meson test -C build-debug

1 change: 1 addition & 0 deletions build-cc-release.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Compile, test and install C++ library
meson compile -C build-release && meson test -C build-release && meson install -C build-release

1 change: 1 addition & 0 deletions build-debug.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Compile and tell debug libraries
./build-cc-debug.sh && ./build-py-debug.sh
3 changes: 2 additions & 1 deletion build-py-debug.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
meson compile -C python/build-debug && meson test -C python/build-debug
# Compile python debug libraries
meson compile -C python/build-debug

3 changes: 3 additions & 0 deletions build-py-release.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Compile, test and install python release libraries
# Unfortunately, the library must be installed before any python tests are run
# (otherwise the import will fail)
meson compile -C python/build-release && meson install -C python/build-release && meson test -C python/build-release

1 change: 1 addition & 0 deletions clean-build-cc-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
meson compile -C build-debug --clean
2 changes: 2 additions & 0 deletions clean-build-cc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Call meson to clean installed C++ library files
meson compile -C build-release --clean
2 changes: 2 additions & 0 deletions clean-build-py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Call meson to clean installed Python library files
meson compile -C python/build-release --clean
2 changes: 2 additions & 0 deletions clean-cc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Delete the C++ build directory
rm -rf build-release
2 changes: 2 additions & 0 deletions clean-py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Delete the Python library build directories
rm -rf python/build-release
2 changes: 0 additions & 2 deletions clean.bash

This file was deleted.

2 changes: 2 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Delete all build directories
./clean-cc.sh && ./clean-py.sh
7 changes: 6 additions & 1 deletion include/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,12 @@ class Model : public ParametricModel {
for (size_t idx = 0; idx < _size; ++idx) {
result[idx] = this->_evaluate_observation(idx, print, is_loglike_grad);
}
result[_size] = this->_evaluate_priors(print, normalize_loglike);
if(
(this->_mode == EvaluatorMode::loglike) || is_loglike_grad
|| (this->_mode == EvaluatorMode::loglike_image) || (this->_mode == EvaluatorMode::jacobian)
) {
result[_size] = this->_evaluate_priors(print, normalize_loglike);
}

return result;
}
Expand Down
45 changes: 34 additions & 11 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,49 @@ project(
default_options : ['cpp_std=c++17',],
)

gauss2d_dep = dependency('gauss2d')
gsl_dep = dependency('GSL')
parameters_dep = dependency('parameters')
eups = find_program('eups', required: false)
use_eups = eups.found()
if use_eups
use_eups = run_command('eups', 'list', 'gauss2dfit', check: false).returncode() == 0
endif

gsl_dep = dependency('GSL', required: false)

if use_eups
gauss2d_eupsdir = run_command('eups', 'list', '-d', 'gauss2d', check: true).stdout().strip()
cpp = meson.get_compiler('cpp')
gauss2d_dep = declare_dependency(
dependencies: [cpp.find_library('gauss2d', dirs: [gauss2d_eupsdir + '/build-release/lib64']),],
include_directories: gauss2d_eupsdir + '/build-release/include',
)

parameters_eupsdir = run_command('eups', 'list', '-d', 'parameters', check: true).stdout().strip()
parameters_dep = declare_dependency(
include_directories: parameters_eupsdir + '/build-release/include',
)
else
gauss2d_dep = dependency('gauss2d')
parameters_dep = dependency('parameters')
endif

inc = include_directories('include')

depends = declare_dependency(
include_directories: inc,
dependencies: [gauss2d_dep, gsl_dep, parameters_dep],
include_directories: inc,
dependencies: [gauss2d_dep, gsl_dep, parameters_dep],
)

subdir('include')
subdir('src')
subdir('tests')

pkg_mod = import('pkgconfig')
pkg_mod.generate(libraries : gauss2dfitlib,
version : '0.1',
name : 'libgauss2dfit',
filebase : 'gauss2dfit',
description : 'Create, manipulate and evaluate 2D Gaussian mixtures and images thereof.')
if not use_eups
pkg_mod = import('pkgconfig')
pkg_mod.generate(libraries : gauss2dfitlib,
version : '0.1',
name : 'libgauss2dfit',
filebase : 'gauss2dfit',
description : 'Create, manipulate and evaluate 2D Gaussian mixtures and images thereof.')
endif

subdir('doc')
2 changes: 1 addition & 1 deletion python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gauss2DFit
.. todo :target: https://pypi.python.org/pypi/gauss2dfit
*gauss2dfit* provides python bindings for the C++ libgauss2dfit library.
Python 3.7+, `pybind11 <https://github.com/pybind/pybind11>`_, and numpy are
Python 3.8+, `pybind11 <https://github.com/pybind/pybind11>`_, and numpy are
requirements, as numpy arrays are used to store images for tests.

With libgauss2dfit installed, these bindings can be built using meson:
Expand Down
34 changes: 27 additions & 7 deletions python/gauss2d/fit/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ sources = [
'pybind11.cc',
]

kwargs = {}

eups = find_program('eups', required: false)
use_eups = eups.found()
if use_eups
use_eups = run_command('eups', 'list', '-d', 'gauss2dfit', check: false).returncode() == 0
endif

if use_eups
# meson.current_build_dir() would be ideal but it seems to delete the file?
kwargs = {'install_dir': meson.build_root() + '/lib/gauss2d/fit'}
else
# Folder relative to site-packages to install to
kwargs = {'subdir': 'gauss2d/fit'}
endif

module = python.extension_module(
'_gauss2d_fit', # Name of the module
sources, # List of sources
Expand All @@ -43,7 +59,7 @@ module = python.extension_module(
gauss2dfit_dep,
pybind11_dep,
],
subdir: 'gauss2d/fit', # Folder relative to site-packages to install to
kwargs: kwargs
)

# Pure Python sources
Expand All @@ -52,9 +68,13 @@ python_sources = [
'utils.py',
]

# Install pure Python
python.install_sources(
python_sources,
pure: false, # Will be installed next to binaries
subdir: 'gauss2d/fit' # Folder relative to site-packages to install to
)
if use_eups
install_data(python_sources, kwargs: kwargs)
else
# Install pure Python
python.install_sources(
python_sources,
pure: false, # Will be installed next to binaries
subdir: 'gauss2d/fit' # Folder relative to site-packages to install to
)
endif
48 changes: 43 additions & 5 deletions python/meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
project(
'gauss2d',
'gauss2dfit',
'cpp',
default_options : ['cpp_std=c++17',],
version : '0.1.0',
)
gauss2d_dep = dependency('gauss2d')
gauss2d_python_dep = dependency('gauss2d_python')
gauss2dfit_dep = dependency('gauss2dfit')

eups = find_program('eups', required: false)
use_eups = eups.found()

if use_eups
gauss2dfit_eups = run_command('eups', 'list', '-d', 'gauss2dfit', check: false)
use_eups = gauss2dfit_eups.returncode() == 0
endif

if use_eups
gauss2d_eupsdir = run_command('eups', 'list', '-d', 'gauss2d', check: true).stdout().strip()
cpp = meson.get_compiler('cpp')
gauss2d_dep = declare_dependency(
dependencies: [cpp.find_library('gauss2d', dirs: [gauss2d_eupsdir + '/build-release/lib64']),],
include_directories: gauss2d_eupsdir + '/build-release/include',
)
gauss2d_python_dep = declare_dependency(
include_directories: gauss2d_eupsdir + '/python/lib/build-release/include',
)
gauss2dfit_eupsdir = gauss2dfit_eups.stdout().strip()
parameters_eupsdir = run_command('eups', 'list', '-d', 'parameters', check: true).stdout().strip()
# TODO: Can this dependency be extracted from '../meson.build' somehow
gauss2dfit_dep = declare_dependency(
dependencies: [cpp.find_library('gauss2dfit', dirs: [gauss2dfit_eupsdir + '/build-release/lib64']),],
include_directories: [
gauss2dfit_eupsdir + '/build-release/include',
parameters_eupsdir + '/build-release/include',
]
)
else
gauss2d_dep = dependency('gauss2d')
gauss2d_python_dep = dependency('gauss2d_python')
gauss2dfit_dep = dependency('gauss2dfit')
endif

pybind11_dep = dependency('pybind11')
pymod = import('python')
python = pymod.find_installation(
Expand All @@ -15,4 +47,10 @@ python = pymod.find_installation(
modules: ['gauss2d', 'pytest'],
)
subdir('gauss2d/fit')
subdir('tests')
subdir('tests')
if not use_eups
pip_cmd = ['python', '-m', 'pip', 'install', meson.source_root(), '-t', python.get_install_dir(), '--no-dependencies']
message('Will run on install:')
message(pip_cmd)
meson.add_install_script(pip_cmd)
endif
35 changes: 18 additions & 17 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[tool.poetry]
name = "gauss2d"
[project]
name = "gauss2dfit"
authors = [
{name="Dan Taranu", email="dan.s.taranu@gmail.com"},
]
description = "Python (pybind11) bindings for gauss2dfit"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"gauss2d",
"numpy",
"pybind11",
"pytest",
]
version = "0.1.0"
description = "Python (pybind11) bindings for gauss2d"
authors = ["taranu <dan.s.taranu@gmail.com>"]
license = "GPL-3.0-or-later"

[tool.poetry.dependencies]
python = "^3.7"
pybind11 = ">2.6.2"
numpy = ">1.20.2"
pytest = ">4"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.setuptools]
py-modules = []
105 changes: 0 additions & 105 deletions python/setup.py

This file was deleted.

Loading

0 comments on commit 53818ab

Please sign in to comment.