Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fmt] core #4874

Merged
merged 11 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package/MDAnalysis/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
and write your own Python code.
"""

__all__ = ['AtomGroup', 'Selection']
__all__ = ["AtomGroup", "Selection"]

from .groups import AtomGroup
from .selection import Selection
61 changes: 40 additions & 21 deletions package/MDAnalysis/core/_get_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
import copy
import inspect

from .. import (_READERS, _READER_HINTS,
_PARSERS, _PARSER_HINTS,
_MULTIFRAME_WRITERS, _SINGLEFRAME_WRITERS, _CONVERTERS)
from .. import (
_READERS,
_READER_HINTS,
_PARSERS,
_PARSER_HINTS,
_MULTIFRAME_WRITERS,
_SINGLEFRAME_WRITERS,
_CONVERTERS,
)
from ..lib import util


Expand Down Expand Up @@ -80,8 +86,8 @@
return format

# ChainReader gets returned even if format is specified
if _READER_HINTS['CHAIN'](filename):
format = 'CHAIN'
if _READER_HINTS["CHAIN"](filename):
format = "CHAIN"
# Only guess if format is not specified
if format is None:
for fmt_name, test in _READER_HINTS.items():
Expand All @@ -103,7 +109,9 @@
" Use the format keyword to explicitly set the format: 'Universe(...,format=FORMAT)'\n"
" For missing formats, raise an issue at "
"https://github.com/MDAnalysis/mdanalysis/issues".format(
format, filename, _READERS.keys()))
format, filename, _READERS.keys()
)
)
raise ValueError(errmsg) from None


Expand Down Expand Up @@ -158,7 +166,7 @@
The `filename` argument has been made mandatory.
"""
if filename is None:
format = 'NULL'
format = "NULL"
elif format is None:
try:
root, ext = util.get_ext(filename)
Expand All @@ -172,18 +180,24 @@
else:
format = util.check_compressed_format(root, ext)

if format == '':
raise ValueError((
'File format could not be guessed from {}, '
'resulting in empty string - '
'only None or valid formats are supported.'
).format(filename))
if format == "":
raise ValueError(
(
"File format could not be guessed from {}, "
"resulting in empty string - "
"only None or valid formats are supported."
).format(filename)
)

format = format.upper()
if multiframe is None:
# Multiframe takes priority, else use singleframe
options = copy.copy(_SINGLEFRAME_WRITERS) # do copy to avoid changing in place
options.update(_MULTIFRAME_WRITERS) # update overwrites existing entries
options = copy.copy(
_SINGLEFRAME_WRITERS
) # do copy to avoid changing in place
options.update(
_MULTIFRAME_WRITERS
) # update overwrites existing entries
errmsg = "No trajectory or frame writer for format '{0}'"
elif multiframe is True:
options = _MULTIFRAME_WRITERS
Expand All @@ -192,9 +206,11 @@
options = _SINGLEFRAME_WRITERS
errmsg = "No single frame writer for format '{0}'"
else:
raise ValueError("Unknown value '{0}' for multiframe,"
" only True, False, None allowed"
"".format(multiframe))
raise ValueError(
"Unknown value '{0}' for multiframe,"
" only True, False, None allowed"
"".format(multiframe)
)

try:
return options[format]
Expand Down Expand Up @@ -252,10 +268,13 @@
" See https://docs.mdanalysis.org/documentation_pages/topology/init.html#supported-topology-formats\n"
" For missing formats, raise an issue at \n"
" https://github.com/MDAnalysis/mdanalysis/issues".format(
format, _PARSERS.keys()))
format, _PARSERS.keys()
)
)
raise ValueError(errmsg) from None
else:
return _PARSERS['MINIMAL']
return _PARSERS["MINIMAL"]


def get_converter_for(format):
"""Return the appropriate topology converter for ``format``.
Expand All @@ -276,6 +295,6 @@
try:
writer = _CONVERTERS[format]
except KeyError:
errmsg = f'No converter found for {format} format'
errmsg = f"No converter found for {format} format"

Check warning on line 298 in package/MDAnalysis/core/_get_readers.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/core/_get_readers.py#L298

Added line #L298 was not covered by tests
raise TypeError(errmsg) from None
return writer
7 changes: 5 additions & 2 deletions package/MDAnalysis/core/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ConverterWrapper:
be accessed as a method with the name of the package in lowercase, i.e.
`convert_to.parmed()`
"""

_CONVERTERS = {}

def __init__(self, ag):
Expand Down Expand Up @@ -199,6 +200,8 @@ def __call__(self, package, *args, **kwargs):
try:
convert = getattr(self, package.lower())
except AttributeError:
raise ValueError(f"No {package!r} converter found. Available: "
f"{' '.join(self._CONVERTERS.keys())}") from None
raise ValueError(
f"No {package!r} converter found. Available: "
f"{' '.join(self._CONVERTERS.keys())}"
) from None
return convert(*args, **kwargs)
Loading
Loading