From 116a430caca98580c8877cf7b0ba270eae9604bf Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:47:15 +0100 Subject: [PATCH] Accept `PathLike` in `Sphinx.add_message_catalog()` --- doc/extdev/i18n.rst | 4 ++-- sphinx/application.py | 2 +- sphinx/locale/__init__.py | 6 +++--- tests/conftest.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/extdev/i18n.rst b/doc/extdev/i18n.rst index c5ffc848306..3c476820fbd 100644 --- a/doc/extdev/i18n.rst +++ b/doc/extdev/i18n.rst @@ -51,8 +51,8 @@ In practice, you have to: :caption: src/__init__.py def setup(app): - package_dir = path.abspath(path.dirname(__file__)) - locale_dir = os.path.join(package_dir, 'locales') + package_dir = Path(__file__).parent.resolve() + locale_dir = package_dir / 'locales' app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir) #. Generate message catalog template ``*.pot`` file, usually in ``locale/`` diff --git a/sphinx/application.py b/sphinx/application.py index 417dd3f7bc3..2d650dc231f 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -1616,7 +1616,7 @@ def add_html_math_renderer( """ self.registry.add_html_math_renderer(name, inline_renderers, block_renderers) - def add_message_catalog(self, catalog: str, locale_dir: str) -> None: + def add_message_catalog(self, catalog: str, locale_dir: str | os.PathLike[str]) -> None: """Register a message catalog. :param catalog: The name of the catalog diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index 1d66c8e1e45..d1a70d05b36 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -5,7 +5,7 @@ import locale import sys from gettext import NullTranslations, translation -from os import path +from pathlib import Path from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -141,11 +141,11 @@ def init( return translator, has_translation -_LOCALE_DIR = path.abspath(path.dirname(__file__)) +_LOCALE_DIR = Path(__file__).parent.resolve() def init_console( - locale_dir: str | None = None, + locale_dir: str | os.PathLike[str] | None = None, catalog: str = 'sphinx', ) -> tuple[NullTranslations, bool]: """Initialize locale for console. diff --git a/tests/conftest.py b/tests/conftest.py index bf8b3eb2ebe..8501825a025 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,7 @@ def _init_console( - locale_dir: str | None = sphinx.locale._LOCALE_DIR, + locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR, catalog: str = 'sphinx', ) -> tuple[gettext.NullTranslations, bool]: """Monkeypatch ``init_console`` to skip its action.