From a0373368e42f27eba55f0bb09c2a7346c42af573 Mon Sep 17 00:00:00 2001 From: David-Le-Nir <97294334+David-Le-Nir@users.noreply.github.com> Date: Mon, 26 Feb 2024 10:12:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Exclude=20external=20needs=20fro?= =?UTF-8?q?m=20`needs=5Fid=5Fregex`=20check=20(#1108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix for [#1099](https://github.com/useblocks/sphinx-needs/issues/1099) --------- Co-authored-by: Chris Sewell --- .gitignore | 2 ++ docs/changelog.rst | 9 +++++++++ sphinx_needs/api/need.py | 6 +++++- tests/doc_test/doc_needs_external_needs/conf.py | 3 +++ tests/doc_test/doc_needs_external_needs/index.rst | 5 +++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4ab112d7d..40b2679d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .idea +*.iml +.DS_Store .venv* .pvenv .nox diff --git a/docs/changelog.rst b/docs/changelog.rst index ed001362d..a85dc0f85 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,15 @@ License .. include:: ../LICENSE +Unreleased +---------- + +Fixed +..... + +* Fix external needs identifier checked by regex (`#1099 `_) + + 2.0.0 ----- diff --git a/sphinx_needs/api/need.py b/sphinx_needs/api/need.py index ec5c39f7a..14f2f30a8 100644 --- a/sphinx_needs/api/need.py +++ b/sphinx_needs/api/need.py @@ -196,7 +196,11 @@ def run(): else: need_id = id - if needs_config.id_regex and not re.match(needs_config.id_regex, need_id): + if ( + needs_config.id_regex + and not is_external + and not re.match(needs_config.id_regex, need_id) + ): raise NeedsInvalidException( f"Given ID '{need_id}' does not match configured regex '{needs_config.id_regex}'" ) diff --git a/tests/doc_test/doc_needs_external_needs/conf.py b/tests/doc_test/doc_needs_external_needs/conf.py index 2d787751d..125a0457e 100644 --- a/tests/doc_test/doc_needs_external_needs/conf.py +++ b/tests/doc_test/doc_needs_external_needs/conf.py @@ -48,3 +48,6 @@ "id_prefix": "ext_rel_path_", }, ] + +# we want to ensure only internal needs are checked against this regex, not the external ones +needs_id_regex = "INTERNAL.*" diff --git a/tests/doc_test/doc_needs_external_needs/index.rst b/tests/doc_test/doc_needs_external_needs/index.rst index 72c82c2f6..0de2703c1 100644 --- a/tests/doc_test/doc_needs_external_needs/index.rst +++ b/tests/doc_test/doc_needs_external_needs/index.rst @@ -1,6 +1,11 @@ TEST DOCUMENT NEEDS EXTERNAL NEEDS ================================== +.. spec:: Internal need + :id: INTERNAL_001 + + An internal requirement with an id check by the regex. External needs identifiers shall not be checked for regex matching. + .. needlist:: :tags: ext_test