Skip to content

Commit

Permalink
fix: max line-length of 79
Browse files Browse the repository at this point in the history
  • Loading branch information
jandom committed Oct 8, 2023
1 parent ec16850 commit 6a5d52e
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ repos:
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
args: ["--profile", "black", "--line-length", "79"]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [--line-length=79]
4 changes: 3 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def sort_authors(filename):
html_favicon = "_static/logos/mdanalysis-logo.ico"
html_logo = "_static/logos/user_guide.png"

html_context = {"versions_json_url": "https://userguide.mdanalysis.org/versions.json"}
html_context = {
"versions_json_url": "https://userguide.mdanalysis.org/versions.json"
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
8 changes: 6 additions & 2 deletions doc/source/scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ def write_table(self):
@staticmethod
def sphinx_class(klass, tilde=True):
prefix = "~" if tilde else ""
return ":class:`{}{}.{}`".format(prefix, klass.__module__, klass.__name__)
return ":class:`{}{}.{}`".format(
prefix, klass.__module__, klass.__name__
)

@staticmethod
def sphinx_meth(meth, tilde=True):
prefix = "~" if tilde else ""
return ":meth:`{}{}.{}`".format(prefix, meth.__module__, meth.__qualname__)
return ":meth:`{}{}.{}`".format(
prefix, meth.__module__, meth.__qualname__
)

@staticmethod
def sphinx_ref(txt: str, label: str = None, suffix: str = "") -> str:
Expand Down
18 changes: 12 additions & 6 deletions doc/source/scripts/clean_example_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class JupyterCell:
time_fmt = "%b %d, %Y"
tag = "a"
close_tag = "</{}>".format(tag)
tagline = ('<{} data-cite="{{key}}" ' 'href="{{url}}">{{authors}}</{}>').format(
tag, tag
)
tagline = (
'<{} data-cite="{{key}}" ' 'href="{{url}}">{{authors}}</{}>'
).format(tag, tag)

@classmethod
def as_references(cls, refs, keys=[]):
Expand Down Expand Up @@ -171,7 +171,9 @@ def find_reference_keys(self, refs, keys=[]):
Track the order of the keys for a final bibliography cell.
"""
matches = [x for x in re.split(refs.regex, self.source) if x is not None]
matches = [
x for x in re.split(refs.regex, self.source) if x is not None
]
new_source = ""

while len(matches) > 1:
Expand All @@ -191,7 +193,9 @@ def find_reference_keys(self, refs, keys=[]):
elif prev_char in ('"', "'"):
new_source += before.rsplit("<", maxsplit=1)[0]
if len(matches) > 2:
matches[2] = matches[2].split(self.close_tag, maxsplit=1)[-1]
matches[2] = matches[2].split(self.close_tag, maxsplit=1)[
-1
]
tag = self.tagline.format(key=key, authors=authors, url=url)
new_source += tag
matches.pop(0)
Expand Down Expand Up @@ -322,7 +326,9 @@ def clean_all_notebooks(notebooks):
if len(errs):
errmsgs = ["{}: {}".format(nb, err) for nb, err in errs]
delim = "\n" + "===" * 10 + "\n"
raise ValueError("Notebooks have errors: {}".format(delim.join(errmsgs)))
raise ValueError(
"Notebooks have errors: {}".format(delim.join(errmsgs))
)


if __name__ == "__main__":
Expand Down
16 changes: 13 additions & 3 deletions doc/source/scripts/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,27 @@
for c in _TOPOLOGY_ATTRS.values()
}

base_attrnames = set(["atomattrs", "residueattrs", "segmentattrs", "topologyattrs"])
base_attrnames = set(
["atomattrs", "residueattrs", "segmentattrs", "topologyattrs"]
)

core_attrnames = set(["indices", "resindices", "segindices"])

BASE_ATTRS = {k: v for k, v in ATTRS.items() if k in base_attrnames}

NON_BASE_ATTRS = {k: v for k, v in ATTRS.items() if k not in base_attrnames}

NON_CORE_ATTRS = {k: v for k, v in NON_BASE_ATTRS.items() if k not in core_attrnames}
NON_CORE_ATTRS = {
k: v for k, v in NON_BASE_ATTRS.items() if k not in core_attrnames
}

TOPOLOGY_CLS = sorted(
set([x for x in _TOPOLOGY_ATTRS.values() if x.attrname in NON_CORE_ATTRS.keys()]),
set(
[
x
for x in _TOPOLOGY_ATTRS.values()
if x.attrname in NON_CORE_ATTRS.keys()
]
),
key=lambda x: x.attrname,
)
13 changes: 11 additions & 2 deletions doc/source/scripts/gen_format_overview_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ class FormatOverview(TableWriter):
filename = "formats/format_overview.txt"
include_table = "Table of all supported formats in MDAnalysis"
preprocess = ["keys"]
headings = ["File type", "Description", "Topology", "Coordinates", "Read", "Write"]
headings = [
"File type",
"Description",
"Topology",
"Coordinates",
"Read",
"Write",
]

def _set_up_input(self):
return sorted_types
Expand Down Expand Up @@ -80,7 +87,9 @@ def _write(self, fmt, handlers):

class CoordinateReaders(FormatOverview):
filename = "formats/coordinate_readers.txt"
include_table = "Table of supported coordinate readers and the information read"
include_table = (
"Table of supported coordinate readers and the information read"
)
headings = ["File type", "Description", "Velocities", "Forces"]

def _set_up_input(self):
Expand Down
12 changes: 9 additions & 3 deletions doc/source/scripts/gen_standard_selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def get_lines(self, klass, attr, sort=False, n=8):

if __name__ == "__main__":
StandardSelectionTable("protein", sel.ProteinSelection, "prot_res", True)
StandardSelectionTable("protein_backbone", sel.BackboneSelection, "bb_atoms")
StandardSelectionTable(
"protein_backbone", sel.BackboneSelection, "bb_atoms"
)
StandardSelectionTable("nucleic", sel.NucleicSelection, "nucl_res")
StandardSelectionTable("nucleic_backbone", sel.NucleicBackboneSelection, "bb_atoms")
StandardSelectionTable(
"nucleic_backbone", sel.NucleicBackboneSelection, "bb_atoms"
)
StandardSelectionTable("base", sel.BaseSelection, "base_atoms")
StandardSelectionTable("nucleic_sugar", sel.NucleicSugarSelection, "sug_atoms")
StandardSelectionTable(
"nucleic_sugar", sel.NucleicSugarSelection, "sug_atoms"
)
15 changes: 12 additions & 3 deletions doc/source/scripts/gen_topologyparser_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@


class TopologyParsers(TableWriter):
headings = ["Format", "Description", "Attributes read", "Attributes guessed"]
headings = [
"Format",
"Description",
"Attributes read",
"Attributes guessed",
]
preprocess = ["keys"]
filename = "formats/topology_parsers.txt"
include_table = "Table of supported topology parsers and the attributes read"
include_table = (
"Table of supported topology parsers and the attributes read"
)
sort = True

def __init__(self):
Expand Down Expand Up @@ -133,7 +140,9 @@ def __init__(self, attrs):

def _set_up_input(self):
return sorted(
[x, *y] for x, y in NON_CORE_ATTRS.items() if x not in MANDATORY_ATTRS
[x, *y]
for x, y in NON_CORE_ATTRS.items()
if x not in MANDATORY_ATTRS
)

def _atom(self, name, singular, *args):
Expand Down
3 changes: 2 additions & 1 deletion doc/source/scripts/gen_unit_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def write_unit_table(filename):
f.write("\n\n")
f.write(
textwrap.indent(
tabulate.tabulate(lines, headers=headings, tablefmt="rst"), " "
tabulate.tabulate(lines, headers=headings, tablefmt="rst"),
" ",
)
)
f.write("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

def test_StandardSelectionTable_protein(snapshot):
with patch("builtins.open"):
ss = StandardSelectionTable("protein", sel.ProteinSelection, "prot_res", True)
ss = StandardSelectionTable(
"protein", sel.ProteinSelection, "prot_res", True
)
assert ss.lines == snapshot


Expand All @@ -20,7 +22,9 @@ def test_StandardSelectionTable_protein_backbone(snapshot):

def test_StandardSelectionTable_nucleic(snapshot):
with patch("builtins.open"):
ss = StandardSelectionTable("nucleic", sel.NucleicSelection, "nucl_res", True)
ss = StandardSelectionTable(
"nucleic", sel.NucleicSelection, "nucl_res", True
)
assert ss.lines == snapshot


Expand All @@ -34,7 +38,9 @@ def test_StandardSelectionTable_nucleic_backbone(snapshot):

def test_StandardSelectionTable_base(snapshot):
with patch("builtins.open"):
ss = StandardSelectionTable("base", sel.BaseSelection, "base_atoms", True)
ss = StandardSelectionTable(
"base", sel.BaseSelection, "base_atoms", True
)
assert ss.lines == snapshot


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from unittest.mock import patch

from gen_topologyparser_attrs import ConnectivityAttrs, TopologyAttrs, TopologyParsers
from gen_topologyparser_attrs import (
ConnectivityAttrs,
TopologyAttrs,
TopologyParsers,
)
from MDAnalysis.core import selection as sel


Expand Down
4 changes: 3 additions & 1 deletion doc/source/scripts/tests/snapshot/test_gen_unit_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def test_write_unit_table(snapshot):
with patch.object(Path, "open", mock_open()) as mock_open_file:
write_unit_table(filename=Path())

lines = [args[0] for args in mock_open_file.return_value.write.call_args_list]
lines = [
args[0] for args in mock_open_file.return_value.write.call_args_list
]
# Exclude the first line, because it contains "Generated by /home/username/..."
assert lines[1:] == snapshot

0 comments on commit 6a5d52e

Please sign in to comment.