|
11 | 11 | import sys |
12 | 12 | import os |
13 | 13 | from io_mp import dictitems,dictvalues,dictkeys |
| 14 | +import glob |
| 15 | +import warnings |
14 | 16 |
|
15 | 17 | def initialise(custom_command=''): |
16 | 18 | """ |
@@ -157,39 +159,17 @@ def recover_cosmological_module(data): |
157 | 159 | # If the cosmological code is CLASS, do the following to import all |
158 | 160 | # relevant quantities |
159 | 161 | if data.cosmological_module_name == 'CLASS': |
| 162 | + sys.path[1:1] = glob.glob(os.path.join(data.path['cosmo'], 'python*', '**', ''), recursive=True) |
160 | 163 | 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.") |
186 | 169 | 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.") |
191 | 171 |
|
192 | | - cosmo = Class() |
| 172 | + cosmo = classy.Class() |
193 | 173 | else: |
194 | 174 | raise io_mp.ConfigurationError( |
195 | 175 | "Unrecognised cosmological module. " + |
|
0 commit comments