Skip to content

Commit 5eef341

Browse files
authored
[fmt] core (#4874)
1 parent 1eca9f2 commit 5eef341

32 files changed

+5822
-4143
lines changed

package/MDAnalysis/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
and write your own Python code.
5151
"""
5252

53-
__all__ = ['AtomGroup', 'Selection']
53+
__all__ = ["AtomGroup", "Selection"]
5454

5555
from .groups import AtomGroup
5656
from .selection import Selection

package/MDAnalysis/core/_get_readers.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222
import copy
2323
import inspect
2424

25-
from .. import (_READERS, _READER_HINTS,
26-
_PARSERS, _PARSER_HINTS,
27-
_MULTIFRAME_WRITERS, _SINGLEFRAME_WRITERS, _CONVERTERS)
25+
from .. import (
26+
_READERS,
27+
_READER_HINTS,
28+
_PARSERS,
29+
_PARSER_HINTS,
30+
_MULTIFRAME_WRITERS,
31+
_SINGLEFRAME_WRITERS,
32+
_CONVERTERS,
33+
)
2834
from ..lib import util
2935

3036

@@ -80,8 +86,8 @@ def get_reader_for(filename, format=None):
8086
return format
8187

8288
# ChainReader gets returned even if format is specified
83-
if _READER_HINTS['CHAIN'](filename):
84-
format = 'CHAIN'
89+
if _READER_HINTS["CHAIN"](filename):
90+
format = "CHAIN"
8591
# Only guess if format is not specified
8692
if format is None:
8793
for fmt_name, test in _READER_HINTS.items():
@@ -103,7 +109,9 @@ def get_reader_for(filename, format=None):
103109
" Use the format keyword to explicitly set the format: 'Universe(...,format=FORMAT)'\n"
104110
" For missing formats, raise an issue at "
105111
"https://github.com/MDAnalysis/mdanalysis/issues".format(
106-
format, filename, _READERS.keys()))
112+
format, filename, _READERS.keys()
113+
)
114+
)
107115
raise ValueError(errmsg) from None
108116

109117

@@ -158,7 +166,7 @@ def get_writer_for(filename, format=None, multiframe=None):
158166
The `filename` argument has been made mandatory.
159167
"""
160168
if filename is None:
161-
format = 'NULL'
169+
format = "NULL"
162170
elif format is None:
163171
try:
164172
root, ext = util.get_ext(filename)
@@ -172,18 +180,24 @@ def get_writer_for(filename, format=None, multiframe=None):
172180
else:
173181
format = util.check_compressed_format(root, ext)
174182

175-
if format == '':
176-
raise ValueError((
177-
'File format could not be guessed from {}, '
178-
'resulting in empty string - '
179-
'only None or valid formats are supported.'
180-
).format(filename))
183+
if format == "":
184+
raise ValueError(
185+
(
186+
"File format could not be guessed from {}, "
187+
"resulting in empty string - "
188+
"only None or valid formats are supported."
189+
).format(filename)
190+
)
181191

182192
format = format.upper()
183193
if multiframe is None:
184194
# Multiframe takes priority, else use singleframe
185-
options = copy.copy(_SINGLEFRAME_WRITERS) # do copy to avoid changing in place
186-
options.update(_MULTIFRAME_WRITERS) # update overwrites existing entries
195+
options = copy.copy(
196+
_SINGLEFRAME_WRITERS
197+
) # do copy to avoid changing in place
198+
options.update(
199+
_MULTIFRAME_WRITERS
200+
) # update overwrites existing entries
187201
errmsg = "No trajectory or frame writer for format '{0}'"
188202
elif multiframe is True:
189203
options = _MULTIFRAME_WRITERS
@@ -192,9 +206,11 @@ def get_writer_for(filename, format=None, multiframe=None):
192206
options = _SINGLEFRAME_WRITERS
193207
errmsg = "No single frame writer for format '{0}'"
194208
else:
195-
raise ValueError("Unknown value '{0}' for multiframe,"
196-
" only True, False, None allowed"
197-
"".format(multiframe))
209+
raise ValueError(
210+
"Unknown value '{0}' for multiframe,"
211+
" only True, False, None allowed"
212+
"".format(multiframe)
213+
)
198214

199215
try:
200216
return options[format]
@@ -252,10 +268,13 @@ def get_parser_for(filename, format=None):
252268
" See https://docs.mdanalysis.org/documentation_pages/topology/init.html#supported-topology-formats\n"
253269
" For missing formats, raise an issue at \n"
254270
" https://github.com/MDAnalysis/mdanalysis/issues".format(
255-
format, _PARSERS.keys()))
271+
format, _PARSERS.keys()
272+
)
273+
)
256274
raise ValueError(errmsg) from None
257275
else:
258-
return _PARSERS['MINIMAL']
276+
return _PARSERS["MINIMAL"]
277+
259278

260279
def get_converter_for(format):
261280
"""Return the appropriate topology converter for ``format``.
@@ -276,6 +295,6 @@ def get_converter_for(format):
276295
try:
277296
writer = _CONVERTERS[format]
278297
except KeyError:
279-
errmsg = f'No converter found for {format} format'
298+
errmsg = f"No converter found for {format} format"
280299
raise TypeError(errmsg) from None
281300
return writer

package/MDAnalysis/core/accessors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class ConverterWrapper:
168168
be accessed as a method with the name of the package in lowercase, i.e.
169169
`convert_to.parmed()`
170170
"""
171+
171172
_CONVERTERS = {}
172173

173174
def __init__(self, ag):
@@ -199,6 +200,8 @@ def __call__(self, package, *args, **kwargs):
199200
try:
200201
convert = getattr(self, package.lower())
201202
except AttributeError:
202-
raise ValueError(f"No {package!r} converter found. Available: "
203-
f"{' '.join(self._CONVERTERS.keys())}") from None
203+
raise ValueError(
204+
f"No {package!r} converter found. Available: "
205+
f"{' '.join(self._CONVERTERS.keys())}"
206+
) from None
204207
return convert(*args, **kwargs)

0 commit comments

Comments
 (0)