Skip to content

Commit 0cbf880

Browse files
committed
factor out regex pattern
1 parent de9e184 commit 0cbf880

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/service-library/src/servicelib/utils_meta.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from packaging.version import Version
88
from pydantic import TypeAdapter
99

10+
_APP_NAME_PATTERN = re.compile(
11+
r"^[a-z]+(-[a-z]+)*$"
12+
) # matches lowercase string with words separated by dashes (no whitespace)
13+
1014

1115
class PackageInfo:
1216
"""Thin wrapper around pgk_resources.Distribution to access package distribution metadata
@@ -29,7 +33,7 @@ def __init__(self, package_name: str):
2933
"""
3034
self._distribution = distribution(package_name)
3135
# property checks
32-
if re.match(r"^[a-z]+(-[a-z]+)*$", self.app_name) is None:
36+
if re.match(_APP_NAME_PATTERN, self.app_name) is None:
3337
raise ValueError(
3438
f"Invalid package name {self.app_name}. "
3539
"It must be all lowercase and words separated by dashes ('-')."

0 commit comments

Comments
 (0)