From b9faa5a3ebc47bdd9415125224848940fed69f2a Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Mon, 16 Jan 2023 23:33:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20CLI=20option=20callbacks?= =?UTF-8?q?=20with=20--config=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These option value should be unprocessed. This also fixes a bug with the directive data caching. --- .github/workflows/tests.yml | 6 ++---- rst_to_myst/cli.py | 2 ++ rst_to_myst/parser.py | 2 +- tests/test_cli.py | 27 +++++++++++++++++++++++++-- tests/test_cli/test_convert.md | 4 ++++ tox.ini | 4 +++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 982d0ed..8e8ef2e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: | diff --git a/rst_to_myst/cli.py b/rst_to_myst/cli.py index 71059bb..1902235 100644 --- a/rst_to_myst/cli.py +++ b/rst_to_myst/cli.py @@ -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", @@ -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.", ) diff --git a/rst_to_myst/parser.py b/rst_to_myst/parser.py index 7aa4c28..3e86ecb 100644 --- a/rst_to_myst/parser.py +++ b/rst_to_myst/parser.py @@ -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 diff --git a/tests/test_cli.py b/tests/test_cli.py index ffe505f..097175a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,5 @@ from pathlib import Path +from textwrap import dedent from click.testing import CliRunner @@ -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, diff --git a/tests/test_cli/test_convert.md b/tests/test_cli/test_convert.md index 98d2c6f..9a13288 100644 --- a/tests/test_cli/test_convert.md +++ b/tests/test_cli/test_convert.md @@ -1,3 +1,7 @@ # head content $a$ + +```{note} +`c` +``` diff --git a/tox.ini b/tox.ini index 8d0fa16..c62fd89 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,8 @@ [tox] envlist = py38 -isolated_build = True + +[testenv] +usedevelop = true [testenv:py{37,38,39,310,311}] deps =