Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
setup.py
1
35
36
from
pathlib
import
Path
37
from
setuptools
import
setup
38
from
setuptools.command.install
import
install
39
import
subprocess
40
import
os
41
from
shutil
import
copy, copytree
42
43
# Your custom post-install command
44
class
StubsGenerator
():
45
def
__init__
(self):
46
print(
'Running stubs generator'
)
47
self.
output_root
= Path(__file__).parent.absolute() /
'gen'
48
self.
target_path
= Path(Path(__file__).parent.absolute() /
'visp'
)
49
self.
output_root
.mkdir(exist_ok=
True
)
50
self.
package_data
= []
51
52
53
def
run
(self):
54
self.
generate_stubs
()
55
self.
rearrange_stubs
()
56
self.
build_package_data
()
57
def
generate_stubs
(self):
58
'''
59
Call Mypy's tool to generate stubs in an temporary folder.
60
CPP stubs are first generated, then the python specific ones
61
'''
62
subprocess.run([
'stubgen'
,
'-o'
, str(self.
output_root
.absolute()),
'--ignore-errors'
,
'--include-docstrings'
,
'-p'
,
'visp._visp'
], check=
True
)
63
subprocess.run([
'stubgen'
,
'-o'
, str(self.
output_root
.absolute()),
'--ignore-errors'
,
'--include-docstrings'
,
'--parse-only'
,
'-p'
,
'visp.python'
], check=
True
)
64
65
def
rearrange_stubs
(self):
66
67
all_submodule_names = [
'python'
]
68
69
# Generate stubs for the bindings (C++ side) and mock it so that they appear in the true 'visp' package
70
cpp_stubs = Path(self.
output_root
/
'visp'
/
'_visp'
)
71
self.
target_path
.mkdir(exist_ok=
True
)
72
for
pyi_file
in
cpp_stubs.iterdir():
73
if
pyi_file.name.endswith(
'.pyi'
):
74
if
pyi_file.stem !=
'__init__'
:
75
76
all_submodule_names.append(pyi_file.stem)
77
submodule_stub_folder = self.
target_path
/ pyi_file.stem
78
submodule_stub_folder.mkdir(exist_ok=
True
)
79
submodules_stubs = submodule_stub_folder /
'__init__.pyi'
80
copy(pyi_file, submodules_stubs)
# Copy replace old files
81
82
# Add stubs for python part
83
python_stubs_path = Path(self.
output_root
/
'visp'
/
'python'
)
84
copytree(str(python_stubs_path), str(self.
target_path
/
'python'
), dirs_exist_ok=
True
)
85
86
87
# Generate a complete list of modules for the __init__ stubs
88
init_stubs_path = self.
target_path
/
'__init__.pyi'
89
with
open(init_stubs_path,
'w'
)
as
init_stubs_file:
90
# init_stubs_file.write(f'from ._visp import *{os.linesep}')
91
92
for
submodule
in
all_submodule_names:
93
init_stubs_file.write(f
'from . import {submodule}{os.linesep}'
)
94
95
def
build_package_data
(self):
96
def
package_data_rec(module: Path, l):
97
for
submodule_path
in
module.iterdir():
98
if
submodule_path.name.endswith(
'.pyi'
):
99
l.append(str(submodule_path.absolute()))
100
elif
submodule_path.is_dir():
101
package_data_rec(submodule_path, l)
102
else
:
103
print(f
'Found file {submodule_path} but it will not be added to package data!'
)
104
package_data_rec(self.
target_path
, self.
package_data
)
105
106
stubs_generator =
StubsGenerator
()
107
stubs_generator.run()
108
109
setup
(
110
packages=[
'visp'
],
111
zip_safe=
False
,
112
package_data = {
113
'visp'
: stubs_generator.package_data
114
},
115
)
setup.StubsGenerator
Definition
setup.py:44
setup.StubsGenerator.target_path
target_path
Definition
setup.py:48
setup.StubsGenerator.generate_stubs
generate_stubs(self)
Definition
setup.py:57
setup.StubsGenerator.run
run(self)
Definition
setup.py:53
setup.StubsGenerator.build_package_data
build_package_data(self)
Definition
setup.py:95
setup.StubsGenerator.package_data
list package_data
Definition
setup.py:50
setup.StubsGenerator.rearrange_stubs
rearrange_stubs(self)
Definition
setup.py:65
setup.StubsGenerator.output_root
str output_root
Definition
setup.py:47
setup.StubsGenerator.__init__
__init__(self)
Definition
setup.py:45
setup
Definition
setup.py:1
modules
python
stubs
setup.py
Generated by
1.17.0