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

Clean up handling of path-related environment variables #1578

Merged
merged 33 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1dcee7b
Don't export variables that can confuse NEST
jougs May 4, 2020
f1736d6
Fix path for bin dir
jougs May 4, 2020
ba6a4ca
Update extras/nest_vars.sh.in
jougs May 5, 2020
078800b
Update extras/nest_vars.sh.in
jougs May 5, 2020
6c7f863
Update extras/nest_vars.sh.in
jougs May 5, 2020
2463ad9
Merge branch 'master' of github.com:nest/nest-simulator into unpollut…
jougs May 8, 2020
2b535ab
Dynamically determine PyNEST test directory
jougs May 8, 2020
1ea4893
Remove environment variable NEST_DOC_DIR
jougs May 8, 2020
8151175
Remove environment variable NEST_DATA_DIR
jougs May 8, 2020
4800125
Remove environment variable NEST_INSTALL_DIR
jougs May 8, 2020
de0c2b4
Fix formatting
jougs May 8, 2020
b33a74c
Fix quotation of string
jougs May 8, 2020
59c9754
Merge branch 'master' of github.com:nest/nest-simulator into unpollut…
jougs May 12, 2020
5d6958e
Silence remaining RNGManager output. This is a follow-up to #1577.
jougs May 13, 2020
d602811
Beautify message composition
jougs May 13, 2020
9e81cfe
Fix wording of comment
jougs May 13, 2020
b7cf678
Extend and fix explanation for MyModule installation
jougs May 13, 2020
5b64508
Use sli instead of nest to get the basedir for the tests
jougs May 13, 2020
827421c
Update doc/guides/spatial/guide_spatially_structured_networks.rst
jougs May 14, 2020
82448a2
Update doc/guides/spatial/guide_spatially_structured_networks.rst
jougs May 14, 2020
3ead74e
Silence NEST at startup when getting PyNEST path
jougs Jun 16, 2020
480b2c2
Merge branch 'unpollute_environment' of github.com:jougs/nest-simulat…
jougs Jun 16, 2020
5363488
Merge branch 'master' of github.com:nest/nest-simulator into unpollut…
jougs Jun 16, 2020
dc93823
Fix silencing of NEST
jougs Jun 17, 2020
aa25266
Use importlib to find PyNEST path instead of importing it
jougs Jun 17, 2020
157426d
Merge branch 'master' of github.com:nest/nest-simulator into unpollut…
jougs Jun 17, 2020
0947e63
Re-add PYTHON variable accidentally lost in 157426d
jougs Jun 18, 2020
b07c26b
Remove line referencing old installation instructions
jougs Jun 24, 2020
0613b18
Update wrt to removed environment variables
jougs Jun 24, 2020
742e631
Make variable names consistent by removing dollar sign
jougs Jun 24, 2020
adabf1d
Merge branch 'master' of github.com:nest/nest-simulator into unpollut…
jougs Jun 24, 2020
0c39c0a
Add library installation directory to dl search path
jougs Jun 25, 2020
bb5666c
Fix note about module location
jougs Jun 29, 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
18 changes: 10 additions & 8 deletions doc/guides/spatial/guide_spatially_structured_networks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1521,14 +1521,16 @@ Manual. The basic steps required to get started are:

.. code:: bash

cmake -Dwith-nest=${NEST_INSTALL_DIR}/bin/nest-config ../mm_src

4. MyModule will then be installed to ``${NEST_INSTALL_DIR}``. This
ensures that NEST will be able to find initializing SLI files for the
module. You should not use the ``--prefix`` to select a different
installation destination. If you do, you must make sure to use
addpath in SLI before loading the module to ensure that NEST will
find the SLI initialization file for your module.
cmake -Dwith-nest=${NEST_INSTALL_PREFIX}/bin/nest-config ../mm_src

4. MyModule will be installed under ``NEST_INSTALL_PREFIX``. This
ensures that NEST will be able to find the module and initializing SLI
files for the module. You should not use the ``-DCMAKE_INSTALL_PREFIX``
to select a different installation destination. If you do, you must make
sure to use ``addpath`` in SLI before loading the module to let NEST
find the SLI initialization file for your module. You also might have
to set ``LD_LIBRARY_PATH`` (on Linux) or ``DYLD_LIBRARY_PATH`` (on macOS)``
for the module itself to be found.

5. Compile and install.

Expand Down
10 changes: 0 additions & 10 deletions doc/installation/linux_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,9 @@ The following variables are set in ``nest_vars.sh``:

