Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched to pipnest package structure #5

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a4e933a
Switched to pipnest package structure
Helveg May 27, 2020
3af82e0
Package can now be built with `python setup.py sdist`
Helveg May 27, 2020
8eeb0ad
Switch to pipnest test
Helveg Jul 13, 2020
ade1b24
pipfix
Helveg Jul 13, 2020
bd4b576
python 3.6 for travis
Helveg Jul 13, 2020
088b24e
Try 3.6.9 to solve libs problem
Helveg Sep 22, 2020
29ec540
use virtual python, not system python3, as nest is installed to former.
Helveg Sep 22, 2020
87ddaf6
test prints
Helveg Sep 22, 2020
620d6af
only site packages in virtualenv? cheat with PYTHON_PATH
Helveg Sep 22, 2020
10dca26
install NEST from DBBS fork
Helveg Sep 22, 2020
97b9499
no site packages at all, come ooooon PYTHON_PATH
Helveg Sep 22, 2020
c2d4084
fixed python path
Helveg Sep 22, 2020
23ceaec
fixed pythonpath typos
Helveg Sep 22, 2020
23bbfa3
eh?
Helveg Sep 22, 2020
6d41f9f
from inside run?
Helveg Sep 22, 2020
28ce231
wth
Helveg Sep 22, 2020
5e22d2f
lib folder check
Helveg Sep 22, 2020
83ade3e
oops, wasn't succesfully cloning the dbbs fork
Helveg Sep 22, 2020
23bcf3e
split up the command for readability
Helveg Sep 22, 2020
8fa7a20
is this the executable?
Helveg Sep 22, 2020
e1e4593
no need to specify probably
Helveg Sep 22, 2020
95d05b5
cleaned up setup + added check for nest install tree
Helveg Sep 22, 2020
ef372ae
full path to test file
Helveg Sep 22, 2020
a9ba68a
removed path trickery from Python
Helveg Sep 22, 2020
008bc5f
fixed full path
Helveg Sep 22, 2020
11d4027
moved tests (to change case)
Helveg Sep 23, 2020
9fc1c21
Changed 'Tests' to 'tests'
Helveg Sep 23, 2020
8350714
use LD_LIBRARY_PATH
Helveg Sep 23, 2020
fc036e1
check nest config contents
Helveg Sep 23, 2020
f4db597
reinstate PYTHONPATH
Helveg Sep 23, 2020
ee43962
nest config discarded as option to determine lib dir
Helveg Sep 23, 2020
8f16f11
Give detailed error message on how to fix env vars for module install
Helveg Sep 23, 2020
0de6981
fixed random excerpt
Helveg Sep 23, 2020
56b10d0
fix error msg
Helveg Sep 23, 2020
7429040
add paths
Helveg Sep 23, 2020
4cf4cc2
added the CMake README instructions again
Helveg Sep 23, 2020
5c9d25c
fixed CMake build instructions
Helveg Sep 24, 2020
3029a10
version 1
Helveg Sep 24, 2020
4e70eed
only check for nest module path.
Helveg Sep 27, 2020
bab23d0
fixed condition
Helveg Sep 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
*.egg-info
dist/*
build/*
3 changes: 3 additions & 0 deletions .pipnest/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
language: generic
language: python
dist: bionic
cache:
pip: true
directories:
- $HOME/nest-$NEST_VERSION
jobs:
include:
python: 3.6.9
install:
- export NEST_INSTALL_DIR=/home/travis/nest-$NEST_VERSION
- source devops/check_nest_cache.sh
Expand All @@ -13,7 +16,10 @@ install:
else
echo "NEST cache found, skipping installation";
fi
- source devops/install_cereb_nest.sh
- source devops/post_install_env_vars.sh
- export PYTHONPATH=/home/travis/nest-$NEST_VERSION/lib/python3.6/site-packages:$PYTHONPATH
- export NEST_MODULE_PATH=/home/travis/nest-$NEST_VERSION/lib/nest:$NEST_MODULE_PATH
- export SLI_PATH=/home/travis/nest-$NEST_VERSION/share/sli:$SLI_PATH
- python -m pip install .
script:
- python3 -c "import nest; nest.Install('cerebmodule')"
- python /home/travis/build/dbbs-lab/cereb-nest/tests/test_install.py
- python -c "import nest; nest.Install('cerebmodule')"
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include cereb_nest/*
include cereb_nest/sli/*
include setup.py
include README.md
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
[![Build Status](https://travis-ci.com/dbbs-lab/cereb-nest.svg?branch=master)](https://travis-ci.com/dbbs-lab/cereb-nest)
# cereb_nest

# cereb-nest
pip installable NEST extension module, generated by pipnest.

Tested with:
## Installation instructions

*branch master*: Ubuntu 18.04 and Red Hat Enterprise Linux Server 7.7 (Maipo), Python 3.7.3 and NEST Release 2.18.0
### Using pip

When installed through pip the module is built for you with CMake outside of the python
package folder, this means that pip cannot track the real installation status. To
uninstall and reinstall see [Uninstallation](Uninstallation).

### Installation instructions
0. Install NEST following the instructions provided here (https://www.nest-simulator.org/)

0. Install NEST following the instructions provided here (http://www.nest-simulator.org/)
1. Install using pip

```
pip install cereb_nest --no-cache-dir
```

3. Load the module after importing nest:

```
import nest
nest.Install("cerebmodule")
```

#### Uninstallation

To uninstall this module use `pip uninstall cereb_nest` and remove the
`(lib)cerebmodule.so` files from the `lib/nest/` directory in your nest installation.

### Using CMake

1. Export an Environment Variable containing the installation directory of NEST. E.g.:
```
Expand All @@ -20,14 +41,15 @@ export NEST_INSTALL_DIR=$HOME/nest-simulator-install
cd $HOME
git clone https://github.com/dbbs-lab/cereb-nest/
```
3. Move to cereb-nest directory and create a new folder where you will build the extension module
3. Move to the cereb-nest directory and create a new folder where you will build the extension module
```
mkdir $HOME/cereb-nest-build
cd $HOME/cereb-nest-build
cd cereb-nest
mkdir build
cd build
```
4. Run the following CMake command (Tested with CMake 3.2.2)
```
cmake -Dwith-nest=${NEST_INSTALL_DIR}/bin/nest-config $HOME/cereb-nest
cmake -Dwith-nest=${NEST_INSTALL_DIR}/bin/nest-config ../cereb_nest
```

The resulting output should be something similar to:
Expand Down Expand Up @@ -56,7 +78,7 @@ Make sure to set the environment variables:
[...]
```

5. Execute the last two lines, generated by the CMake command.
5. Execute the last two lines, generated by the CMake command.
```
export NEST_MODULE_PATH=/home/alberto/nest-simulator-install/lib/nest:$NEST_MODULE_PATH
export SLI_PATH=/home/alberto/nest-simulator-install/share/nest/sli:$SLI_PATH
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion devops/install_cereb_nest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PREVIOUS_DIR=$PWD
mkdir build
cd build
CEREBNEST_BUILD_DIR=$PWD
cmake -Dwith-nest=${NEST_INSTALL_DIR}/bin/nest-config ..
cmake -Dwith-nest=${NEST_INSTALL_DIR}/bin/nest-config ../cereb_nest
export NEST_MODULE_PATH=${NEST_INSTALL_DIR}/lib/nest:$NEST_MODULE_PATH
export SLI_PATH=${NEST_INSTALL_DIR}/share/nest/sli:$SLI_PATH
make
Expand Down
12 changes: 9 additions & 3 deletions devops/install_nest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ echo "Empty cache, starting NEST v$NEST_VERSION installation."
echo ""
export MY_BEFORE_DIR=$PWD
cd /home/travis
wget https://github.com/nest/nest-simulator/archive/v$NEST_VERSION.tar.gz -O nest-simulator-$NEST_VERSION.tar.gz
tar -xzf nest-simulator-$NEST_VERSION.tar.gz
git clone --depth 1 https://github.com/dbbs-lab/nest-simulator nest-simulator-$NEST_VERSION
mkdir nest-simulator-$NEST_VERSION-build
mkdir nest-install-$NEST_VERSION
cd nest-simulator-$NEST_VERSION-build
cmake -Dwith-python=3 -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m/ -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nest-$NEST_VERSION /home/travis/nest-simulator-$NEST_VERSION
ls /home/travis/virtualenv
ls /home/travis/virtualenv/python3.6.9
ls /home/travis/virtualenv/python3.6.9/bin
cmake -Dwith-python=3 \
-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
-DPYTHON_INCLUDE_DIR=/usr/include/python3.6m/ \
-DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nest-$NEST_VERSION \
/home/travis/nest-simulator-$NEST_VERSION
make
make install
cd $MY_BEFORE_DIR
104 changes: 104 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python
import os, sys

import subprocess
from setuptools import setup, Extension
from setuptools.dist import Distribution
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install

with open("README.md", 'r') as fp:
readme_text = fp.read()

def check_cmake():
try:
out = subprocess.check_output(['cmake', '--version'])
return True
except OSError:
return False

class cmake_extension(Extension):
def __init__(self, name):
Extension.__init__(self, name, sources=[])

class cmake_build(build_ext):
def run(self):
if not check_cmake():
raise RuntimeError('CMake is not available. CMake 3.12 is required.')

import nest

nest_install_dir = os.path.sep.join(nest.__path__[0].split(os.path.sep)[:-4])
mod = os.getenv("NEST_MODULE_PATH", "")
mod_dir = os.path.join(nest_install_dir, "lib", "nest")
if mod_dir not in mod:
raise Exception(
f"Please make sure 'NEST_MODULE_PATH' env var contains '{mod_dir}' for the installation to succeed.\n"
+ f"Current value: '{mod}'"
)


# Installation dir of nest, required for the cmake command
nest_config = os.path.join(nest_install_dir, "bin", "nest-config")
# Name of the extension, will be used to determine folder name
ext_name = self.extensions[0].name
# The path where CMake will be configured and Arbor will be built.
build_directory = os.path.abspath(self.build_temp)
# The path where the package will be copied after building.
lib_directory = os.path.abspath(self.build_lib)
# The path where the built libraries end up
source_path = build_directory
# Where to copy the package after it is built, so that whatever the next phase is
# can copy it into the target 'prefix' path.
dest_path = os.path.join(lib_directory, ext_name)

cmake_args = [
'-DCMAKE_BUILD_TYPE=Release', # we compile with debug symbols in release mode.
"-Dwith-nest=" + nest_config
]
build_args = ['--config', 'Release']

env = os.environ.copy()
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)

cmake_list_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), ext_name)
print('-'*20, 'Configure CMake')
subprocess.check_call(['cmake', cmake_list_dir] + cmake_args,
cwd=self.build_temp, env=env)

print('-'*20, 'Build')
cmake_cmd = ['cmake', '--build', '.'] + build_args
subprocess.check_call(cmake_cmd,
cwd=self.build_temp)

cmake_cmd = ['make', 'install']
subprocess.check_call(cmake_cmd,
cwd=self.build_temp)

# Copy from build path to some other place from whence it will later be installed.
# ... or something like that
# ... setuptools is an enigma monkey patched on a mystery
if not os.path.exists(dest_path):
os.makedirs(dest_path, exist_ok=True)
self.copy_tree(source_path, dest_path)

setup(
name="cereb_nest",
version="1.0.0",
description="pip installable NEST extension module, generated by pipnest.",
license="MIT",
author="Alice Geminiani",
author_email="[email protected]",
url="https://github.com/Helveg/pipnest",
long_description=readme_text,
long_description_content_type="text/markdown",
zip_safe=False,
packages=['cereb_nest'],
package_data={'cereb_nest': ['*', 'sli/*', 'doc/*']},
ext_modules=[cmake_extension("cereb_nest")],
cmdclass={
'build_ext': cmake_build,
},
include_package_data = True,
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading