Skip to content

Commit

Permalink
Add --include-codeblocks option to md2po2md (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Feb 16, 2024
1 parent 8f50086 commit beccb31
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
workflow_dispatch:
pull_request_target:
pull_request:
push:
branches:
- master
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions docs/pre-commit-hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
29 changes: 16 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -132,6 +132,8 @@ exclude_lines = [
[tool.ruff]
line-length = 80
target-version = "py37"

[tool.ruff.lint]
select = [
"W",
"B",
Expand Down Expand Up @@ -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
Expand All @@ -196,7 +199,7 @@ extra-standard-library = [
"wsgiref.types"
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/**" = [
"I002",
"D100",
Expand Down
18 changes: 18 additions & 0 deletions src/mdpo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<!-- mdpo-include-codeblock -->")} command'
' before each code block.',
)


def parse_event_argument(value):
"""Parse ``--event`` CLI argument values.
Expand Down
11 changes: 2 additions & 9 deletions src/mdpo/md2po/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<version>".',
)
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("<!-- mdpo-include-codeblock -->")} 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'
Expand Down
3 changes: 3 additions & 0 deletions src/mdpo/md2po2md/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {}),
)
Expand Down
3 changes: 3 additions & 0 deletions src/mdpo/md2po2md/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}

Expand Down

0 comments on commit beccb31

Please sign in to comment.