* - Variable
- Description
* - ``NEST_INSTALL_DIR``
- NEST installation directory. Contains ``bin``, ``lib``, etc.
* - ``NEST_DATA_DIR``
- NEST finds standard *.sli files in ``$NEST_DATA_DIR/sli``
* - ``NEST_DOC_DIR``
- NEST built-in online help finds help files in ``$NEST_DOC_DIR/help``
* - ``NEST_PYTHON_PREFIX``
- The path where the PyNEST bindings are installed.
* - ``PYTHONPATH``
- Search path for non-standard Python module locations. Will be newly set or prepended to the already existing variable if it is already set.
* - ``PATH``
- Search path for binaries. Will be newly set or prepended to the already existing variable if it is already set.
* - ``LD_LIBRARY_PATH``
- Search path for shared objects (*.so files). Note: called ``DYLD_LIBRARY_PATH`` on MacOS. Will be newly set or prepended to the already existing variable if it is already set.

If your operating system does not find the ``nest`` executable or if Python does not find the ``nest`` module, your path variables may not be set correctly. This may also be the case if Python cannot load the ``nest`` module due to missing or incompatible libraries.
3 changes: 0 additions & 3 deletions examples/nest/ReadData_demo.dat

This file was deleted.

63 changes: 0 additions & 63 deletions examples/nest/ReadData_demo.sli

This file was deleted.

2 changes: 1 addition & 1 deletion extras/nest-config.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh

prefix=${NEST_INSTALL_DIR:-@CMAKE_INSTALL_PREFIX@}
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix=${prefix}

usage()
Expand Down
27 changes: 4 additions & 23 deletions extras/nest_vars.sh.in
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
#!/bin/sh

# NEST is installed here. When you relocate NEST, change this variable.
export NEST_INSTALL_DIR="@CMAKE_INSTALL_PREFIX@"
jougs marked this conversation as resolved.
Show resolved Hide resolved
# Make PyNEST available by prepending its path to PYTHONPATH in a safe way.
export PYTHONPATH="@CMAKE_INSTALL_PREFIX@/@PYEXECDIR@${PYTHONPATH:+:$PYTHONPATH}"

# NEST finds standard *.sli files $NEST_DATA_DIR/sli
export NEST_DATA_DIR="${NEST_INSTALL_DIR}/@CMAKE_INSTALL_DATADIR@"
jougs marked this conversation as resolved.
Show resolved Hide resolved

# NEST finds help files $NEST_DOC_DIR/help
export NEST_DOC_DIR="${NEST_INSTALL_DIR}/@CMAKE_INSTALL_DOCDIR@"
jougs marked this conversation as resolved.
Show resolved Hide resolved

# The path in which NEST dynamic libraries are found. Works also if $(DY)LD_LIBRARY_PATH is undefined.
if [ "`uname`" = "Darwin" ]; then
export DYLD_LIBRARY_PATH="$NEST_INSTALL_DIR/@CMAKE_INSTALL_LIBDIR@/nest"${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
else
export LD_LIBRARY_PATH="$NEST_INSTALL_DIR/@CMAKE_INSTALL_LIBDIR@/nest"${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
fi

# The path where the PyNEST bindings are installed.
export NEST_PYTHON_PREFIX="${NEST_INSTALL_DIR}/@PYEXECDIR@"

# Prepend NEST to PYTHONPATH. Works also if $PYTHONPATH is undefined.
export PYTHONPATH="$NEST_PYTHON_PREFIX${PYTHONPATH:+:$PYTHONPATH}"

# Make nest/sli/... executables visible.
export PATH="${NEST_INSTALL_DIR}/bin:${PATH}"
# Make NEST executables available by prepending their path to PATH.
export PATH="@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@:${PATH}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export PATH="@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@:${PATH}"
export PATH="@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@${PATH:+:$PATH}"

Copy link
Contributor Author

@jougs jougs May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we don't need this safety net, as PATH should never be empty on any reasonably configured system. However, if you insist, I'll commit the suggestion and adapt the comment above it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jochen, I fully trust your definition of "reasonable", it's just that I wouldn't trust this in the general case!

3 changes: 0 additions & 3 deletions nestkernel/rng_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ nest::RNGManager::create_rngs_()
void
nest::RNGManager::create_grng_()
{
// create new grng
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this file accidentally added to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should have been in #1577, which now caused trouble here when capturing the output of nest to determine a path in do_tests.sh. As @heplesser reviewed #1577 and is also a reviewer on this one and the change is necessary for making this one run, I thought I rather don't file yet another PR for it.

LOG( M_INFO, "Network::create_grng_", "Creating new default global RNG" );

// create default RNG with default seed
#ifdef HAVE_GSL
grng_ = librandom::RngPtr( new librandom::GslRandomGen( gsl_rng_knuthran2002, librandom::RandomGen::DefaultSeed ) );
Expand Down
6 changes: 0 additions & 6 deletions pynest/nest/lib/hl_api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,6 @@ def show_help_with_pager(hlpobj, pager=None):
pager to use, False if you want to display help using print().
"""

if 'NEST_INSTALL_DIR' not in os.environ:
print(
'NEST help needs to know where NEST is installed.'
'Please source nest_vars.sh or define NEST_INSTALL_DIR manually.')
return

# check that help is available
objf = get_help_filepath(hlpobj)
if objf is None:
Expand Down
10 changes: 2 additions & 8 deletions pynest/nest/lib/hl_api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,8 @@ def helpdesk():

"""

if 'NEST_DOC_DIR' not in os.environ:
print(
'NEST help needs to know where NEST is installed.'
'Please source nest_vars.sh or define NEST_DOC_DIR manually.')
return

helpfile = os.path.join(os.environ['NEST_DOC_DIR'], 'help',
'helpindex.html')
nestdocdir = sli_func("statusdict/prgdocdir ::")
helpfile = os.path.join(nestdocdir, 'help', 'helpindex.html')

# Under Windows systems webbrowser.open is incomplete
# See <https://bugs.python.org/issue8232>
Expand Down
44 changes: 4 additions & 40 deletions sli/slistartup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ true
SLI ] (NONEXISTING) getenv =
false

SLI ] (NEST_DATA_DIR) getenv
SLI [2] { (Using root path: ) =only = }
SLI [3] { (Warning: $NEST_DATA_DIR undefined) =}
SLI [4] ifelse
Using root path: /home/gewaltig/nest/release/release

SLI ] (/home) getenv
false

