From 0635603946c9ac758bc4437e8958d05623a7fbae Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:26:41 +0200 Subject: [PATCH 1/2] Use re.match instead of re.search for regexes in traceability_hyperlink_colors --- doc/configuration.rst | 18 ++++++------------ mlx/traceability.py | 3 --- mlx/traceable_base_node.py | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 32bb3243..68108b61 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -354,25 +354,20 @@ Custom colors for linked items ------------------------------ The plugin allows customization of the colors of traceable items in order to easily recognize the type of item which is -linked to. A dictionary in the configuration file defines the regexp, which is used to search_ item IDs, as key and a +linked to. A dictionary in the configuration file defines the regexp, which is used to match_ item IDs, as key and a tuple of 1-3 color defining strings as value. The first color is used for the default hyperlink state, the second color is used for the hover and active states, and the third color is used to override the default color of the visited state. Leaving a color empty results in the use of the default html style. The top regexp has the highest priority. To support Python versions lower than 3.7, we use an :code:`OrderedDict` to have a deterministic order for prioritizing regexes. -.. warning:: - - In version 9.0.0, the regular expressions in `traceability_hyperlink_colors` will be used to match_ item IDs - instead of search_. This way, all regexes will be handled the same way by this plugin. - .. code-block:: python traceability_hyperlink_colors = OrderedDict([ - (r'^(RQT|r[\d]+', ('#7F00FF', '#b369ff')), - (r'^[IU]TEST_REP', ('rgba(255, 0, 0, 1)', 'rgba(255, 0, 0, 0.7)', 'rgb(200, 0, 0)')), - (r'^[IU]TEST', ('goldenrod', 'hsl(43, 62%, 58%)', 'darkgoldenrod')), - (r'^SYS_', ('', 'springgreen', '')), - (r'^SRS_', ('', 'orange', '')), + (r'(RQT|r[\d]+', ('#7F00FF', '#b369ff')), + (r'[IU]TEST_REP', ('rgba(255, 0, 0, 1)', 'rgba(255, 0, 0, 0.7)', 'rgb(200, 0, 0)')), + (r'[IU]TEST', ('goldenrod', 'hsl(43, 62%, 58%)', 'darkgoldenrod')), + (r'SYS_', ('', 'springgreen', '')), + (r'SRS_', ('', 'orange', '')), ]) .. _traceability_notifications: @@ -475,4 +470,3 @@ per documentation object: traceability_render_relationship_per_item = False .. _match: https://docs.python.org/3/library/re.html#re.match -.. _search: https://docs.python.org/3/library/re.html#re.search diff --git a/mlx/traceability.py b/mlx/traceability.py index 423ddb10..8aa25d5b 100644 --- a/mlx/traceability.py +++ b/mlx/traceability.py @@ -216,9 +216,6 @@ def perform_consistency_check(app, env): if app.config.traceability_hyperlink_colors: app.add_css_file('hyperlink_colors.css') generate_color_css(app, app.config.traceability_hyperlink_colors) - if [regex for regex in app.config.traceability_hyperlink_colors if not regex.startswith('^')]: - warnings.warn('Regexes in traceability_hyperlink_colors will be handled by re.match instead of re.search ' - 'in mlx.traceability>=9', DeprecationWarning) regex = app.config.traceability_checklist.get('checklist_item_regex') if regex is not None and app.config.traceability_checklist['has_checklist_items']: diff --git a/mlx/traceable_base_node.py b/mlx/traceable_base_node.py index 02c6f284..feed27f9 100644 --- a/mlx/traceable_base_node.py +++ b/mlx/traceable_base_node.py @@ -194,7 +194,7 @@ def _find_colors_for_class(hyperlink_colors, item_id): """ for regex, colors in hyperlink_colors.items(): colors = tuple(colors) - if re.search(regex, item_id): + if re.match(regex, item_id): return tuple(colors) return None From d47c3078cbae864802ce3dd72ea2237061e89f78 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Thu, 10 Nov 2022 13:03:52 +0100 Subject: [PATCH 2/2] Remove unused import 'warnings' --- mlx/traceability.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mlx/traceability.py b/mlx/traceability.py index 3bc2391d..d7c5afa4 100644 --- a/mlx/traceability.py +++ b/mlx/traceability.py @@ -6,7 +6,6 @@ Sphinx extension for reStructuredText that added traceable documentation items. See readme for more details. """ -import warnings from collections import namedtuple from re import fullmatch, match from os import path