From 4804deb6630670dff1628a17bf458f17301d21f8 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 12:27:37 +0900 Subject: [PATCH 1/9] feat: Update application module to replace substitutions --- varst/application.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/varst/application.py b/varst/application.py index 307a7d4..6222b62 100644 --- a/varst/application.py +++ b/varst/application.py @@ -3,6 +3,8 @@ from typing import Sequence from varst.utils.parser import Parser +from varst.utils.rst_file import RstFile +from varst.utils.substitution import Substitution class Application: @@ -12,10 +14,16 @@ def __init__(self) -> None: self.parser = Parser() def run(self, argv: Optional[Sequence[str]]): - """Run application + """Run application to replace substitutions. Args: argv: Arguments vector """ self.parser.parse(argv) + + rst_file = RstFile(src=self.parser.input_file) + substitution = Substitution(rst_file) + for k, v in self.parser.variables.items(): + substitution.update(k, v) + rst_file.save(dest=self.parser.output_file) From f0718b2ca4d0c731d7cf715c36f7e2890cb312de Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 12:46:16 +0900 Subject: [PATCH 2/9] docs: Add github action badge to READEME.rst --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 52bd4d9..97f6b37 100644 --- a/README.rst +++ b/README.rst @@ -2,11 +2,12 @@ varST(var ➡️ reStructuredText) ============================== -|pre-commit.ci status| |Documentation Status| +|pre-commit.ci status| |GitHub Workflow Status| |Documentation Status| Replace substitutions in rst files with variables. .. |pre-commit.ci status| image:: https://results.pre-commit.ci/badge/github/junghoon-vans/varst/main.svg :target: https://results.pre-commit.ci/latest/github/junghoon-vans/varst/main +.. |GitHub Workflow Status| image:: https://img.shields.io/github/workflow/status/junghoon-vans/varst/Upload%20Python%20Package .. |Documentation Status| image:: https://readthedocs.org/projects/varst/badge/?version=latest :target: https://varst.readthedocs.io/en/latest/?badge=latest From ab1ae2dcf9f76ed8df8ffe8c3fd42f645ed0aab6 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 12:49:05 +0900 Subject: [PATCH 3/9] docs: Add pypi status badge to README.rst --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 97f6b37..fca6ad2 100644 --- a/README.rst +++ b/README.rst @@ -2,10 +2,12 @@ varST(var ➡️ reStructuredText) ============================== -|pre-commit.ci status| |GitHub Workflow Status| |Documentation Status| +|PyPI version| |pre-commit.ci status| |GitHub Workflow Status| |Documentation Status| Replace substitutions in rst files with variables. +.. |PyPI version| image:: https://img.shields.io/pypi/v/varst + :target: https://pypi.org/project/varst/ .. |pre-commit.ci status| image:: https://results.pre-commit.ci/badge/github/junghoon-vans/varst/main.svg :target: https://results.pre-commit.ci/latest/github/junghoon-vans/varst/main .. |GitHub Workflow Status| image:: https://img.shields.io/github/workflow/status/junghoon-vans/varst/Upload%20Python%20Package From 47aef0b569e84c1a61d99bcfebf2789b539613ae Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 13:38:00 +0900 Subject: [PATCH 4/9] refactor: Update parser to change help message --- varst/utils/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 10ddbf2..6773f3c 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -21,8 +21,8 @@ class Parser: def __init__(self) -> None: self._parser.add_argument( - "variables", nargs="*", - help="key-value pairs of substitutions", + "name=value", nargs="*", + help="name-value pairs of substitutions", type=_pattern_type, ) self._parser.add_argument( From 6e0d7d0be3f29f53f7248a029db2f779980a8844 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 13:39:32 +0900 Subject: [PATCH 5/9] docs: Update README.rst --- README.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.rst b/README.rst index fca6ad2..3070198 100644 --- a/README.rst +++ b/README.rst @@ -6,6 +6,27 @@ varST(var ➡️ reStructuredText) Replace substitutions in rst files with variables. +Installation +------------ + +.. code:: bash + + $ pip install varst + +Usage +----- + +.. code:: bash + + varst [-i INPUT] [-o OUTPUT] [name=value ...] + +License +------- + +`MIT +License `__ + + .. |PyPI version| image:: https://img.shields.io/pypi/v/varst :target: https://pypi.org/project/varst/ .. |pre-commit.ci status| image:: https://results.pre-commit.ci/badge/github/junghoon-vans/varst/main.svg From b2ca62eb022c5bba8f4fe3055b969e3e6f94e124 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 14:15:08 +0900 Subject: [PATCH 6/9] docs: Make subdirectory for api documentation --- docs/source/{ => api}/varst.application.rst | 0 docs/source/{ => api}/varst.cli.rst | 0 docs/source/api/varst.rst | 9 +++++++ docs/source/{ => api}/varst.utils.parser.rst | 0 docs/source/{ => api}/varst.utils.rst | 0 .../source/{ => api}/varst.utils.rst_file.rst | 0 .../{ => api}/varst.utils.substitution.rst | 0 docs/source/index.rst | 6 ++--- docs/source/varst.rst | 27 ------------------- 9 files changed, 12 insertions(+), 30 deletions(-) rename docs/source/{ => api}/varst.application.rst (100%) rename docs/source/{ => api}/varst.cli.rst (100%) create mode 100644 docs/source/api/varst.rst rename docs/source/{ => api}/varst.utils.parser.rst (100%) rename docs/source/{ => api}/varst.utils.rst (100%) rename docs/source/{ => api}/varst.utils.rst_file.rst (100%) rename docs/source/{ => api}/varst.utils.substitution.rst (100%) delete mode 100644 docs/source/varst.rst diff --git a/docs/source/varst.application.rst b/docs/source/api/varst.application.rst similarity index 100% rename from docs/source/varst.application.rst rename to docs/source/api/varst.application.rst diff --git a/docs/source/varst.cli.rst b/docs/source/api/varst.cli.rst similarity index 100% rename from docs/source/varst.cli.rst rename to docs/source/api/varst.cli.rst diff --git a/docs/source/api/varst.rst b/docs/source/api/varst.rst new file mode 100644 index 0000000..3db1192 --- /dev/null +++ b/docs/source/api/varst.rst @@ -0,0 +1,9 @@ +API docs +======== + +.. toctree:: + :maxdepth: 4 + + varst.cli + varst.application + varst.utils diff --git a/docs/source/varst.utils.parser.rst b/docs/source/api/varst.utils.parser.rst similarity index 100% rename from docs/source/varst.utils.parser.rst rename to docs/source/api/varst.utils.parser.rst diff --git a/docs/source/varst.utils.rst b/docs/source/api/varst.utils.rst similarity index 100% rename from docs/source/varst.utils.rst rename to docs/source/api/varst.utils.rst diff --git a/docs/source/varst.utils.rst_file.rst b/docs/source/api/varst.utils.rst_file.rst similarity index 100% rename from docs/source/varst.utils.rst_file.rst rename to docs/source/api/varst.utils.rst_file.rst diff --git a/docs/source/varst.utils.substitution.rst b/docs/source/api/varst.utils.substitution.rst similarity index 100% rename from docs/source/varst.utils.substitution.rst rename to docs/source/api/varst.utils.substitution.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 8a63a8d..39c1b6d 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -2,13 +2,13 @@ var ➡️ reStructuredText ======================= -Contents -======== +API documentation +================= .. toctree:: :maxdepth: 2 - varst + api/varst Changelog ========= diff --git a/docs/source/varst.rst b/docs/source/varst.rst deleted file mode 100644 index 0c8fac0..0000000 --- a/docs/source/varst.rst +++ /dev/null @@ -1,27 +0,0 @@ -varst package -============= - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - varst.utils - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - varst.application - varst.cli - -Module contents ---------------- - -.. automodule:: varst - :members: - :undoc-members: - :show-inheritance: From 89107a27de140a66706ce8c5121134caa383cbfb Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 14:15:47 +0900 Subject: [PATCH 7/9] docs: Update index page in documentation site --- docs/source/index.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index 39c1b6d..f3d1109 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -2,6 +2,23 @@ var ➡️ reStructuredText ======================= +Replace substitutions in rst files with variables. + +Installation +============ + +.. code:: bash + + $ pip install varst + +Usage +===== + +.. code:: bash + + varst [-i INPUT] [-o OUTPUT] [name=value ...] + + API documentation ================= From aac268c61b882d135ef4d29d30d3d0fec9fe9cf3 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 14:24:38 +0900 Subject: [PATCH 8/9] fix: Resolve failure to get variables --- varst/utils/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 6773f3c..6c7585d 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -53,7 +53,7 @@ def parse(self, argv: Optional[Sequence[str]]) -> None: self.input_file = arg_dict['input'] self.output_file = arg_dict['output'] - self.variables = _parse_kv(arg_dict['variables']) + self.variables = _parse_kv(arg_dict['name=value']) _VARIABLE_PATTERN = re.compile(r"[^=]+=[^=]+") From db2217986635d7f4a308fd7b68553bb0b79c0cd1 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 24 Nov 2022 16:03:47 +0900 Subject: [PATCH 9/9] docs: Update usage section --- README.rst | 2 +- docs/source/index.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 3070198..c80bc5f 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ Usage .. code:: bash - varst [-i INPUT] [-o OUTPUT] [name=value ...] + $ varst [-i INPUT] [-o OUTPUT] [name=value ...] License ------- diff --git a/docs/source/index.rst b/docs/source/index.rst index f3d1109..77f22dc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -16,7 +16,7 @@ Usage .. code:: bash - varst [-i INPUT] [-o OUTPUT] [name=value ...] + $ varst [-i INPUT] [-o OUTPUT] [name=value ...] API documentation