Skip to content

Commit cb08169

Browse files
authored
ruff: Enable pydocstyle w/ numpy convention (#449)
See also: - https://www.pydocstyle.org/en/stable/ - https://docs.astral.sh/ruff/settings/#pydocstyle
2 parents 8b47794 + 5953d2b commit cb08169

46 files changed

Lines changed: 405 additions & 236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ $ pip install --user --upgrade --pre libvcs
2929

3030
### Development
3131

32+
- ci: Add pydocstyle rule to ruff (#449)
3233
- Add test for direct usage of `HgSync` (#450)
3334
- pytest-watcher, Add configuration (#450):
3435

3536
- Run initially by default
3637
- Skip post-save files from vim
3738

39+
### Documentation
40+
41+
- Add docstrings to functions, methods, classes, and packages (#449)
42+
3843
## libvcs 0.25.1 (2023-11-23)
3944

4045
### Packaging

conftest.py

Lines changed: 9 additions & 6 deletions
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
@@ -20,22 +20,25 @@ def add_doctest_fixtures(
2020
request: pytest.FixtureRequest,
2121
doctest_namespace: dict[str, t.Any],
2222
) -> None:
23+
"""Configure doctest fixtures for pytest-doctest."""
2324
from _pytest.doctest import DoctestItem
2425

2526
if isinstance(request._pyfuncitem, DoctestItem):
2627
request.getfixturevalue("add_doctest_fixtures")
2728
request.getfixturevalue("set_home")
2829

2930

31+
@pytest.fixture(autouse=True)
32+
def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None:
33+
"""Configure current directory for pytest tests."""
34+
monkeypatch.chdir(tmp_path)
35+
36+
3037
@pytest.fixture(autouse=True)
3138
def setup(
3239
request: pytest.FixtureRequest,
3340
gitconfig: pathlib.Path,
3441
set_home: pathlib.Path,
3542
) -> None:
43+
"""Configure test fixtures for pytest."""
3644
pass
37-
38-
39-
@pytest.fixture(autouse=True)
40-
def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None:
41-
monkeypatch.chdir(tmp_path)

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 libvcs."""
23
import inspect
34
import pathlib
45
import sys
@@ -149,7 +150,7 @@
149150

150151
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
151152
"""
152-
Determine the URL corresponding to Python object
153+
Determine the URL corresponding to Python object.
153154
154155
Notes
155156
-----
@@ -219,11 +220,13 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
219220

220221

221222
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
223+
"""Remove tabs.js from _static after build."""
222224
# Fix for sphinx-inline-tabs#18
223225
if app.builder.format == "html" and not exc:
224226
tabs_js = pathlib.Path(app.builder.outdir) / "_static" / "tabs.js"
225227
tabs_js.unlink(missing_ok=True)
226228

227229

228230
def setup(app: "Sphinx") -> None:
231+
"""Configure Sphinx app hooks."""
229232
app.connect("build-finished", remove_tabs_js)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ select = [
147147
"TRY", # Trycertatops
148148
"PERF", # Perflint
149149
"RUF", # Ruff-specific rules
150+
"D", # pydocstyle
150151
]
151152

152153
[tool.ruff.isort]
@@ -155,6 +156,9 @@ known-first-party = [
155156
]
156157
combine-as-imports = true
157158

159+
[tool.ruff.pydocstyle]
160+
convention = "numpy"
161+
158162
[tool.ruff.per-file-ignores]
159163
"*/__init__.py" = ["F401"]
160164

src/libvcs/__about__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Metadata package for libvcs."""
12
__title__ = "libvcs"
23
__package_name__ = "libvcs"
34
__description__ = "Lite, typed, python utilities for Git, SVN, Mercurial, etc."

src/libvcs/_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/libvcs/_internal/module_loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __repr__(self) -> str:
5656

5757

5858
def import_string(import_name: str, silent: bool = False) -> t.Any:
59-
"""Imports an object based on a string.
59+
"""Import an object based on a string.
6060
6161
This is useful if you want to use import paths as endpoints or
6262
something similar. An import path can be specified either in dotted

src/libvcs/_internal/query_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
class MultipleObjectsReturned(Exception):
17-
"""The requested object does not exist"""
17+
"""The requested object does not exist."""
1818

1919

2020
class ObjectDoesNotExist(Exception):
@@ -132,7 +132,7 @@ def __call__(
132132
data: t.Union[str, list[str], Mapping[str, str]],
133133
rhs: t.Union[str, list[str], Mapping[str, str], re.Pattern[str]],
134134
) -> bool:
135-
"""Callback for :class:`QueryList` filtering operators."""
135+
"""Return callback for :class:`QueryList` filtering operators."""
136136
...
137137

138138

src/libvcs/_internal/run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ProgressCallbackProtocol(Protocol):
8181
"""Callback to report subprocess communication."""
8282

8383
def __call__(self, output: AnyStr, timestamp: datetime.datetime) -> None:
84-
"""Callback signature for subprocess communication."""
84+
"""Process progress for subprocess communication."""
8585
...
8686

8787

@@ -126,7 +126,9 @@ def run(
126126
check_returncode: bool = True,
127127
callback: Optional[ProgressCallbackProtocol] = None,
128128
) -> str:
129-
"""Run 'args' in a shell and return the combined contents of stdout and
129+
"""Run a command.
130+
131+
Run 'args' in a shell and return the combined contents of stdout and
130132
stderr (Blocking). Throws an exception if the command exits non-zero.
131133
132134
Keyword arguments are passthrough to :class:`subprocess.Popen`.

src/libvcs/_internal/subprocess.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Invocable :mod:`subprocess` wrapper.
1+
r"""Invocable :mod:`subprocess` wrapper.
22
33
Defer running a subprocess, such as by handing to an executor.
44
@@ -8,7 +8,6 @@
88
99
Examples
1010
--------
11-
1211
- :class:`~SubprocessCommand`: Wraps :class:`subprocess.Popen` and
1312
:func:`subprocess.run` in a :func:`~dataclasses.dataclass`.
1413
@@ -19,15 +18,15 @@
1918
... ['echo', 'hi'],
2019
... capture_output=True, universal_newlines=True
2120
... ).stdout
22-
'hi\\n'
21+
'hi\n'
2322
2423
With this:
2524
2625
>>> cmd = SubprocessCommand(['echo', 'hi'])
2726
>>> cmd.args
2827
['echo', 'hi']
2928
>>> cmd.run(capture_output=True, universal_newlines=True).stdout
30-
'hi\\n'
29+
'hi\n'
3130
3231
Tweak params before invocation:
3332
@@ -36,7 +35,7 @@
3635
>>> cmd.args
3736
['echo', 'hello']
3837
>>> cmd.run(capture_output=True, universal_newlines=True).stdout
39-
'hello\\n'
38+
'hello\n'
4039
"""
4140
import dataclasses
4241
import subprocess

0 commit comments

Comments
 (0)