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

Ruff format #314

Merged
merged 4 commits into from
May 22, 2024
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
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: 'iodata/test/data/.*'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -26,6 +26,10 @@ repos:
hooks:
- id: remove-crlf
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.1
rev: 0.28.3
hooks:
- id: check-github-workflows
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff-format
122 changes: 61 additions & 61 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# pylint: disable=unused-argument,redefined-builtin
"""Sphinxdoc configuration file."""


import os
import subprocess

Expand All @@ -30,23 +29,23 @@
# An in-place build can also work, provided the necessary environment variables
# are set accordingly.

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if on_rtd:
subprocess.run(['python', '-m', 'pip', 'install', '..'], check=True)
subprocess.run(['./gen_docs.sh'], shell=True, check=True)
subprocess.run(["python", "-m", "pip", "install", ".."], check=True)
subprocess.run(["./gen_docs.sh"], shell=True, check=True)

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
}

Expand All @@ -62,42 +61,42 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
]


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'IOData'
copyright = '2019, The IODATA Development Team'
author = 'The IODATA Development Team'
project = "IOData"
copyright = "2019, The IODATA Development Team"
author = "The IODATA Development Team"

# The version info for the project yo're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ''
version = ""
# The full version, including alpha/beta/rc tags.
release = ''
release = ""

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -109,10 +108,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -122,7 +121,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -133,30 +132,27 @@
# 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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_style = 'css/override.css'
html_static_path = ["_static"]
html_style = "css/override.css"


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'IODatadoc'
htmlhelp_basename = "IODatadoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -166,28 +162,30 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'IOData.tex', 'IOData Documentation',
'The HORTON Developers', 'manual'),
(master_doc, "IOData.tex", "IOData Documentation", "The HORTON Developers", "manual"),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'iodata', 'IOData Documentation',
[author], 1)
]
man_pages = [(master_doc, "iodata", "IOData Documentation", [author], 1)]

# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'IOData', 'IOData Documentation',
author, 'IOData', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"IOData",
"IOData Documentation",
author,
"IOData",
"One line description of project.",
"Miscellaneous",
),
]

# -- Options for Epub output ----------------------------------------------
Expand All @@ -208,20 +206,20 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}


# -- Configuration for autodoc extensions ---------------------------------

autodoc_default_options = {
'undoc-members': True,
'show-inheritance': True,
'members': None,
'inherited-members': True,
'ignore-module-all': True,
"undoc-members": True,
"show-inheritance": True,
"members": None,
"inherited-members": True,
"ignore-module-all": True,
}


Expand All @@ -243,22 +241,24 @@ def setup(app):
# -- Configuration of mathjax extension -----------------------------------

mathjax_config = {
'extensions': ['fast-preview.js'],
"extensions": ["fast-preview.js"],
# TeX: {
# Macros: {
# RR: '{\\bf R}',
# bold: ['{\\bf #1}', 1]
# }
# }
'TeX': {
'Macros': {
'ket': ["{\\left\\vert { #1 } \\right\\rangle}", 1],
'bra': ["{\\left\\langle { #1} \\right\\vert}", 1],
'braket': ["{\\left\\langle {#1} \\mid { #2} \\right\\rangle}", 2],
'ketbra': ["{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}",
2],
'ev': ["{\\left\\langle {#2} \\vert {#1} \\vert {#2} \\right\\rangle}", 2],
'mel': ["{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}", 3]
"TeX": {
"Macros": {
"ket": ["{\\left\\vert { #1 } \\right\\rangle}", 1],
"bra": ["{\\left\\langle { #1} \\right\\vert}", 1],
"braket": ["{\\left\\langle {#1} \\mid { #2} \\right\\rangle}", 2],
"ketbra": [
"{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}",
2,
],
"ev": ["{\\left\\langle {#2} \\vert {#1} \\vert {#2} \\right\\rangle}", 2],
"mel": ["{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}", 3],
}
},
}
8 changes: 4 additions & 4 deletions doc/gen_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


def _format_words(words):
return ', '.join('``{}``'.format(word) for word in words)
return ", ".join("``{}``".format(word) for word in words)


def _print_section(title, linechar):
Expand All @@ -61,11 +61,11 @@ def main():
break
if skip:
continue
lines = module.__doc__.split('\n')
lines = module.__doc__.split("\n")
# add labels for cross-referencing format (e.g. in formats table)
print(f".. _format_{modname}:")
print()
_print_section('{} (``{}``)'.format(lines[0][:-1], modname), "=")
_print_section("{} (``{}``)".format(lines[0][:-1], modname), "=")
print()
for line in lines[2:]:
print(line)
Expand Down Expand Up @@ -95,5 +95,5 @@ def main():
print()


if __name__ == '__main__':
if __name__ == "__main__":
main()
13 changes: 5 additions & 8 deletions doc/gen_formats_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# pylint: disable=unused-argument,redefined-builtin
"""Generate formats.rst."""


from collections import defaultdict
import inspect

Expand Down Expand Up @@ -86,13 +85,12 @@ def generate_table_rst():
table with rows of each property and columns of each format

"""
fmt_names, has_load, guaranteed, ifpresent, has_dump, required, optional = \
fmt_names, has_load, guaranteed, ifpresent, has_dump, required, optional = (
_generate_all_format_parser()
)

# Sort rows by number of times the attribute is used in decreasing order.
rows = sorted(
attr_name for attr_name in dir(iodata.IOData)
if not attr_name.startswith('_'))
rows = sorted(attr_name for attr_name in dir(iodata.IOData) if not attr_name.startswith("_"))

# Order columns based on number of guaranteed and ifpresent entries for each format.
# Also keep track of which format has a load_one and dump_one function.
Expand All @@ -106,10 +104,9 @@ def generate_table_rst():
# Construct header with cross-referencing columns.
header = ["Attribute"]
for fmt_name in cols:
col_name = f':ref:`{fmt_name} <format_{fmt_name}>`'
col_name = f":ref:`{fmt_name} <format_{fmt_name}>`"
col_name += ": {}{}".format(
"L" if fmt_name in has_load else "",
"D" if fmt_name in has_dump else ""
"L" if fmt_name in has_load else "", "D" if fmt_name in has_dump else ""
)
header.append(col_name)
table = [header]
Expand Down
7 changes: 3 additions & 4 deletions doc/gen_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# pylint: disable=unused-argument,redefined-builtin
"""Generate formats.rst."""


from gen_formats import _format_words, _print_section
from iodata.api import INPUT_MODULES

Expand Down Expand Up @@ -54,11 +53,11 @@ def main():
for modname, module in sorted(INPUT_MODULES.items()):
if not hasattr(module, "write_input"):
continue
lines = module.__doc__.split('\n')
lines = module.__doc__.split("\n")
# add labels for cross-referencing format (e.g. in formats table)
print(f".. _input_{modname}:")
print()
_print_section('{} (``{}``)'.format(lines[0][:-1], modname), "=")
_print_section("{} (``{}``)".format(lines[0][:-1], modname), "=")
print()
for line in lines[2:]:
print(line)
Expand All @@ -82,5 +81,5 @@ def main():
print()


if __name__ == '__main__':
if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion iodata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# --
"""Input and Output Module."""


try:
from ._version import __version__
except ImportError:
Expand Down
Loading
Loading