Skip to content

Commit 61318d9

Browse files
committed
Adding pattern matching examples and fetching only the target, ignoring option
Signed-off-by: Sachin Pisal <[email protected]>
1 parent 8c7fe03 commit 61318d9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

docs/notebook_validation.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@ def read_available_backends():
2525
return [backend.strip() for backend in available_backends]
2626

2727

28-
pattern = r'set_target\(\s*\\"([^"]+)\\"(?:\s*,\s*option\s*=\s*\\"([^"]+)\\")?'
28+
# Following pattern matches
29+
# set_target("abc")
30+
# set_target( "abc")
31+
# set_target("abc", option="xyz")
32+
# set_target("abc", option = "xyz")
33+
# set_target(\"abc\")
34+
# set_target( \"abc\")
35+
# set_target(\"abc\", option=\"xyz\")
36+
# set_target(\"abc\", option = \"xyz\")
37+
# set_target('abc')
38+
# set_target( 'abc')
39+
# set_target('abc', option='xyz')
40+
# set_target('abc', option = 'xyz')
41+
pattern = r"set_target\(\s*(\\?['\"])([^'\"]+)\1(?:\s*,\s*option\s*=\s*(\\?['\"])([^'\"]+)\3)?\)"
2942

3043

3144
def validate(notebook_filename, available_backends):
@@ -37,10 +50,8 @@ def validate(notebook_filename, available_backends):
3750

3851
match = re.search(pattern, notebook_content)
3952
if match:
40-
target = match.group(1)
41-
opt = match.group(2)
42-
combined = f"{target}-{opt}" if opt else target
43-
return combined in available_backends
53+
target = match.group(2)
54+
return target in available_backends
4455
for notebook_content in lines:
4556
match = re.search('--target ([^ ]+)', notebook_content)
4657
if match and (match.group(1) not in available_backends):

0 commit comments

Comments
 (0)