Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use re.match for regexes in traceability_hyperlink_colors #311

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions mlx/traceability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,9 +215,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']:
Expand Down
2 changes: 1 addition & 1 deletion mlx/traceable_base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down