Skip to content

Commit e3e25e3

Browse files
committed
fail gracefully with a bad user im-/exporter; improve docs slightly
1 parent 6ff18b6 commit e3e25e3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

GSASII/GSASIIfiles.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ def LoadImportRoutines(prefix, errprefix=None, traceback=False):
636636
reader.longFormatName = '(user supplied) ' + reader.longFormatName
637637
if reader.UseReader:
638638
readerlist.append(reader)
639-
except ImportError as msg:
640-
print(f'Failed to import importer {f} with error\n{msg}')
639+
except Exception as msg:
640+
G2Print(f'\nImporter init: error with importer file {f!r}')
641+
G2Print ('Error message: {}\n'.format(msg))
641642
return readerlist
642643

643644
def LoadExportRoutines(parent, usetraceback=False):
@@ -694,7 +695,7 @@ def LoadExportRoutines(parent, usetraceback=False):
694695
# not sure if I want to do this or not
695696
sys.modules[f"GSASII.userexports.{nam}"] = module
696697
except Exception as exc:
697-
G2Print (f'\nExport init: Error with file {f}')
698+
G2Print (f'\nExport init: Error with exporter file {f!r}')
698699
G2Print ('Error message: {}\n'.format(exc))
699700
if usetraceback:
700701
import traceback

docs/source/exports.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ be written.
2525
A file containing one or more export routine can be placed
2626
either in the ``GSASII/exports`` directory (which requires
2727
modification of the ``__init__.py`` file or the file can be placed in
28-
the ``~/.GSASII/exports`` directory.
28+
the ``~/.GSASII/exports`` directory.
29+
(Note that ``~`` here is translated to the
30+
user's home directory; for Windows this is usually taken from the
31+
USERPROFILE setting or a combination of HOMEPATH and HOMEDRIVE,
32+
so this directory will usually have form
33+
``C:\\Users\\YourUsername\\.GSASII\\exports``.
2934
The next time GSAS-II is started,
30-
the file will loaded when the GSAS-II files are read by the Python and
35+
the file will be loaded with all the other GSAS-II files and
3136
the new data format will appear in the appropriate exporter menu.
3237

3338
.. _export_routines:

docs/source/imports.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ named with the appropriate file name prefix:
4141
This file can be placed
4242
either in the ``GSASII/imports`` directory (which requires
4343
modification of the ``__init__.py`` file or the file can be placed in
44-
the ``~/.GSASII/imports`` directory. The importer file may contain a
45-
single import class or several.
44+
the ``~/.GSASII/imports`` directory.
45+
(Note that ``~`` here is translated to the
46+
user's home directory; for Windows this is usually taken from the
47+
USERPROFILE setting or a combination of HOMEPATH and HOMEDRIVE,
48+
so this directory will usually have form
49+
``C:\\Users\\YourUsername\\.GSASII\\imports``.
4650
The next time GSAS-II is started,
47-
the file will loaded when the GSAS-II files are read by the Python and
51+
the file will be loaded with all the other GSAS-II files and
4852
the new data format(s) will appear in the appropriate importer menu.
53+
The importer file may contain a
54+
single importer class or several.
4955

5056
Importers are documented below, separated by type. Importers tend to
5157
be fairly simple files, where many are in the range of 50-100 lines,

0 commit comments

Comments
 (0)