From 5097bad50dea4b2ba73429a0208955db694f3957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pollersp=C3=B6ck?= Date: Wed, 26 Mar 2025 14:44:44 +0100 Subject: [PATCH 1/6] Update requirements.txt added regex depenency --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 67c0e4f2..aec44765 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ pypandoc GenPackageDoc PythonExtensionsCollection pydotdict +regex From 8ac200496f1b1ecc1e19b1cb6e5e05aae8a41e75 Mon Sep 17 00:00:00 2001 From: ngoan1608 Date: Fri, 28 Mar 2025 10:45:39 +0700 Subject: [PATCH 2/6] allow to trigger 'Publish JsonPreprocessor to PyPI' workflow manually --- .github/workflows/python-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 6307095a..a7b79968 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -5,6 +5,7 @@ on: tags: - "rel/*.*.*" - "rel/*.*.*.*" + workflow_dispatch: jobs: build-n-publish: From 8d1365e2aebe8e4578a46ac08d3426ff947632a8 Mon Sep 17 00:00:00 2001 From: ngoan1608 Date: Fri, 28 Mar 2025 11:16:38 +0700 Subject: [PATCH 3/6] add workflow inputs 'tag_name' for creating GitHub Release when triggering manually --- .github/workflows/python-publish.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index a7b79968..f166f341 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -6,6 +6,11 @@ on: - "rel/*.*.*" - "rel/*.*.*.*" workflow_dispatch: + inputs: + tag_name: + description: 'Release Tag name for creating Github Release' + required: false + type: string jobs: build-n-publish: @@ -44,10 +49,29 @@ jobs: password: ${{ secrets.PYPI_API_TOKEN }} # This token should be created in Settings > Secrets > Actions # repository_url: https://test.pypi.org/legacy/ # Use this for testing to upload the distribution to test.pypi + - name: Determine tag + id: tag + run: | + TAG_NAME="" + if [[ "${{ github.event.inputs.tag_name }}" != "" ]]; then + TAG_NAME="${{ github.event.inputs.tag_name }}" + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then + TAG_NAME="${GITHUB_REF#refs/tags/}" + fi + + if [[ -z "$TAG_NAME" ]]; then + echo "No valid tag provided. Skipping release." + exit 0 + else + echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV + fi + - name: Create/Update GitHub Release id: create_update_release + if: env.TAG_NAME != '' uses: ncipollo/release-action@v1 with: + tag: ${{ env.TAG_NAME }} allowUpdates: true omitNameDuringUpdate: true makeLatest: true From 2e82dc21f8c8208696c67976b55cabb55e09c063 Mon Sep 17 00:00:00 2001 From: qth2hi Date: Mon, 7 Apr 2025 17:18:57 +0200 Subject: [PATCH 4/6] Maintenance of release info --- .../release_items_JsonPreprocessor.json | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/config/robotframework_aio/release_items_JsonPreprocessor.json b/config/robotframework_aio/release_items_JsonPreprocessor.json index 7dc2ce7c..33f2ebb8 100644 --- a/config/robotframework_aio/release_items_JsonPreprocessor.json +++ b/config/robotframework_aio/release_items_JsonPreprocessor.json @@ -178,25 +178,29 @@ ], "0.14.1.;0.15.0." : [ " -* Allowed users define a naming convention rule key names within JSONP content processed by the **JsonPreprocessor** +**Updated naming convention check** - The input parameter ``keyPattern`` is used to define the key name pattern and the ``keyPattern`` is set by users + The **JsonPreprocessor** supports a user-defined convention for key names. This is enforced using a regex pattern + passed to the constructor of the **JsonPreprocessor** class. - **Example:** - - | ``json_preprocessor = CJsonPreprocessor()`` + *Example* - The ``keyPattern`` is not set when initialized ``CJsonPreprocessor``, the naming convention check is not acitve. + Assuming key names may only contain letters and digits but must start with a letter, then the **JsonPreprocessor** + has to be initialized in this way: | ``json_preprocessor = CJsonPreprocessor(keyPattern=r'^[\\p{L}][\\p{L}0-9]*$')`` - The ``keyPattern`` is set ``'^[\\p{L}][\\p{L}0-9]*$'`` means key names in the JONP file have to start with characters and following by characters or numbers. + This feature is an option. If the user does not define the parameter ``keyPattern``, key names can contain any characters (but cannot be empty). -* Replaced ``re`` package by ``regex`` package to handle regular expression. + *Example* -* Improved and aligned error messages + | ``json_preprocessor = CJsonPreprocessor()`` + +**Maintenance** -* Added and updated the Selftest according to the changes +* Replaced ``re`` package by ``regex`` package to handle extended regular expressions +* Improved and aligned error messages +* Added and updated the self test according to the changed features " ] } From 2f7ac853747f162c207e69c6b9c37c04dcf4fd40 Mon Sep 17 00:00:00 2001 From: qth2hi Date: Mon, 7 Apr 2025 18:45:52 +0200 Subject: [PATCH 5/6] Maintenance of release info (added missing underscore) --- config/robotframework_aio/release_items_JsonPreprocessor.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/robotframework_aio/release_items_JsonPreprocessor.json b/config/robotframework_aio/release_items_JsonPreprocessor.json index 33f2ebb8..eed99492 100644 --- a/config/robotframework_aio/release_items_JsonPreprocessor.json +++ b/config/robotframework_aio/release_items_JsonPreprocessor.json @@ -185,10 +185,10 @@ *Example* - Assuming key names may only contain letters and digits but must start with a letter, then the **JsonPreprocessor** + Assuming key names may only contain letters, digits and underscores, but must start with a letter, then the **JsonPreprocessor** has to be initialized in this way: - | ``json_preprocessor = CJsonPreprocessor(keyPattern=r'^[\\p{L}][\\p{L}0-9]*$')`` + | ``json_preprocessor = CJsonPreprocessor(keyPattern=r'^[\\p{L}][\\p{L}0-9_]*$')`` This feature is an option. If the user does not define the parameter ``keyPattern``, key names can contain any characters (but cannot be empty). From d639517760fe7d54c2c5aa29125f6330db477417 Mon Sep 17 00:00:00 2001 From: qth2hi Date: Tue, 8 Apr 2025 16:46:26 +0200 Subject: [PATCH 6/6] Update of documentation (naming convention) --- .../release_items_JsonPreprocessor.json | 2 +- packagedoc/additional_docs/Description.tex | 32 +++++++++++++++++++ packagedoc/additional_docs/History.tex | 2 +- packagedoc/additional_docs/Introduction.tex | 2 +- .../additional_docs/The JSONP format.tex | 14 -------- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/config/robotframework_aio/release_items_JsonPreprocessor.json b/config/robotframework_aio/release_items_JsonPreprocessor.json index eed99492..f3d771c8 100644 --- a/config/robotframework_aio/release_items_JsonPreprocessor.json +++ b/config/robotframework_aio/release_items_JsonPreprocessor.json @@ -188,7 +188,7 @@ Assuming key names may only contain letters, digits and underscores, but must start with a letter, then the **JsonPreprocessor** has to be initialized in this way: - | ``json_preprocessor = CJsonPreprocessor(keyPattern=r'^[\\p{L}][\\p{L}0-9_]*$')`` + | ``json_preprocessor = CJsonPreprocessor(keyPattern=r'^\\p{L}[\\p{L}\\p{Nd}_]*$')`` This feature is an option. If the user does not define the parameter ``keyPattern``, key names can contain any characters (but cannot be empty). diff --git a/packagedoc/additional_docs/Description.tex b/packagedoc/additional_docs/Description.tex index 0d038ab5..e60d2fe1 100644 --- a/packagedoc/additional_docs/Description.tex +++ b/packagedoc/additional_docs/Description.tex @@ -45,6 +45,38 @@ \section{How to execute} In chapter \hyperref[thejsonpformat]{The JSONP format} the format of JSON files used by the \pkg, is described in detail. All discussed JSON files can be tested with the example script listed above. +% -------------------------------------------------------------------------------------------------------------- + +\newpage + +\section{User defined naming convention} + +By default, key names in JSON files can contain any characters (but cannot be empty). But it might be required to limit the character set. +For this purpose the \pkg\ supports an optional user-defined convention for key names. This is enforced using a \pcode{regex} pattern +passed to the constructor of the \pkg\ class. + +Assuming key names may only contain letters, digits and underscores, but must start with a letter, then the \pkg\ has to be initialized +in this way: + +\begin{pythoncode}[linebackgroundcolor=\hlcode{3,5}] +from JsonPreprocessor.CJsonPreprocessor import CJsonPreprocessor +import pprint +import regex + +json_preprocessor = CJsonPreprocessor(keyPattern=r'^\p{L}[\p{L}\p{Nd}_]*$')) +try: + values = json_preprocessor.jsonLoad("./file.jsonp") + pprint.pprint(values) +except Exception as reason: + print(f"'{reason}'") +\end{pythoncode} + +The regular expressions \pcode{\\p\{L\}} and \pcode{\\p\{Nd\}} are provided by the \pcode{regex} module: + +\begin{itemize} + \item \pcode{\\p\{L\}} matches all Unicode characters classified as \textbf{letter} + \item \pcode{\\p\{Nd\}} matches all Unicode characters classified as \textbf{decimal digit} +\end{itemize} % -------------------------------------------------------------------------------------------------------------- diff --git a/packagedoc/additional_docs/History.tex b/packagedoc/additional_docs/History.tex index b99ff7d8..bd6f11cc 100644 --- a/packagedoc/additional_docs/History.tex +++ b/packagedoc/additional_docs/History.tex @@ -96,7 +96,7 @@ \historychange{- Fixed bugs, updated error messages, and improved composite data structure handling} \historyversiondate{0.9.0}{03/2025} -\historychange{- Allowed users define a naming convention rule key names\newline +\historychange{- Added support of a user-defined convention for key names\newline - Improved and aligned error messages\newline - Fixed bugs and updated the Selftest according to the changes} diff --git a/packagedoc/additional_docs/Introduction.tex b/packagedoc/additional_docs/Introduction.tex index e4c82f9b..aaf1244e 100644 --- a/packagedoc/additional_docs/Introduction.tex +++ b/packagedoc/additional_docs/Introduction.tex @@ -45,7 +45,7 @@ These deviations harm the syntax highlighting of editors and also cause invalid findings of JSON format related static code checkers. To avoid conflicts between the standard JSON format and the extended JSON format described here, the \pkg\ uses the alternative file extension -\pcode{.jsonp} for all JSON files. +\pcode{.jsonp} for all JSON files of extended format. \newpage diff --git a/packagedoc/additional_docs/The JSONP format.tex b/packagedoc/additional_docs/The JSONP format.tex index 021df5f3..70e87483 100644 --- a/packagedoc/additional_docs/The JSONP format.tex +++ b/packagedoc/additional_docs/The JSONP format.tex @@ -151,20 +151,6 @@ \section{Comments} {'testlist': ['A1', 'D4']} \end{pythonlog} -\vspace{2ex} - -\section{Naming convention} - -All key names in JSONP files must adhere to the following rules: - -\begin{itemize} - \item Key names can only consist of letters, digits and the following special characters: \pcode{_ + - * / \\\\ @} - (\textit{backslashes are allowed but have to be masked}). - \item Key names have to start with a letter, a digit or an underscore. - \item Key names must not be empty strings. But leading and trailing blanks will be removed (and therefore do not cause errors). - Also blanks in between allowed characters are not allowed. -\end{itemize} - % -------------------------------------------------------------------------------------------------------------- \newpage