Skip to content

Commit 3b01dc8

Browse files
authored
ruff(docs): Enable pydocstyle w/ numpy convention (#509)
See also: - https://www.pydocstyle.org/en/stable/ - https://docs.astral.sh/ruff/settings/#pydocstyle
2 parents ac19b4b + 368b542 commit 3b01dc8

38 files changed

+402
-182
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ $ pip install --user --upgrade --pre libtmux
2020

2121
Thank you @m1guelperez for `Window.__eq__`! (#505)
2222

23+
### Development
24+
25+
- ci: Add pydocstyle rule to ruff (#509)
26+
27+
### Documentation
28+
29+
- Add docstrings to functions, methods, classes, and packages (#509)
30+
2331
## libtmux 0.24.1 (2023-11-23)
2432

2533
### Packaging

conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Conftest.py (root-level)
1+
"""Conftest.py (root-level).
22
33
We keep this in root pytest fixtures in pytest's doctest plugin to be available, as well
44
as avoiding conftest.py from being included in the wheel, in addition to pytest_plugin
@@ -27,6 +27,7 @@ def add_doctest_fixtures(
2727
request: pytest.FixtureRequest,
2828
doctest_namespace: t.Dict[str, t.Any],
2929
) -> None:
30+
"""Configure doctest fixtures for pytest-doctest."""
3031
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
3132
request.getfixturevalue("set_home")
3233
doctest_namespace["server"] = request.getfixturevalue("server")
@@ -42,6 +43,7 @@ def set_home(
4243
monkeypatch: pytest.MonkeyPatch,
4344
user_path: pathlib.Path,
4445
) -> None:
46+
"""Configure home directory for pytest tests."""
4547
monkeypatch.setenv("HOME", str(user_path))
4648

4749

@@ -51,5 +53,6 @@ def setup(
5153
request: pytest.FixtureRequest,
5254
config_file: pathlib.Path,
5355
) -> None:
56+
"""Configure test fixtures for pytest."""
5457
if USING_ZSH:
5558
request.getfixturevalue("zshrc")

docs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Documentation for the libtmux package."""

docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# flake8: NOQA: E501
2+
"""Sphinx configuration for libtmux."""
23
import contextlib
34
import inspect
45
import pathlib
@@ -132,7 +133,7 @@
132133

133134
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
134135
"""
135-
Determine the URL corresponding to Python object
136+
Determine the URL corresponding to Python object.
136137
137138
Notes
138139
-----
@@ -202,6 +203,7 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
202203

203204

204205
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
206+
"""Remove tabs.js from _static after build."""
205207
# Fix for sphinx-inline-tabs#18
206208
if app.builder.format == "html" and not exc:
207209
tabs_js = pathlib.Path(app.builder.outdir) / "_static" / "tabs.js"
@@ -210,4 +212,5 @@ def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
210212

211213

212214
def setup(app: "Sphinx") -> None:
215+
"""Configure Sphinx app hooks."""
213216
app.connect("build-finished", remove_tabs_js)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ select = [
128128
"TRY", # Trycertatops
129129
"PERF", # Perflint
130130
"RUF", # Ruff-specific rules
131+
"D", # pydocstyle
131132
]
132133

133134
[tool.ruff.isort]
@@ -136,6 +137,9 @@ known-first-party = [
136137
]
137138
combine-as-imports = true
138139

140+
[tool.ruff.pydocstyle]
141+
convention = "numpy"
142+
139143
[tool.ruff.per-file-ignores]
140144
"*/__init__.py" = ["F401"]
141145

src/libtmux/__about__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Metadata package for libtmux."""
12
__title__ = "libtmux"
23
__package_name__ = "libtmux"
34
__version__ = "0.24.1"

src/libtmux/_internal/dataclasses.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313

1414

1515
class SkipDefaultFieldsReprMixin:
16-
r"""Skip default fields in :func:`~dataclasses.dataclass`
17-
:func:`object representation <repr()>`.
16+
r"""Skip default fields in :func:`~dataclasses.dataclass` object representation.
17+
18+
See Also
19+
--------
20+
:func:`object representation <repr()>`
1821
1922
Notes
2023
-----
21-
2224
Credit: Pietro Oldrati, 2022-05-08, Unilicense
2325
2426
https://stackoverflow.com/a/72161437/1396928
2527
2628
Examples
2729
--------
28-
2930
>>> @dataclasses.dataclass()
3031
... class Item:
3132
... name: str

src/libtmux/_internal/query_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __call__(
1919
data: t.Union[str, t.List[str], "Mapping[str, str]"],
2020
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
2121
) -> bool:
22-
"""Callback for :class:`QueryList` filtering operators."""
22+
"""Return callback for :class:`QueryList` filtering operators."""
2323
...
2424

2525

@@ -29,7 +29,7 @@ def __call__(
2929

3030

3131
class MultipleObjectsReturned(Exception):
32-
"""The requested object does not exist"""
32+
"""The requested object does not exist."""
3333

3434

3535
class ObjectDoesNotExist(Exception):
@@ -40,7 +40,7 @@ def keygetter(
4040
obj: "Mapping[str, t.Any]",
4141
path: str,
4242
) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]:
43-
"""obj, "foods__breakfast", obj['foods']['breakfast']
43+
"""obj, "foods__breakfast", obj['foods']['breakfast'].
4444
4545
>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods__breakfast")
4646
'cereal'

src/libtmux/_vendor/version.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# This file is dual licensed under the terms of the Apache License, Version
33
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
44
# for complete details.
5-
"""
5+
"""Backport of the ``packaging.version`` module from Python 3.8.
6+
67
.. testsetup::
78
89
from packaging.version import parse, Version
@@ -159,7 +160,7 @@ def __ne__(self, other: object) -> bool:
159160

160161

161162
class Version(_BaseVersion):
162-
"""This class abstracts handling of a project's versions.
163+
"""Class abstracts handling of a project's versions.
163164
164165
A :class:`Version` instance is comparison aware and can be compared and
165166
sorted using the standard Python interfaces.
@@ -194,7 +195,6 @@ def __init__(self, version: str) -> None:
194195
If the ``version`` does not conform to PEP 440 in any way then this
195196
exception will be raised.
196197
"""
197-
198198
# Validate the version and parse it into pieces
199199
match = self._regex.search(version)
200200
if not match:
@@ -223,15 +223,15 @@ def __init__(self, version: str) -> None:
223223
)
224224

225225
def __repr__(self) -> str:
226-
"""A representation of the Version that shows all internal state.
226+
"""Return representation of the Version that shows all internal state.
227227
228228
>>> Version('1.0.0')
229229
<Version('1.0.0')>
230230
"""
231231
return f"<Version('{self}')>"
232232

233233
def __str__(self) -> str:
234-
"""A string representation of the version that can be rounded-tripped.
234+
"""Return string representation of the version that can be rounded-tripped.
235235
236236
>>> str(Version("1.0a5"))
237237
'1.0a5'
@@ -492,9 +492,7 @@ def _parse_letter_version(
492492

493493

494494
def _parse_local_version(local: str) -> Optional[LocalType]:
495-
"""
496-
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
497-
"""
495+
"""Take a string like abc.1.twelve and turns it into ("abc", 1, "twelve")."""
498496
if local is not None:
499497
return tuple(
500498
part.lower() if not part.isdigit() else int(part)

src/libtmux/common.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# flake8: NOQA: W605
2-
"""Helper methods and mixins.
2+
"""Helper methods and mixins for libtmux.
33
44
libtmux.common
55
~~~~~~~~~~~~~~
@@ -36,11 +36,7 @@
3636

3737

3838
class EnvironmentMixin:
39-
40-
"""
41-
Mixin class for managing session and server level environment variables in
42-
tmux.
43-
"""
39+
"""Mixin for manager session and server level environment variables in tmux."""
4440

4541
_add_option = None
4642

@@ -194,13 +190,11 @@ def getenv(self, name: str) -> Optional[t.Union[str, bool]]:
194190

195191

196192
class tmux_cmd:
197-
198193
"""
199194
:term:`tmux(1)` command via :py:mod:`subprocess`.
200195
201196
Examples
202197
--------
203-
204198
.. code-block:: python
205199
206200
proc = tmux_cmd('new-session', '-s%' % 'my session')
@@ -220,7 +214,6 @@ class tmux_cmd:
220214
221215
Notes
222216
-----
223-
224217
.. versionchanged:: 0.8
225218
Renamed from ``tmux`` to ``tmux_cmd``.
226219
"""
@@ -413,7 +406,6 @@ def has_minimum_version(raises: bool = True) -> bool:
413406
414407
Notes
415408
-----
416-
417409
.. versionchanged:: 0.7.0
418410
No longer returns version, returns True or False
419411
@@ -436,8 +428,7 @@ def has_minimum_version(raises: bool = True) -> bool:
436428

437429

438430
def session_check_name(session_name: t.Optional[str]) -> None:
439-
"""
440-
Raises exception session name invalid, modeled after tmux function.
431+
"""Raise exception session name invalid, modeled after tmux function.
441432
442433
tmux(1) session names may not be empty, or include periods or colons.
443434
These delimiters are reserved for noting session, window and pane.
@@ -461,7 +452,7 @@ def session_check_name(session_name: t.Optional[str]) -> None:
461452

462453

463454
def handle_option_error(error: str) -> t.Type[exc.OptionError]:
464-
"""Raises exception if error in option command found.
455+
"""Raise exception if error in option command found.
465456
466457
In tmux 3.0, show-option and show-window-option return invalid option instead of
467458
unknown option. See https://github.com/tmux/tmux/blob/3.0/cmd-show-options.c.

0 commit comments

Comments
 (0)