|
54 | 54 | from . import GSASIImath as G2mth |
55 | 55 |
|
56 | 56 | # Delay imports loading to not slow down small scripts that don't need them |
57 | | -Readers = {'Pwdr':[], 'Phase':[], 'Image':[]} |
| 57 | +Readers = {'Pwdr': [], 'Phase': [], 'Image': [], 'importErrpkgs': []} |
58 | 58 | '''Readers by reader type''' |
59 | 59 | exportersByExtension = {} |
60 | 60 | '''Specifies the list of extensions that are supported for Powder data export''' |
@@ -166,10 +166,14 @@ def LoadG2fil(): |
166 | 166 | ''' |
167 | 167 | if len(Readers['Pwdr']) > 0: return |
168 | 168 | # initialize imports |
| 169 | + before = list(G2fil.condaRequestList.keys()) |
169 | 170 | Readers['Pwdr'] = G2fil.LoadImportRoutines("pwd", "Powder_Data") |
170 | 171 | Readers['Phase'] = G2fil.LoadImportRoutines("phase", "Phase") |
171 | 172 | Readers['Image'] = G2fil.LoadImportRoutines("img", "Image") |
172 | 173 | Readers['HKLF'] = G2fil.LoadImportRoutines('sfact','Struct_Factor') |
| 174 | + # save list of importers that could not be loaded |
| 175 | + Readers['importErrpkgs'] = [i for i in G2fil.condaRequestList.keys() |
| 176 | + if i not in before] |
173 | 177 |
|
174 | 178 | # initialize exports |
175 | 179 | for obj in G2fil.LoadExportRoutines(None): |
@@ -435,14 +439,31 @@ def import_generic(filename, readerlist, fmthint=None, bank=None, |
435 | 439 | filename = downloadFile(filename,download_loc) |
436 | 440 | # Translated from OnImportGeneric method in GSASII.py |
437 | 441 | primaryReaders, secondaryReaders = [], [] |
| 442 | + hintcount = 0 |
438 | 443 | for reader in readerlist: |
439 | 444 | if fmthint is not None and fmthint not in reader.formatName: continue |
| 445 | + hintcount += 1 |
440 | 446 | flag = reader.ExtensionValidator(filename) |
441 | 447 | if flag is None: |
442 | 448 | secondaryReaders.append(reader) |
443 | 449 | elif flag: |
444 | 450 | primaryReaders.append(reader) |
445 | 451 | if not secondaryReaders and not primaryReaders: |
| 452 | + print('Available importers:') |
| 453 | + for reader in readerlist: |
| 454 | + print(f'\t{reader.longFormatName}') |
| 455 | + # common reason for read error -- package needed? |
| 456 | + l = [] |
| 457 | + for i in Readers['importErrpkgs']: |
| 458 | + for j in G2fil.condaRequestList[i]: |
| 459 | + if j not in l: l.append(j) |
| 460 | + if Readers['importErrpkgs']: |
| 461 | + print('The following importer(s) are not available:\n'+ |
| 462 | + f'\t{", ".join(Readers["importErrpkgs"])}') |
| 463 | + print('because the following optional Python package(s) are not installed:\n'+ |
| 464 | + f'\t{", ".join(l)}\n') |
| 465 | + if fmthint is not None and hintcount == 0: |
| 466 | + print(f'No readers matched hint {fmthint!r}\n') |
446 | 467 | raise G2ImportException(f"Could not read file: {filename}") |
447 | 468 |
|
448 | 469 | with open(filename, 'r'): |
|
0 commit comments