FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdk/.github/scripts/validate_examples.py at master · sinricpro/python-sdk · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sinricpro
/
python-sdk
Public
Notifications
You must be signed in to change notification settings
Fork
9
Star
26
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sdk
/
.github
/
scripts
/
validate_examples.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (80 loc) · 2.83 KB
Breadcrumbs
python-sdk
/
.github
/
scripts
/
validate_examples.py
Copy path
File metadata and controls
99 lines (80 loc) · 2.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""Validate Python example files for syntax and imports."""
import
ast
import
importlib
import
sys
from
pathlib
import
Path
def
validate_syntax
(
file_path
:
Path
)
->
bool
:
"""Validate Python syntax of a file."""
try
:
with
open
(
file_path
,
'r'
)
as
f
:
ast
.
parse
(
f
.
read
())
print
(
f' ✓ Syntax valid:
{
file_path
}
'
)
return
True
except
SyntaxError
as
e
:
print
(
f' ✗ Syntax error in
{
file_path
}
:
{
e
}
'
)
return
False
def
validate_imports
(
file_path
:
Path
)
->
bool
:
"""Validate that sinricpro imports work."""
try
:
with
open
(
file_path
,
'r'
)
as
f
:
tree
=
ast
.
parse
(
f
.
read
())
except
SyntaxError
:
return
False
# Already reported by validate_syntax
success
=
True
for
node
in
ast
.
walk
(
tree
):
if
isinstance
(
node
,
ast
.
ImportFrom
):
if
node
.
module
and
node
.
module
.
startswith
(
'sinricpro'
):
module_name
=
node
.
module
try
:
importlib
.
import_module
(
module_name
)
print
(
f' ✓ Import OK:
{
module_name
}
'
)
except
ImportError
as
e
:
print
(
f' ✗ Failed to import
{
module_name
}
:
{
e
}
'
)
success
=
False
elif
isinstance
(
node
,
ast
.
Import
):
for
alias
in
node
.
names
:
if
alias
.
name
.
startswith
(
'sinricpro'
):
try
:
importlib
.
import_module
(
alias
.
name
)
print
(
f' ✓ Import OK:
{
alias
.
name
}
'
)
except
ImportError
as
e
:
print
(
f' ✗ Failed to import
{
alias
.
name
}
:
{
e
}
'
)
success
=
False
return
success
def
main
():
"""Main validation function."""
examples_dir
=
Path
(
'examples'
)
if
not
examples_dir
.
exists
():
print
(
f'Error:
{
examples_dir
}
directory not found'
)
sys
.
exit
(
1
)
python_files
=
sorted
(
examples_dir
.
rglob
(
'*.py'
))
if
not
python_files
:
print
(
'Warning: No Python files found in examples/'
)
sys
.
exit
(
0
)
print
(
f'Found
{
len
(
python_files
)
}
Python example files
\n
'
)
all_valid
=
True
# Check syntax
print
(
'='
*
60
)
print
(
'Validating Python syntax...'
)
print
(
'='
*
60
)
for
file_path
in
python_files
:
if
not
validate_syntax
(
file_path
):
all_valid
=
False
# Check imports
print
(
'
\n
'
+
'='
*
60
)
print
(
'Validating sinricpro imports...'
)
print
(
'='
*
60
)
for
file_path
in
python_files
:
print
(
f'
\n
Checking:
{
file_path
}
'
)
if
not
validate_imports
(
file_path
):
all_valid
=
False
print
(
'
\n
'
+
'='
*
60
)
if
all_valid
:
print
(
'✅ All examples validated successfully!'
)
sys
.
exit
(
0
)
else
:
print
(
'❌ Some examples failed validation'
)
sys
.
exit
(
1
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL