Skip to content

Commit

Permalink
Merge pull request #317 from glotzerlab/ruff
Browse files Browse the repository at this point in the history
Switch from flake8/yapf to ruff
  • Loading branch information
joaander authored Jan 22, 2024
2 parents af0a923 + 774a26f commit 9d7153d
Show file tree
Hide file tree
Showing 19 changed files with 1,383 additions and 1,151 deletions.
18 changes: 4 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,11 @@ repos:
- --add=Part of GSD, released under the BSD 2-Clause License.
- --keep-after=.. include
- --comment-prefix=..
- repo: https://github.com/google/yapf
rev: 'v0.40.2'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.13'
hooks:
- id: yapf
additional_dependencies:
- toml==0.10.2
- repo: https://github.com/PyCQA/flake8
rev: '6.1.0'
hooks:
- id: flake8
additional_dependencies:
- pep8-naming==0.13.3
- pydocstyle==6.2.3
- flake8-docstrings==1.6.0
- flake8-rst-docstrings==0.3.0
- id: ruff-format
- id: ruff
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
Expand Down
59 changes: 59 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
target-version = "py38"

extend-select = [
"A",
"B",
"D",
"E501",
"EM",
"I",
"ICN",
"ISC",
"N",
"NPY",
"PL",
"PT",
"RET",
"RUF",
"UP",
"W",
]

ignore = [
"N806", "N803", # Allow occasional use of uppercase variable and argument names (e.g. N).
"D107", # Do not document __init__ separately from the class.
"PLR09", # Allow "too many" statements/arguments/etc...
"N816", # Allow mixed case names like kT.
"PT011", # PT011 insists that specific pytest.raises checks should impossibly more specific
"RUF012", # gsd does not use typing hints
]

[lint.per-file-ignores]

"__init__.py" = ["F401", # __init__.py import submodules for use by the package importer.
]

"gsd/test/*.py" = ["PLR2004", # unit test value comparisons are not magic values
]

"doc/conf.py" = ["A001", # Allow copyright variable name
"D", # conf.py does not need documentation
]

[pydocstyle]
convention = "google"

[format]
quote-style = "single"

[lint.flake8-import-conventions]
# Prefer no import aliases
aliases = {}
# Always import hoomd and gsd without 'from'
banned-from = ["hoomd", "gsd"]

# Ban standard import conventions and force common packages to be imported by their actual name.
[lint.flake8-import-conventions.banned-aliases]
"numpy" = ["np"]
"pandas" = ["pd"]
"matplotlib" = ["mpl"]
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
},
"[python]": {
"editor.rulers": [
80
88
]
},
"[cython]": {
"editor.rulers": [
80
88
]
},
"[markdown]": {
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Change Log

* Provide support via GitHub discussions
(`#308 <https://github.com/glotzerlab/gsd/issues/308>`__).
* Use ruff
(`#317 <https://github.com/glotzerlab/gsd/pull/317>`__).

3.2.0 (2023-09-27)
^^^^^^^^^^^^^^^^^^
Expand Down
59 changes: 32 additions & 27 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
# Copyright (c) 2016-2023 The Regents of the University of Michigan
# Part of GSD, released under the BSD 2-Clause License.

import datetime
import os
import subprocess
import gsd
import datetime
import tempfile

import gsd

extensions = [
'breathe',
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
'sphinx.ext.mathjax',
'IPython.sphinxext.ipython_console_highlighting',
'IPython.sphinxext.ipython_directive'
'IPython.sphinxext.ipython_directive',
]

napoleon_include_special_with_doc = True

intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/doc/stable', None),
'hoomd': ('https://hoomd-blue.readthedocs.io/en/latest/', None),
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/doc/stable', None),
'hoomd': ('https://hoomd-blue.readthedocs.io/en/latest/', None),
}
autodoc_docstring_signature = True;
autodoc_docstring_signature = True

templates_path = ['_templates']

Expand All @@ -43,50 +45,53 @@

default_role = 'any'

pygments_style = "friendly"
pygments_dark_style = "native"
pygments_style = 'friendly'
pygments_dark_style = 'native'

html_theme = 'furo'
html_static_path = ['_static']
html_theme_options = {
"dark_css_variables": {
"color-brand-primary": "#5187b2",
"color-brand-content": "#5187b2",
'dark_css_variables': {
'color-brand-primary': '#5187b2',
'color-brand-content': '#5187b2',
},
"light_css_variables": {
"color-brand-primary": "#406a8c",
"color-brand-content": "#406a8c",
'light_css_variables': {
'color-brand-primary': '#406a8c',
'color-brand-content': '#406a8c',
},
}


### Add custom directives
def setup(app):
app.add_object_type('chunk', 'chunk',
objname='Data chunk',
indextemplate='single: %s (data chunk)')
app.add_object_type(
'chunk', 'chunk', objname='Data chunk', indextemplate='single: %s (data chunk)'
)


tmpdir = tempfile.TemporaryDirectory()

###### IPython directive settings
ipython_mplbackend = ''
ipython_execlines = ['import gsd.fl',
'import gsd.hoomd',
'import gsd.pygsd',
'import numpy',
'import os',
f'os.chdir("{tmpdir.name}")']
ipython_execlines = [
'import gsd.fl',
'import gsd.hoomd',
'import gsd.pygsd',
'import numpy',
'import os',
f'os.chdir("{tmpdir.name}")',
]


dirname = os.path.abspath(os.path.dirname(__file__))
breathe_projects = {'gsd': os.path.join(dirname, '..', 'devdoc', 'xml')}
breathe_default_project = 'gsd'

breathe_domain_by_extension = {
"h" : "c",
'h': 'c',
}

read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'

if read_the_docs_build:

subprocess.call('cd ..; doxygen', shell=True)
subprocess.call('cd ..; doxygen', shell=True)
3 changes: 2 additions & 1 deletion gsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import signal
import sys
from . import version # noqa: F401

from . import version

# Install a SIGTERM handler that gracefully exits, allowing open files to flush
# buffered writes and close. Catch ValueError and pass as there is no way to
Expand Down
Loading

0 comments on commit 9d7153d

Please sign in to comment.