Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
RustPython/scripts/generate_docs.py at main · mode9/RustPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mode9
/
RustPython
Public
forked from
RustPython/RustPython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
RustPython
/
scripts
/
generate_docs.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
133 lines (106 loc) · 3.76 KB
main
Breadcrumbs
RustPython
/
scripts
/
generate_docs.py
Copy path
Top
File metadata and controls
Code
Blame
133 lines (106 loc) · 3.76 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import
sys
import
warnings
from
pydoc
import
ModuleScanner
def
scan_modules
():
"""taken from the source code of help('modules')
https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Lib/pydoc.py#L2178"""
modules
=
{}
def
callback
(
path
,
modname
,
desc
,
modules
=
modules
):
if
modname
and
modname
[
-
9
:]
==
".__init__"
:
modname
=
modname
[:
-
9
]
+
" (package)"
if
modname
.
find
(
"."
)
<
0
:
modules
[
modname
]
=
1
def
onerror
(
modname
):
callback
(
None
,
modname
,
None
)
with
warnings
.
catch_warnings
():
# ignore warnings from importing deprecated modules
warnings
.
simplefilter
(
"ignore"
)
ModuleScanner
().
run
(
callback
,
onerror
=
onerror
)
return
list
(
modules
.
keys
())
def
import_module
(
module_name
):
import
io
from
contextlib
import
redirect_stdout
# Importing modules causes ('Constant String', 2, None, 4) and
# "Hello world!" to be printed to stdout.
f
=
io
.
StringIO
()
with
warnings
.
catch_warnings
(),
redirect_stdout
(
f
):
# ignore warnings caused by importing deprecated modules
warnings
.
filterwarnings
(
"ignore"
,
category
=
DeprecationWarning
)
try
:
module
=
__import__
(
module_name
)
except
Exception
as
e
:
return
e
return
module
def
is_child
(
module
,
item
):
import
inspect
item_mod
=
inspect
.
getmodule
(
item
)
return
item_mod
is
module
def
traverse
(
module
,
names
,
item
):
import
inspect
has_doc
=
inspect
.
ismodule
(
item
)
or
inspect
.
isclass
(
item
)
or
inspect
.
isbuiltin
(
item
)
if
has_doc
and
isinstance
(
item
.
__doc__
,
str
):
yield
names
,
item
.
__doc__
attr_names
=
dir
(
item
)
for
name
in
attr_names
:
if
name
in
[
"__class__"
,
"__dict__"
,
"__doc__"
,
"__objclass__"
,
"__name__"
,
"__qualname__"
,
"__annotations__"
,
]:
continue
try
:
attr
=
getattr
(
item
,
name
)
except
AttributeError
:
assert
name
==
"__abstractmethods__"
,
name
continue
if
module
is
item
and
not
is_child
(
module
,
attr
):
continue
is_type_or_module
=
(
type
(
attr
)
is
type
)
or
(
type
(
attr
)
is
type
(
__builtins__
))
new_names
=
names
.
copy
()
new_names
.
append
(
name
)
if
item
==
attr
:
pass
elif
not
inspect
.
ismodule
(
item
)
and
inspect
.
ismodule
(
attr
):
pass
elif
is_type_or_module
:
yield
from
traverse
(
module
,
new_names
,
attr
)
elif
(
callable
(
attr
)
or
not
issubclass
(
type
(
attr
),
type
)
or
type
(
attr
).
__name__
in
(
"getset_descriptor"
,
"member_descriptor"
)
):
if
inspect
.
isbuiltin
(
attr
):
yield
new_names
,
attr
.
__doc__
else
:
assert
False
, (
module
,
new_names
,
attr
,
type
(
attr
).
__name__
)
def
traverse_all
():
for
module_name
in
scan_modules
():
if
module_name
in
(
"this"
,
"antigravity"
):
continue
module
=
import_module
(
module_name
)
if
hasattr
(
module
,
"__cached__"
):
# python module
continue
yield
from
traverse
(
module
, [
module_name
],
module
)
def
docs
():
return
((
"."
.
join
(
names
),
doc
)
for
names
,
doc
in
traverse_all
())
if
__name__
==
"__main__"
:
import
sys
import
json
try
:
out_path
=
sys
.
argv
[
1
]
except
IndexError
:
out_path
=
"-"
def
dump
(
docs
):
yield
"[
\n
"
for
name
,
doc
in
docs
:
if
doc
is
None
:
yield
f" (
{
json
.
dumps
(
name
)
}
, None),
\n
"
else
:
yield
f" (
{
json
.
dumps
(
name
)
}
, Some(
{
json
.
dumps
(
doc
)
}
)),
\n
"
yield
"]
\n
"
out_file
=
open
(
out_path
,
"w"
)
if
out_path
!=
"-"
else
sys
.
stdout
out_file
.
writelines
(
dump
(
docs
()))
You can’t perform that action at this time.