diff --git a/.github/workflows/pymoose.yml b/.github/workflows/pymoose.yml index c89f538c5b..cc0119026a 100644 --- a/.github/workflows/pymoose.yml +++ b/.github/workflows/pymoose.yml @@ -17,24 +17,43 @@ jobs: - os: macos-14 brew: 20 steps: - - uses: actions/checkout@v2 - - if: ${{ matrix.apt }} - run: sudo apt-get install libhdf5-dev libgsl0-dev - - if: ${{ matrix.brew }} - run: | - brew install gsl - brew install hdf5 - - name: Set up Python ${{ matrix.python-version }} - shell: bash - run: | - "${SHELL}" <(curl -L micro.mamba.pm/install.sh) - micromamba self-update - micromamba create -n moose python=${{ matrix.python-version }} graphviz lxml cmake numpy matplotlib vpython hdf5 pytables doxygen -c conda-forge - eval "$(micromamba shell hook --shell bash)" - micromamba activate moose - pip install python-libsbml - pip install pyneuroml - - name: Build - run: | - pip install . - + - name: mamba-setup + uses: mamba-org/setup-micromamba@v1 + with: + environment-name: moose + cache-environment: true + cache-downloads: true + create-args: >- + python=${{ matrix.python-version }} + hdf5 + graphviz + pytables + numpy + matplotlib + vpython + lxml + doxygen + setuptools + wheel + - name: Display Python version + run: | + python -c "import sys; print(sys.version)" + - if: ${{ matrix.apt }} + run: sudo apt-get install libhdf5-dev libgsl0-dev graphviz-dev python3-lxml cmake doxygen + - if: ${{ matrix.brew }} + run: | + brew install gsl + brew install hdf5 + brew install graphviz + brew install cmake + brew install doxygen + - name: install python module dependencies via pip + run: | + pip install pybind11[global] + pip install python-libsbml + - name: checkout + uses: actions/checkout@v4 + - name: build and install + run: | + pip install . + python -c "import moose; moose.le()" diff --git a/CMakeLists.txt b/CMakeLists.txt index 632d5d4925..cb51595c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,9 @@ include(CheckCXXCompiler.cmake) include(CheckIncludeFileCXX) # We find python executable here. Though mainly used inside pymoose. -# FIXME: When cmake 3.12 is widely available use the following: -# find_package(Python3 COMPONENTS Interpreter Numpy) -# set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) -set(Python_ADDITIONAL_VERSIONS 2.7) -find_package(PythonInterp 3.5) -if(NOT PYTHONINTERP_FOUND) - find_package(PythonInterp 2.7) -endif() +find_package(Python3 COMPONENTS Interpreter Numpy) +set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) +find_package(PythonInterp 3.8) set(CMAKE_MACOSX_RPATH OFF) @@ -321,14 +316,9 @@ endif( WITH_BOOST ) # It can be easily done with `pip install pybind11` # See: https://pybind11.readthedocs.io/en/stable/installing.html # - Subha, Mon Apr 22 14:26:58 IST 2024 - -# if(NOT WITH_LEGACY_BINDING) -# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/pybind11) -# add_subdirectory(pybind11) -# else() -# message(STATUS "Building legacy python binding.") -# add_subdirectory(pymoose) -# endif() +execute_process(COMMAND ${CMAKE_COMMAND} -E pybind11-config --cmakedir OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) +find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}") +add_subdirectory(pybind11) # always override debian default installation directory. It will be installed in diff --git a/INSTALL.md b/INSTALL.md index ec13239fa2..d0a61fef6b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,11 +8,12 @@ followings are installed. - gsl-1.16 or higher. - python-numpy +- pybind11 (if the setup fails to find pybind11, try running `pip install pybind11[global]`) On Ubuntu-16.04 or higher, these dependencies can be installed with: ``` -sudo apt-get install python-pip python-numpy cmake libgsl-dev g++ +sudo apt-get install python-pip python-numpy cmake libgsl-dev g++ pybind11 ``` Now use `pip` to download and install `pymoose` from the [github repository](https://github.com/BhallaLab/moose-core). @@ -83,10 +84,26 @@ Now you can import moose in a Python script or interpreter with the statement: >>> import moose >>> moose.test() # will take time. Not all tests will pass. +## Uninstall + +To uninstall moose, run + + $ pip uninstall pymoose + +If you are building moose from source, make sure to get out of the source directory, or you may encounter a message like this: + + Found existing installation: pymoose {version} + Can't uninstall 'pymoose'. No files were found to uninstall. + + + + # Notes -SBML support is enabled by installing +- SBML support is enabled by installing [python-libsbml](http://sbml.org/Software/libSBML/docs/python-api/libsbml-installation.html). Alternatively, it can be installed by using `python-pip` $ sudo pip install python-libsbml + + diff --git a/pybind11/Finfo.cpp b/pybind11/Finfo.cpp index 0ef7a6b7ca..4d24179964 100644 --- a/pybind11/Finfo.cpp +++ b/pybind11/Finfo.cpp @@ -9,10 +9,10 @@ // // ===================================================================================== -#include "../external/pybind11/include/pybind11/pybind11.h" -#include "../external/pybind11/include/pybind11/stl.h" -#include "../external/pybind11/include/pybind11/numpy.h" -#include "../external/pybind11/include/pybind11/functional.h" +#include +#include +#include +#include namespace py = pybind11; diff --git a/pybind11/MooseVec.cpp b/pybind11/MooseVec.cpp index 604293fbb8..19fbd78730 100644 --- a/pybind11/MooseVec.cpp +++ b/pybind11/MooseVec.cpp @@ -13,9 +13,9 @@ using namespace std; -#include "../external/pybind11/include/pybind11/pybind11.h" -#include "../external/pybind11/include/pybind11/numpy.h" -#include "../external/pybind11/include/pybind11/stl.h" +#include +#include +#include namespace py = pybind11; diff --git a/pybind11/MooseVec.h b/pybind11/MooseVec.h index 542bbaee67..c783f272ce 100644 --- a/pybind11/MooseVec.h +++ b/pybind11/MooseVec.h @@ -10,8 +10,8 @@ #ifndef MOOSE_VEC_H #define MOOSE_VEC_H -#include "../external/pybind11/include/pybind11/pybind11.h" -#include "../external/pybind11/include/pybind11/numpy.h" +#include +#include namespace py = pybind11; class MooseVec diff --git a/pybind11/helper.cpp b/pybind11/helper.cpp index c8064125d1..f22c01061c 100644 --- a/pybind11/helper.cpp +++ b/pybind11/helper.cpp @@ -18,16 +18,16 @@ #include #include -#include "../external/pybind11/include/pybind11/functional.h" -#include "../external/pybind11/include/pybind11/numpy.h" -#include "../external/pybind11/include/pybind11/pybind11.h" -#include "../external/pybind11/include/pybind11/stl.h" +#include +#include +#include +#include namespace py = pybind11; // See // https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#binding-stl-containers -// #include "../external/pybind11/include/pybind11/stl_bind.h" +// #include #include "../basecode/header.h" #include "../basecode/global.h" diff --git a/pybind11/pymoose.cpp b/pybind11/pymoose.cpp index 351061c246..3bc8ccaea5 100644 --- a/pybind11/pymoose.cpp +++ b/pybind11/pymoose.cpp @@ -19,9 +19,9 @@ #include #include -#include "../external/pybind11/include/pybind11/pybind11.h" -#include "../external/pybind11/include/pybind11/stl.h" -#include "../external/pybind11/include/pybind11/numpy.h" +#include +#include +#include namespace py = pybind11; using namespace std; diff --git a/setup.py b/setup.py index 2694fc6507..e680a6ebb4 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # See https://docs.python.org/3/library/distutils.html # setuptools is preferred over distutils. And we are supporting python3 only. from setuptools import setup, Extension, Command -from setuptools.command.build_ext import build_ext as _build_ext +from setuptools.command.build_ext import build_ext import subprocess # Global variables. @@ -39,6 +39,7 @@ if not os.path.exists(builddir_): os.makedirs(builddir_) + numCores_ = multiprocessing.cpu_count() @@ -49,18 +50,10 @@ class CMakeExtension(Extension): + # Reference: https://martinopilia.com/posts/2018/09/15/building-python-extension.html def __init__(self, name, **kwargs): # don't invoke the original build_ext for this special extension - import tempfile - - # Create a temp file to create a dummy target. This build raises an - # exception because sources are empty. With python3 we can fix it by - # passing `optional=True` to the argument. With python2 there is no - # getaway from it. - f = tempfile.NamedTemporaryFile(suffix='.cpp', delete=False) - f.write(b'int main() { return 1; }') - Extension.__init__(self, name, sources=[f.name], **kwargs) - f.close() + Extension.__init__(self, name, sources=[], **kwargs) class TestCommand(Command): @@ -79,14 +72,14 @@ def run(self): os.chdir(sdir_) -class build_ext(_build_ext): +class cmake_build_ext(build_ext): user_options = [ ('with-boost', None, 'Use Boost Libraries (OFF)'), ('with-gsl', None, 'Use Gnu Scienfific Library (ON)'), ('with-gsl-static', None, 'Use GNU Scientific Library (static library) (OFF)'), ('debug', None, 'Build moose in debugging mode (OFF)'), ('no-build', None, 'DO NOT BUILD. (for debugging/development)'), - ] + _build_ext.user_options + ] + build_ext.user_options def initialize_options(self): # Initialize options. @@ -97,12 +90,12 @@ def initialize_options(self): self.no_build = 0 self.cmake_options = {} # super().initialize_options() - _build_ext.initialize_options(self) + build_ext.initialize_options(self) def finalize_options(self): # Finalize options. # super().finalize_options() - _build_ext.finalize_options(self) + build_ext.finalize_options(self) self.cmake_options['PYTHON_EXECUTABLE'] = os.path.realpath(sys.executable) self.cmake_options['VERSION_MOOSE'] = version_ if self.with_boost: @@ -122,7 +115,7 @@ def run(self): for ext in self.extensions: self.build_cmake(ext) # super().run() - _build_ext.run(self) + build_ext.run(self) def build_cmake(self, ext): global numCores_ @@ -175,7 +168,7 @@ def build_cmake(self, ext): ] }, install_requires=['numpy', 'matplotlib', 'vpython', 'pybind11'], - extra_requires={'dev': ['coverage', 'pytest', 'pytest-cov']}, - ext_modules=[CMakeExtension('dummy', optional=True)], - cmdclass={'build_ext': build_ext, 'test': TestCommand}, + extra_require={'dev': ['coverage', 'pytest', 'pytest-cov']}, + ext_modules=[CMakeExtension('_moose', optional=True)], + cmdclass={'build_ext': cmake_build_ext, 'test': TestCommand}, )