Skip to content

Commit a70bc27

Browse files
authored
Merge pull request #177 from stevenhua0320/deprecate-parser-display
chore: derepcate P_pdb method
2 parents 5ddd7b4 + c89466c commit a70bc27

File tree

12 files changed

+138
-149
lines changed

12 files changed

+138
-149
lines changed

news/deprecate-parser-display.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
**Added:**
2+
3+
* Added ``input_formats`` method in ``parsers/__init__.py``
4+
* Added ``output_formats`` method in ``parsers/__init__.py``
5+
* Added ``title_lines`` method in ``p_pdb.py``
6+
* Added ``cryst1_lines`` method in ``p_pdb.py``
7+
* Added ``atom_lines`` method in ``p_pdb.py``
8+
9+
**Changed:**
10+
11+
* <news item>
12+
13+
**Deprecated:**
14+
15+
* Deprecated ``inputFormats`` method in ``parsers/__init__.py`` for removal in version 4.0.0
16+
* Deprecated ``outputFormats`` method in ``parsers/__init__.py`` for removal in version 4.0.0
17+
* Deprecated ``titleLines`` method in ``p_pdb.py`` for removal in version 4.0.0
18+
* Deprecated ``crystl1Lines`` method in ``p_pdb.py`` for removal in version 4.0.0
19+
* Deprecated ``atomLines`` method in ``p_pdb.py`` for removal in version 4.0.0
20+
21+
**Removed:**
22+
23+
* <news item>
24+
25+
**Fixed:**
26+
27+
* <news item>
28+
29+
**Security:**
30+
31+
* <news item>

src/diffpy/structure/apps/anyeye.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def usage(style=None):
7272
if style == "brief":
7373
msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname
7474
else:
75-
from diffpy.structure.parsers import inputFormats
75+
from diffpy.structure.parsers import input_formats
7676

77-
fmts = [f for f in inputFormats() if f != "auto"]
77+
fmts = [f for f in input_formats() if f != "auto"]
7878
msg = msg.replace("inputFormats", " ".join(fmts))
7979
print(msg)
8080
return

src/diffpy/structure/apps/transtru.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def usage(style=None):
5252
if style == "brief":
5353
msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname
5454
else:
55-
from diffpy.structure.parsers import inputFormats, outputFormats
55+
from diffpy.structure.parsers import input_formats, output_formats
5656

57-
msg = msg.replace("inputFormats", " ".join(inputFormats()))
58-
msg = msg.replace("outputFormats", " ".join(outputFormats()))
57+
msg = msg.replace("inputFormats", " ".join(input_formats()))
58+
msg = msg.replace("outputFormats", " ".join(output_formats()))
5959
print(msg)
6060
return
6161

@@ -88,14 +88,14 @@ def main():
8888
usage("brief")
8989
sys.exit()
9090
# process arguments
91-
from diffpy.structure.parsers import inputFormats, outputFormats
91+
from diffpy.structure.parsers import input_formats, output_formats
9292

9393
try:
9494
infmt, outfmt = args[0].split("..", 1)
95-
if infmt not in inputFormats():
95+
if infmt not in input_formats():
9696
print("'%s' is not valid input format" % infmt, file=sys.stderr)
9797
sys.exit(2)
98-
if outfmt not in outputFormats():
98+
if outfmt not in output_formats():
9999
print("'%s' is not valid output format" % outfmt, file=sys.stderr)
100100
sys.exit(2)
101101
except ValueError:

src/diffpy/structure/parsers/__init__.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,26 @@
4646
"get_parser",
4747
removal_version,
4848
)
49+
inputFormats_deprecation_msg = build_deprecation_message(
50+
parsers_base,
51+
"inputFormats",
52+
"input_formats",
53+
removal_version,
54+
)
55+
outputFormats_deprecation_msg = build_deprecation_message(
56+
parsers_base,
57+
"outputFormats",
58+
"output_formats",
59+
removal_version,
60+
)
4961

5062

5163
@deprecated(getParser_deprecation_msg)
5264
def getParser(format, **kw):
53-
"""Return Parser instance for a given structure format.
54-
55-
Parameters
56-
----------
57-
format : str
58-
String with the format name, see `parser_index_mod`.
59-
**kw : dict
60-
Keyword arguments passed to the Parser init function.
65+
"""This function has been deprecated and will be removed in version
66+
4.0.0.
6167
62-
Returns
63-
-------
64-
Parser
65-
Parser instance for the given format.
66-
67-
Raises
68-
------
69-
StructureFormatError
70-
When the format is not defined.
68+
Please use diffpy.structure.get_parser instead.
7169
"""
7270
return get_parser(format, **kw)
7371

@@ -102,14 +100,34 @@ def get_parser(format, **kw):
102100
return ns["pm"].get_parser(**kw)
103101

104102

103+
@deprecated(inputFormats_deprecation_msg)
105104
def inputFormats():
105+
"""This function has been deprecated and will be removed in version
106+
4.0.0.
107+
108+
Please use diffpy.structure.input_formats instead.
109+
"""
110+
return input_formats()
111+
112+
113+
def input_formats():
106114
"""Return list of implemented input structure formats."""
107115
input_formats = [fmt for fmt, prop in parser_index.items() if prop["has_input"]]
108116
input_formats.sort()
109117
return input_formats
110118

111119

120+
@deprecated(outputFormats_deprecation_msg)
112121
def outputFormats():
122+
"""This function has been deprecated and will be removed in version
123+
4.0.0.
124+
125+
Please use diffpy.structure.output_formats instead.
126+
"""
127+
return output_formats()
128+
129+
130+
def output_formats():
113131
"""Return list of implemented output structure formats."""
114132
output_formats = [fmt for fmt, prop in parser_index.items() if prop["has_output"]]
115133
output_formats.sort()

src/diffpy/structure/parsers/p_auto.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def _get_ordered_formats(self):
7373
7474
This only works when `self.filename` has a known extension.
7575
"""
76-
from diffpy.structure.parsers import inputFormats
76+
from diffpy.structure.parsers import input_formats
7777

