Skip to content

ruff: Enable pydocstyle w/ numpy convention #509

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

Merged
merged 41 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fba07b8
ruff: Enable pydocstyle w/ numpy convention
tony Nov 25, 2023
f32527d
ruff(pydocstyle): Run automated fixes
tony Nov 25, 2023
8775e3e
ruff(pydocstyle): Run automated fixes (unsafe ones)
tony Nov 25, 2023
8c038bd
chore(tests[window]): pydocstyle manual fixes
tony Nov 25, 2023
08d4522
chore(tests[version]): pydocstyle manual fixes
tony Nov 25, 2023
7b7a143
chore(tests[test]): pydocstyle manual fixes
tony Nov 25, 2023
7fa1211
chore(tests[session]): pydocstyle manual fixes
tony Nov 25, 2023
591da9e
chore(tests[server]): pydocstyle manual fixes
tony Nov 25, 2023
5860efb
chore(tests[pytest_plugin]): pydocstyle manual fixes
tony Nov 25, 2023
c7857fe
chore(tests[pane]): pydocstyle manual fixes
tony Nov 25, 2023
7796d6a
chore(tests[dataclasses]): pydocstyle manual fixes
tony Nov 25, 2023
402fe8a
chore(tests[common]): pydocstyle manual fixes
tony Nov 25, 2023
0c4b5e2
chore(tests[legacy_window]): pydocstyle manual fixes
tony Nov 25, 2023
530df7d
chore(tests[legacy_version]): pydocstyle manual fixes
tony Nov 25, 2023
a98fc87
chore(tests[legacy_test]): pydocstyle manual fixes
tony Nov 25, 2023
fdef43c
chore(tests[legacy_session]): pydocstyle manual fixes
tony Nov 25, 2023
0c28aab
chore(tests[legacy_server]): pydocstyle manual fixes
tony Nov 25, 2023
2750019
chore(tests[legacy_pane]): pydocstyle manual fixes
tony Nov 25, 2023
66a5f6a
chore(tests[legacy_common]): pydocstyle manual fixes
tony Nov 25, 2023
611dba3
chore(tests[legacy]): pydocstyle manual fixes
tony Nov 25, 2023
9a2859a
chore(tests): pydocstyle manual fixes
tony Nov 25, 2023
147ecc5
chore(window): pydocstyle manual fixes
tony Nov 25, 2023
57c9868
chore(test): pydocstyle manual fixes
tony Nov 25, 2023
4a30958
chore(session): pydocstyle manual fixes
tony Nov 25, 2023
56eb00a
chore(server): pydocstyle manual fixes
tony Nov 25, 2023
9d047bb
chore(pytest_plugin): pydocstyle manual fixes
tony Nov 25, 2023
023aa2f
chore(pane): pydocstyle manual fixes
tony Nov 25, 2023
ddeb5f3
chore(neo): pydocstyle manual fixes
tony Nov 25, 2023
c3e03d0
chore(common): pydocstyle manual fixes
tony Nov 25, 2023
f85d653
chore(vendor[version]): pydocstyle manual fixes
tony Nov 25, 2023
1d636f8
chore(internal[query_list]): pydocstyle manual fixes
tony Nov 25, 2023
71a707e
chore(internal[dataclasses]): pydocstyle manual fixes
tony Nov 25, 2023
c2872c3
chore(__about__): pydocstyle manual fixes
tony Nov 25, 2023
5e9a940
chore(docs): pydocstyle manual fixes
tony Nov 25, 2023
bae767a
chore(conftest): pydocstyle manual fixes
tony Nov 25, 2023
25ebedb
chore(docs[conf]): pydocstyle manual fixes
tony Nov 25, 2023
6dcd7d8
docs(server): Document deprecated legacy APIs
tony Nov 25, 2023
b6389fd
docs(session): Document deprecated legacy APIs
tony Nov 25, 2023
67a46c8
docs(window): Document deprecated legacy APIs
tony Nov 25, 2023
c8c72b3
docs(pane): Document deprecated legacy APIs
tony Nov 25, 2023
368b542
docs(CHANGES): Note documentation updates
tony Nov 25, 2023
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: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ $ pip install --user --upgrade --pre libtmux

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

### Development

