Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyCommandCenter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Starcraft AI Course
PyCommandCenter
Commits
d9b2d0d2
There was an error fetching the commit references. Please try again later.
Commit
d9b2d0d2
authored
10 months ago
by
David Warnquist
Browse files
Options
Downloads
Patches
Plain Diff
Feat: docs now show in autocomplete
parent
dcf1e3ca
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
generate_pydocs.py
+79
-0
79 additions, 0 deletions
generate_pydocs.py
with
80 additions
and
0 deletions
README.md
+
1
−
0
View file @
d9b2d0d2
...
...
@@ -104,6 +104,7 @@ Make sure you have mypy installed. Navigate to where your library.pyd/so is loca
```
terminal
stubgen -m library -o .
```
After creating the .pyi file run the generate_pydocs.py file according to the instructions in that file.
# How to use the library with PyCharm
...
...
This diff is collapsed.
Click to expand it.
generate_pydocs.py
0 → 100644
+
79
−
0
View file @
d9b2d0d2
"""
This file inserts the docs of each class and method into the pyi file for autocompletetion.
Before running make sure you have created the pyi according to the README.
You might need to change the pyi_path.
Then simply run this file.
After running all the docs should have been inserted but YOU
'
RE NOT DONE YET.
You need to fix the intedention at the two bottom function of the pyi file.
Now you
'
re done and can enjoy working autocompletion of this library.
"""
import
sys
import
inspect
import
re
sys
.
path
.
append
(
'
build/python-api-src
'
)
import
library
def
update_pyi_with_docstrings
(
pyi_path
):
"""
Update the .pyi file with docstrings from the corresponding library.
Args:
pyi_path (str): The path to the .pyi file.
Returns:
None
"""
with
open
(
pyi_path
,
'
r
'
)
as
file
:
lines
=
file
.
readlines
()
new_lines
=
[]
known_def
=
{}
#To keep track of docs to class methods
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
if
line
.
strip
().
startswith
(
'
class
'
):
new_lines
.
append
(
line
)
if
not
line
.
strip
().
endswith
(
"
ID:
"
):
class_name
=
re
.
split
(
r
'
[\(: ]
'
,
line
)[
1
]
docstring
=
inspect
.
getdoc
(
getattr
(
library
,
class_name
))
new_lines
.
append
(
f
'
"""
{
docstring
}
"""
\n
'
)
for
func
in
dir
(
getattr
(
library
,
class_name
)):
if
func
.
startswith
(
"
__
"
):
continue
func_docs
=
inspect
.
getdoc
(
getattr
(
getattr
(
library
,
class_name
),
func
))
known_def
[
func
]
=
func_docs
elif
line
.
strip
().
startswith
(
'
def
'
):
new_lines
.
append
(
line
[:
-
4
])
func_name
=
re
.
split
(
r
'
[\(: ]
'
,
line
.
strip
())[
1
]
if
func_name
.
startswith
(
"
__
"
):
new_lines
.
append
(
f
'
{
line
[
-
4
:
]
}
'
)
continue
elif
func_name
in
known_def
:
new_lines
.
append
(
f
'
\n
"""
{
known_def
[
func_name
]
}
"""
\n
'
)
new_lines
.
append
(
f
'
{
line
[
-
4
:
]
}
'
)
continue
else
:
try
:
func_doc
=
inspect
.
getdoc
(
getattr
(
library
,
func_name
))
new_lines
.
append
(
f
'
\n
"""
{
func_doc
}
"""
\n
'
)
new_lines
.
append
(
f
'
{
line
[
-
4
:
]
}
'
)
continue
except
AttributeError
:
new_lines
.
append
(
f
'
\n
"""
not found
"""
\n
'
)
new_lines
.
append
(
f
'
{
line
[
-
4
:
]
}
'
)
continue
else
:
new_lines
.
append
(
line
)
# Write the updated content back to the .pyi file
with
open
(
pyi_path
,
'
w
'
)
as
file
:
file
.
writelines
(
new_lines
)
# Path to the generated .pyi file
pyi_file_path
=
'
build/python-api-src/library.pyi
'
update_pyi_with_docstrings
(
pyi_file_path
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment