Skip to content
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
5 changes: 3 additions & 2 deletions src/ssvc/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
# subject to its own license.
# DM24-0278

import re
from enum import StrEnum

from ssvc.utils.defaults import MAX_NS_LENGTH, MIN_NS_LENGTH, X_PFX
from ssvc.utils.patterns import NS_PATTERN
from ssvc.utils.patterns import NS_PATTERN_STR

EXT_SEP = "/"
FRAG_SEP = "#"
Expand Down Expand Up @@ -86,7 +87,7 @@ def validate(cls, value: str) -> str:
ValueError: if the value is not a valid namespace

"""
valid = NS_PATTERN.match(value)
valid = re.match(NS_PATTERN_STR, value)

if valid:
# pattern matches, so we can proceed with further checks
Expand Down
4 changes: 2 additions & 2 deletions src/ssvc/utils/field_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pydantic import Field

from ssvc.utils.defaults import MAX_NS_LENGTH, MIN_NS_LENGTH
from ssvc.utils.patterns import NS_PATTERN, VERSION_PATTERN
from ssvc.utils.patterns import NS_PATTERN_STR, VERSION_PATTERN

VersionString = Annotated[
str,
Expand All @@ -50,7 +50,7 @@
"x_example.test#test//.example.test#private-extension",
"ssvc/de-DE/.example.organization#reference-arch-1",
],
pattern=NS_PATTERN.pattern,
pattern=NS_PATTERN_STR,
min_length=MIN_NS_LENGTH,
max_length=MAX_NS_LENGTH,
),
Expand Down
4 changes: 0 additions & 4 deletions src/ssvc/utils/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# subject to its own license.
# DM24-0278

import re

# from https://semver.org/
VERSION_PATTERN = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
"""A regular expression pattern for semantic versioning (semver)."""
Expand Down Expand Up @@ -81,5 +79,3 @@

# --- Combine all parts into the full namespace pattern ---
NS_PATTERN_STR = rf"^{namespace}$"

NS_PATTERN = re.compile(NS_PATTERN_STR)
10 changes: 5 additions & 5 deletions src/test/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# This Software includes and/or makes use of Third-Party Software each
# subject to its own license.
# DM24-0278

import re
import unittest

from ssvc.namespaces import NameSpace, RESERVED_NS
from ssvc.utils.patterns import NS_PATTERN
from ssvc.utils.patterns import NS_PATTERN_STR


class MyTestCase(unittest.TestCase):
Expand All @@ -41,7 +41,7 @@ def test_ns_pattern(self):

for ns in should_match:
with self.subTest(ns=ns):
self.assertTrue(NS_PATTERN.match(ns), ns)
self.assertTrue(re.match(NS_PATTERN_STR, ns), ns)

should_not_match = [
"",
Expand All @@ -62,8 +62,8 @@ def test_ns_pattern(self):
failures = []
for ns in should_not_match:
with self.subTest(ns=ns):
# re.search() to catch if NS_PATTERN is not anchored at start
match = NS_PATTERN.search(ns)
# re.search() to catch if NS_PATTERN_STR is not anchored at start
match = re.search(NS_PATTERN_STR, ns)
if match:
failures.append(
f"Unexpected match for '{ns}': {match.group(0)}"
Expand Down
4 changes: 2 additions & 2 deletions src/test/test_namespaces_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
BASE_PATTERN,
EXT_SEGMENT_PATTERN,
LENGTH_CHECK_PATTERN,
NS_PATTERN,
NS_PATTERN_STR,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,7 +98,7 @@ def setUp(self):

def test_ns_pattern(self):
self._test_successes_failures(
NS_PATTERN.pattern, self.expect_fail, self.expect_success
NS_PATTERN_STR, self.expect_fail, self.expect_success
)

def test_base_pattern(self):
Expand Down
4 changes: 2 additions & 2 deletions src/test/test_selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from ssvc import selection
from ssvc.selection import MinimalDecisionPointValue, SelectionList
from ssvc.utils.patterns import NS_PATTERN, VERSION_PATTERN
from ssvc.utils.patterns import NS_PATTERN_STR, VERSION_PATTERN


class MyTestCase(unittest.TestCase):
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_minimal_selection_init(self):
self.assertIsInstance(self.s1.namespace, str)
self.assertRegex(
self.s1.namespace,
NS_PATTERN,
NS_PATTERN_STR,
"Namespace does not match the required pattern",
)

Expand Down
Loading