Expand Down Expand Up @@ -209,7 +203,7 @@ SLIStartup::checkenvpath( std::string const& envvar, SLIInterpreter* i, std::str
SLIStartup::SLIStartup( int argc, char** argv )
: startupfilename( "sli-init.sli" )
, slilibpath( "/sli" )
, slihomepath( NEST_INSTALL_PREFIX "/" NEST_INSTALL_DATADIR )
, slilibdir( NEST_INSTALL_PREFIX "/" NEST_INSTALL_DATADIR )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the "data" directory and not a "lib" directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEST_INSTALL_DATADIR contains all non-binary data files for NEST and the SLI standard library is considered as such data.

, slidocdir( NEST_INSTALL_PREFIX "/" NEST_INSTALL_DOCDIR )
, sliprefix( NEST_INSTALL_PREFIX )
, verbosity_( SLIInterpreter::M_INFO ) // default verbosity level
Expand Down Expand Up @@ -340,43 +334,13 @@ SLIStartup::init( SLIInterpreter* i )
i->createcommand( getenv_name, &getenvfunction );
std::string fname;

// Check for supplied NEST_DATA_DIR
std::string slihomepath_env = checkenvpath( "NEST_DATA_DIR", i, slihomepath );
if ( slihomepath_env != "" )
{
slihomepath = slihomepath_env; // absolute path & directory exists
i->message(
SLIInterpreter::M_DEBUG, "SLIStartup", String::compose( "Using NEST_DATA_DIR=%1", slihomepath ).c_str() );
}

// check for supplied NEST_DOC_DIR
std::string slidocdir_env = checkenvpath( "NEST_DOC_DIR", i, slidocdir );
if ( slidocdir_env != "" )
{
slidocdir = slidocdir_env; // absolute path & directory exists
i->message( SLIInterpreter::M_DEBUG, "SLIStartup", String::compose( "Using NEST_DOC_DIR=%1", slidocdir ).c_str() );
}

// check for supplied NEST_INSTALL_DIR
std::string sliprefix_env = checkenvpath( "NEST_INSTALL_DIR", i, sliprefix );
if ( sliprefix_env != "" )
{
sliprefix = sliprefix_env; // absolute path & directory exists
i->message(
SLIInterpreter::M_DEBUG, "SLIStartup", String::compose( "Using NEST_INSTALL_DIR=%1", sliprefix ).c_str() );
}

// check for sli-init.sli
if ( not checkpath( slihomepath, fname ) )
if ( not checkpath( slilibdir, fname ) )
{
i->message( SLIInterpreter::M_FATAL, "SLIStartup", "Your NEST installation seems broken. \n" );
i->message( SLIInterpreter::M_FATAL, "SLIStartup", "I could not find the startup file that" );
i->message( SLIInterpreter::M_FATAL,
"SLIStartup",
std::string( std::string( "should have been in " ) + slihomepath ).c_str() );
i->message( SLIInterpreter::M_FATAL, "SLIStartup", ( std::string( "should have been in " ) + slilibdir ).c_str() );
i->message( SLIInterpreter::M_FATAL, "SLIStartup", "Please re-build NEST and try again." );
i->message( SLIInterpreter::M_FATAL, "SLIStartup", "The file install.html in NEST's doc directory tells you how." );

i->message( SLIInterpreter::M_FATAL, "SLIStartup", "Bye." );

// We cannot call i->terminate() here because the interpreter is not
Expand All @@ -401,7 +365,7 @@ SLIStartup::init( SLIInterpreter* i )
statusdict->insert( version_name, Token( new StringDatum( NEST_VERSION_STRING ) ) );
statusdict->insert( exitcode_name, Token( new IntegerDatum( EXIT_SUCCESS ) ) );
statusdict->insert( prgbuilt_name, Token( new StringDatum( String::compose( "%1 %2", __DATE__, __TIME__ ) ) ) );
statusdict->insert( prgdatadir_name, Token( new StringDatum( slihomepath ) ) );
statusdict->insert( prgdatadir_name, Token( new StringDatum( slilibdir ) ) );
statusdict->insert( prgdocdir_name, Token( new StringDatum( slidocdir ) ) );
statusdict->insert( prefix_name, Token( new StringDatum( sliprefix ) ) );
statusdict->insert( host_name, Token( new StringDatum( NEST_HOST ) ) );
Expand Down
2 changes: 1 addition & 1 deletion sli/slistartup.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SLIStartup : public SLIModule
{
const std::string startupfilename;
const std::string slilibpath;
std::string slihomepath;
std::string slilibdir;
std::string slidocdir;
std::string sliprefix;

Expand Down
14 changes: 6 additions & 8 deletions testsuite/do_tests.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ EXTENDED_REGEX_PARAM=r
. "$(dirname $0)/junit_xml.sh"
. "$(dirname $0)/run_test.sh"

TEST_BASEDIR="${NEST_DOC_DIR:-@CMAKE_INSTALL_FULL_DOCDIR@}"
TEST_BASEDIR="$(sli -c 'statusdict/prgdocdir :: =only')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the test hardness use the docdir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of some historical peculiarity (someone once thought the tests are also good examples and thus a kind of documentation), we install the tests into the documentation installation directory. I am already in discussions with @heplesser about changing this in the future.

TEST_OUTDIR="${TEST_OUTDIR:-$( pwd )/reports}"
TEST_LOGFILE="${TEST_OUTDIR}/installcheck.log"
TEST_OUTFILE="${TEST_OUTDIR}/output.log"
Expand All @@ -104,7 +104,6 @@ fi
mkdir "${TEST_OUTDIR}"

PYTHON="${PYTHON:-python}"
PYTHON_HARNESS="${NEST_DATA_DIR:-@CMAKE_INSTALL_FULL_DATADIR@}/extras/do_tests.py"

TMPDIR="${TMPDIR:-${TEST_OUTDIR}}"
TEST_TMPDIR="$(mktemp -d "${TMPDIR:-/tmp}/nest.XXXXX")"
Expand Down Expand Up @@ -432,7 +431,7 @@ if test "x${TEST_PYNEST}" = xtrue ; then
echo "Phase 7: Running PyNEST tests."
echo "------------------------------"

# If possible, we run using nosetests. To find out if nosetests work,
# If possible, we run using nosetests. To find out if nosetests works,
# we proceed in two steps:
# 1. Check if nosetests is available
# 2. Check that nosetests supports --with-xunit by running nosetests.
Expand All @@ -442,12 +441,11 @@ if test "x${TEST_PYNEST}" = xtrue ; then
# dummy directory to search for tests.

if command -v @NOSETESTS@ >/dev/null 2>&1 && @PYTHON@ @NOSETESTS@ --with-xunit --xunit-file=/dev/null --where="${TEST_OUTDIR}" >/dev/null 2>&1; then

@PYTHON@ @NOSETESTS@ -v \
--with-xunit --xunit-testsuite-name="07_pynest_tests" --xunit-file="${TEST_OUTDIR}/07_pynest_tests.xml" \
"${NEST_PYTHON_PREFIX:-@CMAKE_INSTALL_PREFIX@/@PYEXECDIR@}/nest/tests" 2>&1 \
# Find the path to PyNEST without actually importing it
PYNEST_TEST_DIR="$(@PYTHON@ -c "import importlib; print(importlib.util.find_spec('nest').submodule_search_locations[0])")/tests"
XUNIT_FILE="${TEST_OUTDIR}/07_pynest_tests.xml"
@PYTHON@ @NOSETESTS@ -v --with-xunit --xunit-testsuite-name="07_pynest_tests" --xunit-file="${XUNIT_FILE}" "${PYNEST_TEST_DIR}" 2>&1 \
| tee -a "${TEST_LOGFILE}" | grep -i --line-buffered "\.\.\. ok\|fail\|skip\|error" | sed 's/^/ /'

else
echo
echo " Not running PyNEST tests because nosetests is not available."
Expand Down