@@ -114,3 +114,36 @@ def pick_csv(filename, directory=None):
114
114
return file_path + '.csv'
115
115
# Couldn't find a suitable CSV file
116
116
return None
117
+
118
+
119
+ def pick_smi (filename , directory = None ):
120
+ """Returns a full path to the chosen SMI file. The supplied file
121
+ is not expected to contain a recognised SMI extension, this is added
122
+ automatically.
123
+ If a file with the extension `.smi.gz` or `.smi` is found the path to it
124
+ (excluding the extension) is returned. If this fails, `None` is returned.
125
+
126
+ :param filename: The SMI file basename, whose path is required.
127
+ :type filename: ``str``
128
+ :param directory: An optional directory.
129
+ If not provided it is calculated automatically.
130
+ :type directory: ``str``
131
+ :return: The full path to the file without extension,
132
+ or None if it does not exist
133
+ :rtype: ``str``
134
+ """
135
+ if directory is None :
136
+ directory = utils .get_undecorated_calling_module ()
137
+ # If the 'cwd' is not '/output' (which indicates we're in a Container)
138
+ # then remove the CWD and the anticipated '/'
139
+ # from the front of the module
140
+ if os .getcwd () not in ['/output' ]:
141
+ directory = directory [len (os .getcwd ()) + 1 :]
142
+
143
+ file_path = os .path .join (directory , filename )
144
+ if os .path .isfile (file_path + '.smi.gz' ):
145
+ return file_path + '.smi.gz'
146
+ elif os .path .isfile (file_path + '.smi' ):
147
+ return file_path + '.smi'
148
+ # Couldn't find a suitable SMI file
149
+ return None
0 commit comments