78-
ofmts = [fmt for fmt in inputFormats() if fmt != "auto"]
78+
ofmts = [fmt for fmt in input_formats() if fmt != "auto"]
7979
if not self.filename:
8080
return ofmts
8181
# filename is defined here
@@ -252,17 +252,10 @@ def _wrap_parse_method(self, method: object, *args: object, **kwargs: object) ->
252252

253253
@deprecated(getParser_deprecation_msg)
254254
def getParser(**kw):
255-
"""Return a new instance of the automatic parser.
256-
257-
Parameters
258-
----------
259-
**kw : dict
260-
Keyword arguments for the structure parser
255+
"""This function has been deprecated and will be removed in version
256+
4.0.0.
261257
262-
Returns
263-
-------
264-
P_auto
265-
Instance of `P_auto`.
258+
Please use diffpy.structure.P_auto.get_parser instead.
266259
"""
267260
return get_parser(**kw)
268261

src/diffpy/structure/parsers/p_cif.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -910,18 +910,10 @@ def getSymOp(s):
910910

911911
@deprecated(getParser_deprecation_msg)
912912
def getParser(eps=None):
913-
"""Return new `parser` object for CIF format.
913+
"""This function has been deprecated and will be removed in version
914+
4.0.0.
914915
915-
Parameters
916-
----------
917-
eps : float, Optional
918-
fractional coordinates cutoff for duplicate positions.
919-
When ``None`` use the default for `ExpandAsymmetricUnit`: ``1.0e-5``.
920-
921-
Returns
922-
-------
923-
P_cif
924-
Instance of `P_cif`.
916+
Please use diffpy.structure.P_cif.get_parser instead.
925917
"""
926918
return get_parser(eps)
927919

src/diffpy/structure/parsers/p_discus.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,10 @@ def _parse_not_implemented(self, words):
424424

425425
@deprecated(getParser_deprecation_msg)
426426
def getParser():
427-
"""Return new `parser` object for DISCUS format.
427+
"""This function has been deprecated and will be removed in version
428+
4.0.0.
428429
429-
Returns
430-
-------
431-
P_discus
432-
Instance of `P_discus`.
430+
Please use diffpy.structure.P_discus.get_parser instead.
433431
"""
434432
return get_parser()
435433

src/diffpy/structure/parsers/p_pdb.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545
"to_lines",
4646
removal_version,
4747
)
48+
titleLines_deprecation_msg = build_deprecation_message(
49+
base,
50+
"titleLines",
51+
"title_lines",
52+
removal_version,
53+
)
54+
cryst1Lines_deprecation_msg = build_deprecation_message(
55+
base,
56+
"cryst1Lines",
57+
"cryst1_lines",
58+
removal_version,
59+
)
60+
atomLines_deprecation_msg = build_deprecation_message(
61+
base,
62+
"atomLines",
63+
"atom_lines",
64+
removal_version,
65+
)
4866

4967

5068
class P_pdb(StructureParser):
@@ -269,7 +287,12 @@ def parse_lines(self, lines):
269287
raise e.with_traceback(exc_traceback)
270288
return stru
271289

290+
@deprecated(titleLines_deprecation_msg)
272291
def titleLines(self, stru):
292+
"""Build lines corresponding to `TITLE` record."""
293+
return self.title_lines(stru)
294+
295+
def title_lines(self, stru):
273296
"""Build lines corresponding to `TITLE` record."""
274297
lines = []
275298
title = stru.title
@@ -288,7 +311,12 @@ def titleLines(self, stru):
288311
title = title[stop:]
289312
return lines
290313

314+
@deprecated(cryst1Lines_deprecation_msg)
291315
def cryst1Lines(self, stru):
316+
"""Build lines corresponding to `CRYST1` record."""
317+
return self.cryst1_lines(stru)
318+
319+
def cryst1_lines(self, stru):
292320
"""Build lines corresponding to `CRYST1` record."""
293321
lines = []
294322
latpar = (
@@ -304,7 +332,13 @@ def cryst1Lines(self, stru):
304332
lines.append("%-80s" % line)
305333
return lines
306334

335+
@deprecated(atomLines_deprecation_msg)
307336
def atomLines(self, stru, idx):
337+
"""Build `ATOM` records and possibly `SIGATM`, `ANISOU` or
338+
`SIGUIJ` records for `structure` stru `atom` number aidx."""
339+
return self.atom_lines(stru, idx)
340+
341+
def atom_lines(self, stru, idx):
308342
"""Build `ATOM` records and possibly `SIGATM`, `ANISOU` or
309343
`SIGUIJ` records for `structure` stru `atom` number aidx."""
310344
lines = []
@@ -425,10 +459,10 @@ def to_lines(self, stru):
425459
List of lines in PDB format.
426460
"""
427461
lines = []
428-
lines.extend(self.titleLines(stru))
429-
lines.extend(self.cryst1Lines(stru))
462+
lines.extend(self.title_lines(stru))
463+
lines.extend(self.cryst1_lines(stru))
430464
for idx in range(len(stru)):
431-
lines.extend(self.atomLines(stru, idx))
465+
lines.extend(self.atom_lines(stru, idx))
432466
line = (
433467
"TER " # 1-6
434468
+ "%(serial)5i " # 7-11, 12-17

0 commit comments

Comments
 (0)