Skip to content

Commit 6a08012

Browse files
committed
Fixed classy finding
1 parent d3e2c72 commit 6a08012

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

montepython/initialise.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import sys
1212
import os
1313
from io_mp import dictitems,dictvalues,dictkeys
14+
import glob
15+
import warnings
1416

1517
def initialise(custom_command=''):
1618
"""
@@ -157,39 +159,17 @@ def recover_cosmological_module(data):
157159
# If the cosmological code is CLASS, do the following to import all
158160
# relevant quantities
159161
if data.cosmological_module_name == 'CLASS':
162+
sys.path[1:1] = glob.glob(os.path.join(data.path['cosmo'], 'python', '**/*/'), recursive=True)
160163
try:
161-
classy_path = ''
162-
for elem in os.listdir(os.path.join(
163-
data.path['cosmo'], "python", "build")):
164-
if elem.find("lib.") != -1 and elem.find(sys.version)!=-1:
165-
classy_path = os.path.join(
166-
data.path['cosmo'], "python", "build", elem)
167-
if len(classy_path)==1:
168-
classy_path = classy_path[0]
169-
else:
170-
stringcheck = "%i.%i"%(sys.version_info.major,sys.version_info.minor)
171-
for path in classy_path:
172-
if stringcheck in path:
173-
classy_path = path
174-
break
175-
except OSError:
176-
raise io_mp.ConfigurationError(
177-
"You probably did not compile the python wrapper of CLASS. " +
178-
"Please go to /path/to/class/python/ and do\n" +
179-
"..]$ python setup.py build")
180-
181-
# Inserting the previously found path into the list of folders to
182-
# search for python modules.
183-
sys.path.insert(1, classy_path)
184-
try:
185-
from classy import Class
164+
import classy
165+
if data.path['cosmo'] not in classy.__file__:
166+
warnings.warn(f"The classy wrapper {classy.__file__} was not imported from " +
167+
f"the correct folder {data.path['cosmo']}. You might have " +
168+
"forgotten to compile the wrapper.")
186169
except ImportError:
187-
raise io_mp.MissingLibraryError(
188-
"You must have compiled the classy.pyx file. Please go to " +
189-
"/path/to/class/python and run the command\n " +
190-
"python setup.py build")
170+
raise io_mp.MissingLibraryError("You need to have the python wrapper of CLASS installed.")
191171

192-
cosmo = Class()
172+
cosmo = classy.Class()
193173
else:
194174
raise io_mp.ConfigurationError(
195175
"Unrecognised cosmological module. " +

0 commit comments

Comments
 (0)