- ci: Add pydocstyle rule to ruff (#509)

### Documentation

- Add docstrings to functions, methods, classes, and packages (#509)

## libtmux 0.24.1 (2023-11-23)

### Packaging
Expand Down
5 changes: 4 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Conftest.py (root-level)
"""Conftest.py (root-level).

We keep this in root pytest fixtures in pytest's doctest plugin to be available, as well
as avoiding conftest.py from being included in the wheel, in addition to pytest_plugin
Expand Down Expand Up @@ -27,6 +27,7 @@ def add_doctest_fixtures(
request: pytest.FixtureRequest,
doctest_namespace: t.Dict[str, t.Any],
) -> None:
"""Configure doctest fixtures for pytest-doctest."""
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
request.getfixturevalue("set_home")
doctest_namespace["server"] = request.getfixturevalue("server")
Expand All @@ -42,6 +43,7 @@ def set_home(
monkeypatch: pytest.MonkeyPatch,
user_path: pathlib.Path,
) -> None:
"""Configure home directory for pytest tests."""
monkeypatch.setenv("HOME", str(user_path))


Expand All @@ -51,5 +53,6 @@ def setup(
request: pytest.FixtureRequest,
config_file: pathlib.Path,
) -> None:
"""Configure test fixtures for pytest."""
if USING_ZSH:
request.getfixturevalue("zshrc")
1 change: 1 addition & 0 deletions docs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Documentation for the libtmux package."""
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: NOQA: E501
"""Sphinx configuration for libtmux."""
import contextlib
import inspect
import pathlib
Expand Down Expand Up @@ -132,7 +133,7 @@

def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object
Determine the URL corresponding to Python object.

Notes
-----
Expand Down Expand Up @@ -202,6 +203,7 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:


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


def setup(app: "Sphinx") -> None:
"""Configure Sphinx app hooks."""
app.connect("build-finished", remove_tabs_js)
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ select = [
"TRY", # Trycertatops
"PERF", # Perflint
"RUF", # Ruff-specific rules
"D", # pydocstyle
]

[tool.ruff.isort]
Expand All @@ -136,6 +137,9 @@ known-first-party = [
]
combine-as-imports = true

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
"*/__init__.py" = ["F401"]

Expand Down
1 change: 1 addition & 0 deletions src/libtmux/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Metadata package for libtmux."""
__title__ = "libtmux"
__package_name__ = "libtmux"
__version__ = "0.24.1"
Expand Down
9 changes: 5 additions & 4 deletions src/libtmux/_internal/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@


class SkipDefaultFieldsReprMixin:
r"""Skip default fields in :func:`~dataclasses.dataclass`
:func:`object representation <repr()>`.
r"""Skip default fields in :func:`~dataclasses.dataclass` object representation.

See Also
--------
:func:`object representation <repr()>`

Notes
-----

Credit: Pietro Oldrati, 2022-05-08, Unilicense

https://stackoverflow.com/a/72161437/1396928

Examples
--------

>>> @dataclasses.dataclass()
... class Item:
... name: str
Expand Down
6 changes: 3 additions & 3 deletions src/libtmux/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __call__(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
"""Callback for :class:`QueryList` filtering operators."""
"""Return callback for :class:`QueryList` filtering operators."""
...


Expand All @@ -29,7 +29,7 @@ def __call__(


class MultipleObjectsReturned(Exception):
"""The requested object does not exist"""
"""The requested object does not exist."""


class ObjectDoesNotExist(Exception):
Expand All @@ -40,7 +40,7 @@ def keygetter(
obj: "Mapping[str, t.Any]",
path: str,
) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]:
"""obj, "foods__breakfast", obj['foods']['breakfast']
"""obj, "foods__breakfast", obj['foods']['breakfast'].

>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods__breakfast")
'cereal'
Expand Down
14 changes: 6 additions & 8 deletions src/libtmux/_vendor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
"""
"""Backport of the ``packaging.version`` module from Python 3.8.

.. testsetup::

from packaging.version import parse, Version
Expand Down Expand Up @@ -159,7 +160,7 @@ def __ne__(self, other: object) -> bool:


class Version(_BaseVersion):
"""This class abstracts handling of a project's versions.
"""Class abstracts handling of a project's versions.

A :class:`Version` instance is comparison aware and can be compared and
sorted using the standard Python interfaces.
Expand Down Expand Up @@ -194,7 +195,6 @@ def __init__(self, version: str) -> None:
If the ``version`` does not conform to PEP 440 in any way then this
exception will be raised.
"""

# Validate the version and parse it into pieces
match = self._regex.search(version)
if not match:
Expand Down Expand Up @@ -223,15 +223,15 @@ def __init__(self, version: str) -> None:
)

def __repr__(self) -> str:
"""A representation of the Version that shows all internal state.
"""Return representation of the Version that shows all internal state.

>>> Version('1.0.0')
<Version('1.0.0')>
"""
return f"<Version('{self}')>"

def __str__(self) -> str:
"""A string representation of the version that can be rounded-tripped.
"""Return string representation of the version that can be rounded-tripped.

>>> str(Version("1.0a5"))
'1.0a5'
Expand Down Expand Up @@ -492,9 +492,7 @@ def _parse_letter_version(


def _parse_local_version(local: str) -> Optional[LocalType]:
"""
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
"""
"""Take a string like abc.1.twelve and turns it into ("abc", 1, "twelve")."""
if local is not None:
return tuple(
part.lower() if not part.isdigit() else int(part)
Expand Down
17 changes: 4 additions & 13 deletions src/libtmux/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: NOQA: W605
"""Helper methods and mixins.
"""Helper methods and mixins for libtmux.

libtmux.common
~~~~~~~~~~~~~~
Expand Down Expand Up @@ -36,11 +36,7 @@


class EnvironmentMixin:

"""
Mixin class for managing session and server level environment variables in
tmux.
"""
"""Mixin for manager session and server level environment variables in tmux."""

_add_option = None

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


class tmux_cmd:

"""
:term:`tmux(1)` command via :py:mod:`subprocess`.

Examples
--------

.. code-block:: python

proc = tmux_cmd('new-session', '-s%' % 'my session')
Expand All @@ -220,7 +214,6 @@ class tmux_cmd:

Notes
-----

.. versionchanged:: 0.8
Renamed from ``tmux`` to ``tmux_cmd``.
"""
Expand Down Expand Up @@ -413,7 +406,6 @@ def has_minimum_version(raises: bool = True) -> bool:

Notes
-----

.. versionchanged:: 0.7.0
No longer returns version, returns True or False

Expand All @@ -436,8 +428,7 @@ def has_minimum_version(raises: bool = True) -> bool:


def session_check_name(session_name: t.Optional[str]) -> None:
"""
Raises exception session name invalid, modeled after tmux function.
"""Raise exception session name invalid, modeled after tmux function.

tmux(1) session names may not be empty, or include periods or colons.
These delimiters are reserved for noting session, window and pane.
Expand All @@ -461,7 +452,7 @@ def session_check_name(session_name: t.Optional[str]) -> None:


def handle_option_error(error: str) -> t.Type[exc.OptionError]:
"""Raises exception if error in option command found.
"""Raise exception if error in option command found.

In tmux 3.0, show-option and show-window-option return invalid option instead of
unknown option. See https://github.com/tmux/tmux/blob/3.0/cmd-show-options.c.
Expand Down
32 changes: 8 additions & 24 deletions src/libtmux/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@


class LibTmuxException(Exception):

"""Base Exception for libtmux Errors."""


class TmuxSessionExists(LibTmuxException):

"""Session does not exist in the server."""


class TmuxCommandNotFound(LibTmuxException):

"""Application binary for tmux not found."""


Expand All @@ -47,12 +44,10 @@ def __init__(


class VersionTooLow(LibTmuxException):

"""Raised if tmux below the minimum version to use libtmux."""


class BadSessionName(LibTmuxException):

"""Disallowed session name for tmux (empty, contains periods or colons)."""

def __init__(
Expand All @@ -65,52 +60,45 @@ def __init__(


class OptionError(LibTmuxException):

"""Root error for any error involving invalid, ambiguous or bad options."""


class UnknownOption(OptionError):

"""Option unknown to tmux show-option(s) or show-window-option(s)."""


class UnknownColorOption(UnknownOption):

"""Unknown color option."""

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


class InvalidOption(OptionError):

"""Option invalid to tmux, introduced in tmux v2.4."""


class AmbiguousOption(OptionError):

"""Option that could potentially match more than one."""


class WaitTimeout(LibTmuxException):

"""Function timed out without meeting condition"""
"""Function timed out without meeting condition."""


class VariableUnpackingError(LibTmuxException):

"""Error unpacking variable"""
"""Error unpacking variable."""

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


class PaneError(LibTmuxException):
"""Any type of pane related error"""
"""Any type of pane related error."""


class PaneNotFound(PaneError):
"""Pane not found"""
"""Pane not found."""

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


class WindowError(LibTmuxException):

"""Any type of window related error"""
"""Any type of window related error."""


class MultipleActiveWindows(WindowError):

"""Multiple active windows"""
"""Multiple active windows."""

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


class NoActiveWindow(WindowError):

"""No active window found"""
"""No active window found."""

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


class NoWindowsExist(WindowError):

"""No windows exist for object"""
"""No windows exist for object."""

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