Skip to content

Commit

Permalink
🐛 FIX: CLI option callbacks with --config (#60)
Browse files Browse the repository at this point in the history
These option value should be unprocessed.
This also fixes a bug with the directive data caching.
  • Loading branch information
chrisjsewell authored Jan 16, 2023
1 parent c660937 commit b9faa5a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Installation (deps and package)
# we install with flit --pth-file,
# so that coverage will be recorded up for the module
run: |
pip install flit
flit install --deps=production --extras=test,sphinx --pth-file
pip install --upgrade pip
pip install -e .[test,sphinx]
- name: Run pytest
run: |
Expand Down
2 changes: 2 additions & 0 deletions rst_to_myst/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def read_conversions(ctx, param, value):
"--conversions",
"-c",
default=None,
type=click.types.UNPROCESSED,
callback=read_conversions,
metavar="PATH",
help="YAML file mapping directives -> conversions",
Expand Down Expand Up @@ -132,6 +133,7 @@ def split_extension(ctx, param, value):
OPT_EXTENSIONS = click.option(
"--extensions",
"-e",
type=click.types.UNPROCESSED,
callback=split_extension,
help="A comma-separated list of sphinx extensions to load.",
)
Expand Down
2 changes: 1 addition & 1 deletion rst_to_myst/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def to_docutils_ast(
# get conversion lookup for directives
directive_data = _load_directive_data()
if conversions:
directive_data.update(conversions)
directive_data = {**directive_data, **conversions}
document.settings.directive_data = directive_data

# whether to treat initial field list as front matter
Expand Down
27 changes: 25 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from textwrap import dedent

from click.testing import CliRunner

Expand Down Expand Up @@ -63,9 +64,31 @@ def test_stream():

def test_convert(tmp_path: Path, file_regression):
tmp_path.joinpath("test.rst").write_text(
"head\n====\n\ncontent `a`\n", encoding="utf8"
dedent(
"""\
head
====
content `a`
.. note:: `c`
```
"""
),
encoding="utf8",
)
tmp_path.joinpath("config.yaml").write_text(
dedent(
"""\
default_role: math
sphinx: true
extensions: [sphinx.ext.intersphinx]
conversions:
docutils.parsers.rst.directives.admonitions.Note: direct
"""
),
encoding="utf8",
)
tmp_path.joinpath("config.yaml").write_text("default_role: math\n", encoding="utf8")
runner = CliRunner()
result = runner.invoke(
cli.convert,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cli/test_convert.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# head

content $a$

```{note}
`c`
```
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[tox]
envlist = py38
isolated_build = True

[testenv]
usedevelop = true

[testenv:py{37,38,39,310,311}]
deps =
Expand Down

0 comments on commit b9faa5a

Please sign in to comment.