5252import sys
5353
5454from diffpy .structure .structureerrors import StructureFormatError
55+ from diffpy .utils ._deprecator import build_deprecation_message , deprecated
56+
57+ base = "diffpy.structure"
58+ removal_version = "4.0.0"
59+ loadStructureFile_deprecation_msg = build_deprecation_message (
60+ base ,
61+ "loadStructureFile" ,
62+ "load_structure_file" ,
63+ removal_version ,
64+ )
65+ convertStructureFile_deprecation_msg = build_deprecation_message (
66+ base ,
67+ "loadStructureFile" ,
68+ "load_structure_file" ,
69+ removal_version ,
70+ )
71+ watchStructureFile_deprecation_msg = build_deprecation_message (
72+ base ,
73+ "watchStructureFile" ,
74+ "watch_structure_file" ,
75+ removal_version ,
76+ )
77+ cleanUp_deprecation_msg = build_deprecation_message (
78+ base ,
79+ "cleanUp" ,
80+ "clean_up" ,
81+ removal_version ,
82+ )
83+ parseFormula_deprecation_msg = build_deprecation_message (
84+ base ,
85+ "parseFormula" ,
86+ "parse_formula" ,
87+ removal_version ,
88+ )
89+ signalHandler_deprecation_msg = build_deprecation_message (
90+ base ,
91+ "signalHandler" ,
92+ "signal_handler" ,
93+ removal_version ,
94+ )
5595
5696# parameter dictionary
5797pd = {
@@ -87,9 +127,28 @@ def version():
87127 return
88128
89129
130+ @deprecated (loadStructureFile_deprecation_msg )
90131def loadStructureFile (filename , format = "auto" ):
91132 """Load structure from specified file.
92133
134+ Parameters
135+ ----------
136+ filename : str
137+ Path to the structure file.
138+ format : str, Optional
139+ File format, by default "auto".
140+
141+ Returns
142+ -------
143+ tuple
144+ A tuple of (Structure, fileformat).
145+ """
146+ return load_structure_file (filename , format )
147+
148+
149+ def load_structure_file (filename , format = "auto" ):
150+ """Load structure from specified file.
151+
93152 Parameters
94153 ----------
95154 filename : str
@@ -110,7 +169,12 @@ def loadStructureFile(filename, format="auto"):
110169 return (stru , fileformat )
111170
112171
172+ @deprecated (convertStructureFile_deprecation_msg )
113173def convertStructureFile (pd ):
174+ return convert_structure_file (pd )
175+
176+
177+ def convert_structure_file (pd ):
114178 # make temporary directory on the first pass
115179 if "tmpdir" not in pd :
116180 from tempfile import mkdtemp
@@ -134,7 +198,7 @@ def convertStructureFile(pd):
134198 return
135199 # otherwise convert to the first recognized viewer format
136200 if stru is None :
137- stru = loadStructureFile (strufile , fmt )[0 ]
201+ stru = load_structure_file (strufile , fmt )[0 ]
138202 if pd ["formula" ]:
139203 formula = pd ["formula" ]
140204 if len (formula ) != len (stru ):
@@ -154,19 +218,29 @@ def convertStructureFile(pd):
154218 return
155219
156220
221+ @deprecated (watchStructureFile_deprecation_msg )
157222def watchStructureFile (pd ):
223+ return watch_structure_file (pd )
224+
225+
226+ def watch_structure_file (pd ):
158227 from time import sleep
159228
160229 strufile = pd ["strufile" ]
161230 tmpfile = pd ["tmpfile" ]
162231 while pd ["watch" ]:
163232 if os .path .getmtime (tmpfile ) < os .path .getmtime (strufile ):
164- convertStructureFile (pd )
233+ convert_structure_file (pd )
165234 sleep (1 )
166235 return
167236
168237
238+ @deprecated (cleanUp_deprecation_msg )
169239def cleanUp (pd ):
240+ return clean_up (pd )
241+
242+
243+ def clean_up (pd ):
170244 if "tmpfile" in pd :
171245 os .remove (pd ["tmpfile" ])
172246 del pd ["tmpfile" ]
@@ -176,7 +250,14 @@ def cleanUp(pd):
176250 return
177251
178252
253+ @deprecated (parseFormula_deprecation_msg )
179254def parseFormula (formula ):
255+ """Parse chemical formula and return a list of elements."""
256+ # remove all blanks
257+ return parse_formula (formula )
258+
259+
260+ def parse_formula (formula ):
180261 """Parse chemical formula and return a list of elements."""
181262 # remove all blanks
182263 formula = re .sub (r"\s" , "" , formula )
@@ -197,11 +278,17 @@ def parseFormula(formula):
197278
198279
199280def die (exit_status = 0 , pd = {}):
200- cleanUp (pd )
281+ clean_up (pd )
201282 sys .exit (exit_status )
202283
203284
285+ @deprecated (signalHandler_deprecation_msg )
204286def signalHandler (signum , stackframe ):
287+ # revert to default handler
288+ return signal_handler (signum , stackframe )
289+
290+
291+ def signal_handler (signum , stackframe ):
205292 # revert to default handler
206293 signal .signal (signum , signal .SIG_DFL )
207294 if signum == signal .SIGCHLD :
@@ -231,7 +318,7 @@ def main():
231318 for o , a in opts :
232319 if o in ("-f" , "--formula" ):
233320 try :
234- pd ["formula" ] = parseFormula (a )
321+ pd ["formula" ] = parse_formula (a )
235322 except RuntimeError as msg :
236323 print (msg , file = sys .stderr )
237324 die (2 )
@@ -255,23 +342,23 @@ def main():
255342 die (2 )
256343 pd ["strufile" ] = args [0 ]
257344 # trap the following signals
258- signal .signal (signal .SIGHUP , signalHandler )
259- signal .signal (signal .SIGQUIT , signalHandler )
260- signal .signal (signal .SIGSEGV , signalHandler )
261- signal .signal (signal .SIGTERM , signalHandler )
262- signal .signal (signal .SIGINT , signalHandler )
345+ signal .signal (signal .SIGHUP , signal_handler )
346+ signal .signal (signal .SIGQUIT , signal_handler )
347+ signal .signal (signal .SIGSEGV , signal_handler )
348+ signal .signal (signal .SIGTERM , signal_handler )
349+ signal .signal (signal .SIGINT , signal_handler )
263350 env = os .environ .copy ()
264351 if os .path .basename (pd ["viewer" ]).startswith ("atomeye" ):
265352 env ["XLIB_SKIP_ARGB_VISUALS" ] = "1"
266353 # try to run the thing:
267354 try :
268- convertStructureFile (pd )
355+ convert_structure_file (pd )
269356 spawnargs = (pd ["viewer" ], pd ["viewer" ], pd ["tmpfile" ], env )
270357 # load strufile in atomeye
271358 if pd ["watch" ]:
272- signal .signal (signal .SIGCHLD , signalHandler )
359+ signal .signal (signal .SIGCHLD , signal_handler )
273360 os .spawnlpe (os .P_NOWAIT , * spawnargs )
274- watchStructureFile (pd )
361+ watch_structure_file (pd )
275362 else :
276363 status = os .spawnlpe (os .P_WAIT , * spawnargs )
277364 die (status , pd )
0 commit comments