Skip to content

Commit

Permalink
Merge pull request #208 from mach3-software/fix_pyMaCh3_pip_install
Browse files Browse the repository at this point in the history
Fix pyMaCh3 pip install
  • Loading branch information
henry-wallace-phys authored Nov 14, 2024
2 parents 4961a1a + bb5f61e commit 56afbb8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ add_subdirectory(mcmc)
add_subdirectory(Diagnostics)
add_subdirectory(plotting)
if (MaCh3_PYTHON_ENABLED)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
add_subdirectory(python)
endif()

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ Some functionalities rely on setting `Env{MACH3}` which should point to path exp

## Python

MaCh3 can be compiled with a python interface by specifying the cmake option
MaCh3 has an optional python interface (pyMaCh3) which provides much of the same functionality as the c++ interface (see [here](https://mach3-software.github.io/MaCh3/pyMaCh3/mainpage.html) for documentation).

You can tell the build system to set up the pyMaCh3 interface by specifying

```bash
cmake ../ -DMaCh3_PYTHON_ENABLED=ON
make && make install
```

Currently the python module only contains an interface to the plotting library (see [here](https://github.com/mach3-software/MaCh3/blob/develop/plotting/README.md#python) for more information on how to use it)

when building

### Building with Pip

Expand All @@ -79,7 +81,7 @@ Additionally, you can build just the Python module by doing:
```bash
pip install -t <install location> .
```
The -t option specifies an install location which can be useful if you are on a computing cluster and don't have write access to the default install location. If you specify a non-standard location you will need to add it to your `PYTHONPATH` as above so that python can find the module.
The (optional) -t option specifies an install location which can be useful if you are on a computing cluster and don't have write access to the default install location. If you specify a non-standard location you will need to add it to your `PYTHONPATH` as above so that python can find the module.

## Multithreading
MaCh3 quite heavily relies on Multithreading, it is turned on by default. If for debugging purposes you would like to turn it off please use
Expand Down
2 changes: 1 addition & 1 deletion cmake/Templates/setup.MaCh3.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ add_to_PATH ${MaCh3_ROOT}/bin
add_to_LD_LIBRARY_PATH ${MaCh3_ROOT}/lib

if test -d ${MaCh3_ROOT}/pyMaCh3; then
add_to_PYTHONPATH ${MaCh3_ROOT}/pyMaCh3
add_to_PYTHONPATH ${MaCh3_ROOT}
fi

unset SETUPDIR
10 changes: 5 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
################################# pybind11 stuff ##################################
## EM: make a module target out of all the python*Module.cpp files (currently just one...)
pybind11_add_module(
pyMaCh3 MODULE
_pyMaCh3 MODULE
pyMaCh3.cpp
plotting.cpp
fitter.cpp
Expand All @@ -13,7 +13,7 @@ pybind11_add_module(
)
## EM: only works with code compiled with -fPIC enabled.. I think this flag can make things slightly slower
## so would be good to find a way around this.
set_property( TARGET pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON )
target_link_libraries( pyMaCh3 PUBLIC MaCh3::All )
target_link_libraries( pyMaCh3 PRIVATE MaCh3Warnings )
install( TARGETS pyMaCh3 DESTINATION pyMaCh3/)
set_property( TARGET _pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON )
target_link_libraries( _pyMaCh3 PRIVATE MaCh3::All NuOscillator yaml-cpp::yaml-cpp MaCh3Warnings )
install( DIRECTORY pyMaCh3 DESTINATION ./ )
install( TARGETS _pyMaCh3 DESTINATION pyMaCh3/ )
2 changes: 1 addition & 1 deletion python/pyMaCh3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void initManager(py::module &); // <- defined in python/manager.cpp
void initCovariance(py::module &); // <- defined in python/covariance.cpp
void initSplines(py::module &); // <- defined in python/splines.cpp

PYBIND11_MODULE( pyMaCh3, m ) {
PYBIND11_MODULE( _pyMaCh3, m ) {
initPlotting(m);
initFitter(m);
initSamplePDF(m);
Expand Down
3 changes: 3 additions & 0 deletions python/pyMaCh3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._pyMaCh3 import __doc__, fitter, manager, plotting, sample_pdf, splines, covariance

__all__ = ["__doc__", "fitter", "manager", "plotting", "sample_pdf", "splines", "covariance"]

0 comments on commit 56afbb8

Please sign in to comment.