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.

src/libtmux/exc.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313

1414

1515
class LibTmuxException(Exception):
16-
1716
"""Base Exception for libtmux Errors."""
1817

1918

2019
class TmuxSessionExists(LibTmuxException):
21-
2220
"""Session does not exist in the server."""
2321

2422

2523
class TmuxCommandNotFound(LibTmuxException):
26-
2724
"""Application binary for tmux not found."""
2825

2926

@@ -47,12 +44,10 @@ def __init__(
4744

4845

4946
class VersionTooLow(LibTmuxException):
50-
5147
"""Raised if tmux below the minimum version to use libtmux."""
5248

5349

5450
class BadSessionName(LibTmuxException):
55-
5651
"""Disallowed session name for tmux (empty, contains periods or colons)."""
5752

5853
def __init__(
@@ -65,52 +60,45 @@ def __init__(
6560

6661

6762
class OptionError(LibTmuxException):
68-
6963
"""Root error for any error involving invalid, ambiguous or bad options."""
7064

7165

7266
class UnknownOption(OptionError):
73-
7467
"""Option unknown to tmux show-option(s) or show-window-option(s)."""
7568

7669

7770
class UnknownColorOption(UnknownOption):
78-
7971
"""Unknown color option."""
8072

8173
def __init__(self, *args: object):
8274
return super().__init__("Server.colors must equal 88 or 256")
8375

8476

8577
class InvalidOption(OptionError):
86-
8778
"""Option invalid to tmux, introduced in tmux v2.4."""
8879

8980

9081
class AmbiguousOption(OptionError):
91-
9282
"""Option that could potentially match more than one."""
9383

9484

9585
class WaitTimeout(LibTmuxException):
96-
97-
"""Function timed out without meeting condition"""
86+
"""Function timed out without meeting condition."""
9887

9988

10089
class VariableUnpackingError(LibTmuxException):
101-
102-
"""Error unpacking variable"""
90+
"""Error unpacking variable."""
10391

10492
def __init__(self, variable: t.Optional[t.Any] = None, *args: object):
10593
return super().__init__(f"Unexpected variable: {variable!s}")
10694

10795

10896
class PaneError(LibTmuxException):
109-
"""Any type of pane related error"""
97+
"""Any type of pane related error."""
11098

11199

112100
class PaneNotFound(PaneError):
113-
"""Pane not found"""
101+
"""Pane not found."""
114102

115103
def __init__(self, pane_id: t.Optional[str] = None, *args: object):
116104
if pane_id is not None:
@@ -119,29 +107,25 @@ def __init__(self, pane_id: t.Optional[str] = None, *args: object):
119107

120108

121109
class WindowError(LibTmuxException):
122-
123-
"""Any type of window related error"""
110+
"""Any type of window related error."""
124111

125112

126113
class MultipleActiveWindows(WindowError):
127-
128-
"""Multiple active windows"""
114+
"""Multiple active windows."""
129115

130116
def __init__(self, count: int, *args: object):
131117
return super().__init__(f"Multiple active windows: {count} found")
132118

133119

134120
class NoActiveWindow(WindowError):
135-
136-
"""No active window found"""
121+
"""No active window found."""
137122

138123
def __init__(self, *args: object):
139124
return super().__init__("No active windows found")
140125

141126

142127
class NoWindowsExist(WindowError):
143-
144-
"""No windows exist for object"""
128+
"""No windows exist for object."""
145129

146130
def __init__(self, *args: object):
147131
return super().__init__("No windows exist for object")

0 commit comments

Comments
 (0)