Skip to content

Commit 1198de7

Browse files
iamaeroplaneclaude
andcommitted
refactor(extensions): extract compiled command name regex constant
Replace two raw re.match() calls with a single class-level compiled constant _COMMAND_NAME_RE. Removes duplicated pattern string and avoids recompiling the regex on every command validated during install. Also drops inline comments that restated the docstring. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ecb2478 commit 1198de7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/specify_cli/extensions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ExtensionManifest:
7676

7777
SCHEMA_VERSION = "1.0"
7878
REQUIRED_FIELDS = ["schema_version", "extension", "requires", "provides"]
79+
_COMMAND_NAME_RE = re.compile(r'^speckit\.[a-z0-9-]+\.[a-z0-9-]+$')
7980

8081
def __init__(self, manifest_path: Path):
8182
"""Load and validate extension manifest.
@@ -150,7 +151,7 @@ def _validate(self):
150151
raise ValidationError("Command missing 'name' or 'file'")
151152

152153
# Validate command name format
153-
if not re.match(r'^speckit\.[a-z0-9-]+\.[a-z0-9-]+$', cmd["name"]):
154+
if not self._COMMAND_NAME_RE.match(cmd["name"]):
154155
corrected = self._try_correct_command_name(cmd["name"], ext["id"])
155156
if corrected:
156157
self.warnings.append(
@@ -178,12 +179,10 @@ def _try_correct_command_name(name: str, ext_id: str) -> Optional[str]:
178179
parts = name.split('.')
179180
if len(parts) == 2:
180181
if parts[0] == 'speckit':
181-
# speckit.command → speckit.{ext_id}.command
182182
candidate = f"speckit.{ext_id}.{parts[1]}"
183183
else:
184-
# extension.command → speckit.extension.command
185184
candidate = f"speckit.{parts[0]}.{parts[1]}"
186-
if re.match(r'^speckit\.[a-z0-9-]+\.[a-z0-9-]+$', candidate):
185+
if ExtensionManifest._COMMAND_NAME_RE.match(candidate):
187186
return candidate
188187
return None
189188

0 commit comments

Comments
 (0)