Skip to content

Commit bf6157f

Browse files
committed
♻️ refactor(pep723): verbose regex and covdefaults pragmas
1 parent d758806 commit bf6157f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/tox/tox_env/python/virtual_env/pep723.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55
import re
66
import sys
77
from dataclasses import dataclass, field
8+
from typing import Final
89

9-
if sys.version_info >= (3, 11):
10+
if sys.version_info >= (3, 11): # pragma: >=3.11 cover
1011
import tomllib
11-
else:
12+
else: # pragma: <3.11 cover
1213
import tomli as tomllib
1314

1415

15-
SCRIPT_METADATA_RE = re.compile(
16-
r"(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$",
16+
SCRIPT_METADATA_RE: Final = re.compile(
17+
r"""
18+
(?m)
19+
^[#][ ]///[ ](?P<type>[a-zA-Z0-9-]+)$ # opening: # /// <type>
20+
\s # blank line or whitespace
21+
(?P<content> # TOML content lines:
22+
(?:^[#](?:| .*)$\s)+ # each line starts with # (optionally followed by space + text)
23+
)
24+
^[#][ ]///$ # closing: # ///
25+
""",
26+
re.VERBOSE,
1727
)
1828

1929

0 commit comments

Comments
 (0)