diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6c6f5c..ff05245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: workflow_dispatch: - pull_request_target: + pull_request: push: branches: - master diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b93745f..b54943a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.3 + rev: v4.0.0-alpha.8 hooks: - id: prettier types_or: @@ -16,7 +16,7 @@ repos: minimum_pre_commit_version: 2.9.0 exclude: ^tests - repo: https://github.com/mondeja/project-config - rev: v0.9.2 + rev: v0.9.4 hooks: - id: project-config - repo: meta @@ -34,13 +34,13 @@ repos: - id: end-of-file-fixer name: end-of-file-fixer - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.1 + rev: v1.5.5 hooks: - id: remove-crlf files: \.bat$ name: "*.bat end of lines" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 + rev: v0.2.1 hooks: - id: ruff args: @@ -51,7 +51,7 @@ repos: hooks: - id: autopep8 - repo: https://github.com/adrienverge/yamllint - rev: v1.32.0 + rev: v1.35.0 hooks: - id: yamllint - repo: https://github.com/editorconfig-checker/editorconfig-checker.python @@ -67,7 +67,7 @@ repos: name: markdown-link-check files: ^README\.md$ - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: v0.10.0 + rev: v0.12.1 hooks: - id: markdownlint-cli2 name: markdownlint-po2md-tests diff --git a/docs/conf.py b/docs/conf.py index 378cf31..ae1df55 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ ' = ', )[1].strip().strip('"').strip("'") elif line.startswith('authors ='): - metadata['author'] = re.search('name = \"([^\"]+)\"', line).group(1) + metadata['author'] = re.search('name = "([^"]+)"', line).group(1) elif not line: break diff --git a/docs/pre-commit-hooks.rst b/docs/pre-commit-hooks.rst index fc06830..cf1c902 100644 --- a/docs/pre-commit-hooks.rst +++ b/docs/pre-commit-hooks.rst @@ -19,7 +19,7 @@ so you don't need to specify them. .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: md2po args: @@ -32,7 +32,7 @@ so you don't need to specify them. .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: md2po files: ^README\.md @@ -53,7 +53,7 @@ po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: po2md args: @@ -68,7 +68,7 @@ po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: po2md files: ^README\.md @@ -91,7 +91,7 @@ md2po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: md2po2md args: @@ -107,7 +107,7 @@ md2po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: md2po2md files: ^README\.md @@ -126,7 +126,7 @@ mdpo2html .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: mdpo2html args: @@ -141,7 +141,7 @@ mdpo2html .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.4 + rev: v1.1.5 hooks: - id: mdpo2html files: ^README\.html diff --git a/pyproject.toml b/pyproject.toml index 81d9598..5f17a18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mdpo" -version = "1.1.4" +version = "1.1.5" description = "Markdown files translation using PO files." readme = "README.md" license = "BSD-3-Clause" @@ -88,11 +88,11 @@ python = ["py37", "py38", "py39", "py310", "py311", "py312"] [tool.hatch.envs.docs] python = "3.10" dependencies = [ - "Sphinx~=4.0", - "sphinx-rtd-theme~=1.0", - "sphinx-argparse-cli~=1.8", + "Sphinx~=7.2", + "sphinx-rtd-theme~=2.0", + "sphinx-argparse-cli~=1.12", "sphinx-github-changelog~=1.2", - "sphinx-tabs~=3.3", + "sphinx-tabs~=3.4", ] [tool.hatch.envs.docs.scripts] @@ -109,9 +109,9 @@ targets = [{ file = "pyproject.toml" }, { file = "docs/pre-commit-hooks.rst" }] [tool.project-config] cache = "2 days" style = [ - "gh://mondeja/project-config-styles@v5.1/python/base.json5", - "gh://mondeja/project-config-styles@v5.1/python/sphinx.json5", - "gh://mondeja/project-config-styles@v5.1/python/readthedocs.json5", + "gh://mondeja/project-config-styles@v5.2/python/base.json5", + "gh://mondeja/project-config-styles@v5.2/python/sphinx.json5", + "gh://mondeja/project-config-styles@v5.2/python/readthedocs.json5", ] [tool.pytest.ini_options] @@ -132,6 +132,8 @@ exclude_lines = [ [tool.ruff] line-length = 80 target-version = "py37" + +[tool.ruff.lint] select = [ "W", "B", @@ -165,21 +167,22 @@ ignore = [ "PLR0915", "PLR0913", "FBT002", + "G004", ] -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" -[tool.ruff.flake8-quotes] +[tool.ruff.lint.flake8-quotes] inline-quotes = "single" multiline-quotes = "single" -[tool.ruff.flake8-pytest-style] +[tool.ruff.lint.flake8-pytest-style] fixture-parentheses = false parametrize-values-type = "tuple" parametrize-values-row-type = "tuple" -[tool.ruff.isort] +[tool.ruff.lint.isort] lines-after-imports = 2 combine-as-imports = true force-wrap-aliases = true @@ -196,7 +199,7 @@ extra-standard-library = [ "wsgiref.types" ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/**" = [ "I002", "D100", diff --git a/src/mdpo/cli.py b/src/mdpo/cli.py index 8555d5c..5d4eb02 100644 --- a/src/mdpo/cli.py +++ b/src/mdpo/cli.py @@ -332,6 +332,24 @@ def add_event_argument(parser): ) +def add_include_codeblocks_option(parser): + """Add the ``--include-codeblocks`` option to an argument parser. + + Args: + parser (:py:class:`argparse.ArgumentParser`): Arguments parser to + extend. + """ + parser.add_argument( + '-c', '--include-codeblocks', + dest='include_codeblocks', action='store_true', + help='Include all code blocks found inside PO file result. This is' + ' useful if you want to translate all your blocks of code.' + ' Equivalent to append' + f' {cli_codespan("")} command' + ' before each code block.', + ) + + def parse_event_argument(value): """Parse ``--event`` CLI argument values. diff --git a/src/mdpo/md2po/__main__.py b/src/mdpo/md2po/__main__.py index 1feaacb..475dbcd 100755 --- a/src/mdpo/md2po/__main__.py +++ b/src/mdpo/md2po/__main__.py @@ -18,6 +18,7 @@ add_encoding_arguments, add_event_argument, add_extensions_argument, + add_include_codeblocks_option, add_nolocation_option, add_wrapwidth_argument, cli_codespan, @@ -112,15 +113,7 @@ def build_parser(): help='Include in the resulting PO file the mdpo specification' ' X-Header "X-Generation", whose value is "mdpo v".', ) - parser.add_argument( - '-c', '--include-codeblocks', - dest='include_codeblocks', action='store_true', - help='Include all code blocks found inside PO file result. This is' - ' useful if you want to translate all your blocks of code.' - ' Equivalent to append' - f' {cli_codespan("")} command' - ' before each code block.', - ) + add_include_codeblocks_option(parser) parser.add_argument( '--ignore-msgids', dest='ignore_msgids', default=None, help='Path to a plain text file where all msgids to ignore from being' diff --git a/src/mdpo/md2po2md/__init__.py b/src/mdpo/md2po2md/__init__.py index cb3faa0..b443bd0 100644 --- a/src/mdpo/md2po2md/__init__.py +++ b/src/mdpo/md2po2md/__init__.py @@ -20,6 +20,7 @@ def markdown_to_pofile_to_markdown( md_wrapwidth=80, po_encoding=None, md_encoding=None, + include_codeblocks=False, md2po_kwargs=None, po2md_kwargs=None, _check_saved_files_changed=False, @@ -64,6 +65,7 @@ def markdown_to_pofile_to_markdown( possible. po_encoding (str): PO files encoding. md_encoding (str): Markdown files encoding. + include_codeblocks (bool): Include codeblocks in the extraction process. md2po_kwargs (dict): Additional optional arguments passed to ``markdown_to_pofile`` function. po2md_kwargs (dict): Additional optional arguments passed to @@ -139,6 +141,7 @@ def markdown_to_pofile_to_markdown( debug=debug, location=location, wrapwidth=po_wrapwidth, + include_codeblocks=include_codeblocks, _check_saved_files_changed=_check_saved_files_changed, **(md2po_kwargs or {}), ) diff --git a/src/mdpo/md2po2md/__main__.py b/src/mdpo/md2po2md/__main__.py index 142e6d3..169985d 100755 --- a/src/mdpo/md2po2md/__main__.py +++ b/src/mdpo/md2po2md/__main__.py @@ -17,6 +17,7 @@ add_debug_option, add_encoding_arguments, add_extensions_argument, + add_include_codeblocks_option, add_nolocation_option, add_wrapwidth_argument, cli_codespan, @@ -82,6 +83,7 @@ def build_parser(): add_wrapwidth_argument( parser, markup='md', markup_prefix=True, short=False, default='80', ) + add_include_codeblocks_option(parser) add_encoding_arguments(parser) add_debug_option(parser) add_check_option(parser) @@ -132,6 +134,7 @@ def run(args=frozenset()): 'md_wrapwidth': opts.md_wrapwidth, 'po_encoding': opts.po_encoding, 'md_encoding': opts.md_encoding, + 'include_codeblocks': opts.include_codeblocks, '_check_saved_files_changed': opts.check_saved_files_changed, }