Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion sphinx_intl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("sphinx_intl")
Expand Down
8 changes: 3 additions & 5 deletions sphinx_intl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import multiprocessing as mp
import os
from glob import glob
from typing import Optional

import click

from . import catalog as c
from .pycompat import relpath


# ==================================
# utility functions

Expand Down Expand Up @@ -40,8 +38,8 @@ class UpdateItem:
class UpdateResult:
po_file: str
status: str
added: Optional[int] = 0
deleted: Optional[int] = 0
added: int = 0
deleted: int = 0


def _update_single_file(update_item: UpdateItem):
Expand Down Expand Up @@ -174,7 +172,7 @@ def stat(locale_dir, languages):
for dirpath, dirnames, filenames in os.walk(lang_dir):
for filename in filenames:
po_file = os.path.join(dirpath, filename)
base, ext = os.path.splitext(po_file)
_, ext = os.path.splitext(po_file)
if ext != ".po":
continue

Expand Down
2 changes: 1 addition & 1 deletion sphinx_intl/catalog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from babel.messages import pofile, mofile
from babel.messages import mofile, pofile


def load_po(filename, **kwargs):
Expand Down
22 changes: 10 additions & 12 deletions sphinx_intl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
:license: BSD, see LICENSE for details.
"""

import re
import os
import re
import warnings
from glob import glob

import click
from sphinx.util.tags import Tags

from . import basic
from . import transifex
from . import basic, transifex
from .pycompat import execfile_, relpath

ENVVAR_PREFIX = "SPHINXINTL"
Expand All @@ -40,7 +39,7 @@ def read_config(path, passed_tags):
olddir = os.getcwd()
try:
if not os.path.isfile(path):
msg = "'%s' is not found (or specify --locale-dir option)." % path
msg = f"'{path}' is not found (or specify --locale-dir option)."
raise click.BadParameter(msg)
os.chdir(os.path.dirname(path) or ".")
execfile_(os.path.basename(path), namespace)
Expand Down Expand Up @@ -248,13 +247,12 @@ def main(ctx, config, tag):
ctx.transifex_project_name = None
target = os.path.normpath(".tx/config")
if os.path.exists(target):
matched = re.search(r"\[(.*)\..*\]", open(target).read())
with open(target) as config_file:
matched = re.search(r"\[(.*)\..*\]", config_file.read())
if matched:
ctx.transifex_project_name = matched.groups()[0]
click.echo(
"Project name loaded from .tx/config: {}".format(
ctx.transifex_project_name
)
f"Project name loaded from .tx/config: {ctx.transifex_project_name}"
)

ctx.default_map = {
Expand Down Expand Up @@ -296,8 +294,8 @@ def update(locale_dir, pot_dir, language, line_width, no_obsolete, jobs):
pot_dir = os.path.join(locale_dir, "pot")
if not os.path.exists(pot_dir):
msg = (
"%(pot_dir)r does not exist. Please specify pot directory with "
"-p option, or preparing your pot files in %(pot_dir)r." % locals()
f"{pot_dir!r} does not exist. Please specify pot directory with "
f"-p option, or preparing your pot files in {pot_dir!r}."
)
raise click.BadParameter(msg, param_hint="pot_dir")
if not language:
Expand All @@ -306,8 +304,8 @@ def update(locale_dir, pot_dir, language, line_width, no_obsolete, jobs):
if not languages:
msg = (
"No languages are found. Please specify language with -l "
"option, or preparing language directories under %(locale_dir)r "
"directory." % locals()
f"option, or preparing language directories under {locale_dir!r} "
"directory."
)
raise click.BadParameter(msg, param_hint="language")

Expand Down
6 changes: 3 additions & 3 deletions sphinx_intl/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Python compatibility functions.
"""

import sys
import os
import sys
import warnings
from typing import Any, Callable

Expand All @@ -23,8 +23,8 @@ def relpath(path: str, start: str = os.curdir) -> str:
# convert_with_2to3():
# support for running 2to3 over config files
def convert_with_2to3(filepath: str) -> str:
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
from lib2to3.pgen2.parse import ParseError
from lib2to3.refactor import RefactoringTool, get_fixers_from_package

fixers = get_fixers_from_package("lib2to3.fixes")
refactoring_tool = RefactoringTool(fixers)
Expand Down Expand Up @@ -58,4 +58,4 @@ def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None:
"Convert %s to Python 3 syntax.",
source=filepath,
)
exec(code, _globals)
exec(code, _globals) # noqa: S102 # conf.py is executable Python by design
4 changes: 3 additions & 1 deletion sphinx_intl/sphinx_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from collections.abc import Iterator


# port from https://github.com/sphinx-doc/sphinx/blob/ad41e0b/sphinx/util/tags.py
class Tags:
def __init__(self, tags: list[str] = None) -> None:
def __init__(self, tags: list[str] | None = None) -> None:
self.tags = dict.fromkeys(tags or [], True)

def has(self, tag: str) -> bool:
Expand Down
1 change: 0 additions & 1 deletion sphinx_intl/transifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .catalog import load_po


# ==================================
# settings

Expand Down