Skip to content

Commit cd961eb

Browse files
author
Murilo Marinho
committed
[stubs] Adjuting automatic generated stubs to follow the necessary folder structure pattern.
1 parent 2fbd804 commit cd961eb

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.github/workflows/python_package.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ jobs:
5959
run: |
6060
pip install pybind11-stubgen
6161
pip install .
62-
pybind11-stubgen dqrobotics --output-dir dqrobotics-stubs
62+
mkdir -p stubs_temp
63+
pybind11-stubgen dqrobotics --output-dir stubs_temp
64+
python renegerate_stubs.py
65+
cp -r stubs_temp/dqrobotics/dqrobotics/ dqrobotics-stubs
6366
pip uninstall dqrobotics -y
6467
- name: Compile
6568
run: |

regenerate_stubs.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Fix the stubs created by pybind11-stubgen
3+
4+
The default version of pybind11 stubgen will generate something like
5+
6+
.
7+
└── dqrobotics
8+
├── __init__.pyi
9+
└── _dqrobotics
10+
├── __init__.pyi
11+
├── _interfaces
12+
│   ├── __init__.pyi
13+
│   └── _json11.pyi
14+
├── _robot_control.pyi
15+
├── _robot_modeling.pyi
16+
├── _robots.pyi
17+
├── _solvers.pyi
18+
└── _utils
19+
├── _DQ_LinearAlgebra.pyi
20+
├── _DQ_Math.pyi
21+
└── __init__.pyi
22+
23+
which is not compatible with dqrobotics' structure. It's not clear to me why that's the case.
24+
This script will adjust it to something like below, which make the stubs quite useful.
25+
26+
.
27+
├── README.md
28+
├── __init__.pyi
29+
├── interfaces
30+
│   ├── __init__.pyi
31+
│   └── json11
32+
│   └── __init__.py
33+
├── robot_control
34+
│   └── __init__.py
35+
├── robot_modeling
36+
│   └── __init__.py
37+
├── robots
38+
│   └── __init__.py
39+
├── solvers
40+
│   └── __init__.py
41+
└── utils
42+
├── DQ_LinearAlgebra
43+
│   └── __init__.py
44+
├── DQ_Math
45+
│   └── __init__.py
46+
└── __init__.pyi
47+
48+
Author: Murilo M. Marinho
49+
"""
50+
51+
import os
52+
53+
def main():
54+
cwd = os.path.join(os.getcwd(),"stubs_temp")
55+
for root, dirs, files in os.walk(cwd, topdown=False):
56+
for name in files:
57+
if name.startswith('__'):
58+
continue
59+
elif name.startswith('_') and name.endswith('.pyi'):
60+
os.makedirs(os.path.join(root, name[1:-4]), exist_ok=True)
61+
os.rename(os.path.join(root, name), os.path.join(root, name[1:-4], "__init__.py"))
62+
for name in dirs:
63+
if name.startswith('_'):
64+
os.rename(os.path.join(root, name), os.path.join(root, name[1:]))
65+
66+
if __name__ == "__main__":
67+
main()

0 commit comments

Comments
 (0)