Skip to content
13 changes: 1 addition & 12 deletions nexus/bin/eshdf
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ from optparse import OptionParser
# Non-standard Python library imports
import numpy as np


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules

# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version
from nexus.developer import obj,log,warn,error,ci
Expand Down
27 changes: 27 additions & 0 deletions nexus/bin/nexus_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env python3

def find_nexus_modules():
import os
import sys
# Prepend the assumed path of a folder containing the closely coupled nexus module to module search path
# It points to the top Nexus directory not necessarily the top QMCPACK directory.
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..'))
sys.path.insert(0,nexus_lib)

# check import of nexus modules
try:
import nexus
except (ImportError, ModuleNotFoundError):
raise ImportError(
"Nexus module is required but cannot be imported!"
)
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))

# ensure closely coupled nexus module is in use.
if nexus_lib != nexus_lib2:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the line that is probably going to continue failing if the executables get moved. The enforcement of location of the current file with the location of Nexus means that this will likely still result in a failure if the executables are moved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately that is a current requirement.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should keep the strict association in this PR. We can remove it in a following PR once a decision is made.

exe_full_path = os.path.abspath(sys.argv[0])
raise Exception('Broken Nexus installation! Nexus Python scripts are required to reside in the directory that contains the Nexus module.'
+ '\nNexus Python script : ' + exe_full_path
+ '\nNexus module root directory : ' + nexus_lib2)

#end def find_nexus_modules
13 changes: 1 addition & 12 deletions nexus/bin/nxs-redo
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@ import os
from optparse import OptionParser


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules


# Get Nexus version
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version

Expand Down
14 changes: 1 addition & 13 deletions nexus/bin/nxs-sim
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
import os
from optparse import OptionParser


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules


# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version
from nexus.developer import obj
Expand Down
24 changes: 1 addition & 23 deletions nexus/bin/nxs-test
Original file line number Diff line number Diff line change
Expand Up @@ -2178,17 +2178,7 @@ def regenerate_reference(update=False):

#end def regenerate_reference





def find_nexus_modules():
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.append(nexus_lib)
#end def find_nexus_modules

from nexus_modules import find_nexus_modules

def import_nexus_module(module_name):
import importlib
Expand Down Expand Up @@ -2220,18 +2210,6 @@ if __name__=='__main__':
from time import time # used to get user wall clock rather than cpu time
tstart_all = time()

testing_wrong_nexus_install = False
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 deleted?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please reply. This should not be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The replaced find_nexus_module did the work already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to the current requirement of nxs-test that exception should not be raise by itself. The gold implementation can not be used and kept by nxs-test. I reverted most of the changes in nxs-test.

try:
import nexus
nexus_file = os.path.realpath(os.path.join(nexus.__file__,'../..'))
test_file = os.path.realpath(os.path.join(__file__,'../..'))
testing_wrong_nexus_install = nexus_file!=test_file
except:
pass
if testing_wrong_nexus_install:
print('\n\n\nInstalled Nexus package does not reside with this nxs-test executable.\n Currently installed nexus package: {}\n Correct Nexus package : {}\n Please install the correct Nexus package above.\n\n'.format(nexus_file,test_file))
sys.exit(1)

# read command line input
regex = None
ctest = False
Expand Down
15 changes: 2 additions & 13 deletions nexus/bin/qdens
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@
import gc
import os
from optparse import OptionParser
import nexus.numpy_extensions as npe

def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules


# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
import nexus.numpy_extensions as npe
from nexus.nexus_version import nexus_version
from nexus.developer import DevBase,obj,error,ci,unavailable
import nexus.memory as memory
Expand Down
14 changes: 1 addition & 13 deletions nexus/bin/qdens-radial
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@

from optparse import OptionParser


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules


# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version
from nexus.developer import DevBase,obj,error,ci,unavailable
Expand Down
12 changes: 1 addition & 11 deletions nexus/bin/qmc-fit
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@ except (ImportError,RuntimeError):
#end try


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules

# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version
from nexus.developer import DevBase,obj,log,warn,error
Expand Down
14 changes: 1 addition & 13 deletions nexus/bin/qmca
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ import os
import sys
from optparse import OptionParser


def find_nexus_modules():
import os
import sys
nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))
assert(os.path.exists(nexus_lib))
sys.path.insert(0,nexus_lib)
import nexus
nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))
assert nexus_lib2==nexus_lib
#end def find_nexus_modules


# Load Nexus modules
from nexus_modules import find_nexus_modules
find_nexus_modules()
from nexus.nexus_version import nexus_version
from nexus.developer import DevBase,obj,unavailable
Expand Down
Loading