Skip to content

Commit a01e66c

Browse files
Darxealsamuelpmish
authored andcommitted
fix python stubs (#19)
1 parent ac22b70 commit a01e66c

7 files changed

Lines changed: 966 additions & 1174 deletions

File tree

pybind11_stubgen.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,23 @@ def to_lines(self): # type: () -> List[str]
348348
result = []
349349
result.append("@property")
350350
result.append("def {field_name}(self) -> {rtype}:".format(field_name=self.name,rtype=self.signature.rtype))
351-
docstring = self.remove_signatures(self.prop.__doc__)
352-
docstring += "\n:type: {rtype}".format(rtype=self.signature.rtype)
351+
result.append(self.indent("pass"))
352+
result.append("")
353+
#result.append("{field_name}: {rtype}".format(field_name=self.name,rtype=self.signature.rtype))
353354

354-
result.append(self.indent('"""{}"""'.format(docstring)))
355+
#docstring = self.remove_signatures(self.prop.__doc__)
356+
#docstring += "\n:type: {rtype}".format(rtype=self.signature.rtype)
355357

356-
if self.signature.setter_args != "None":
357-
result.append("@{field_name}.setter".format(field_name=self.name))
358-
result.append("def {field_name}({args}) -> None:".format(field_name=self.name, args=self.signature.setter_args))
359-
docstring = self.remove_signatures(self.prop.__doc__)
360-
if docstring:
361-
result.append(self.indent('"""{}"""'.format(docstring)))
362-
else:
363-
result.append(self.indent("pass"))
358+
#result.append(self.indent('"""{}"""'.format(docstring)))
359+
360+
# if self.signature.setter_args != "None":
361+
# result.append("@{field_name}.setter".format(field_name=self.name))
362+
# result.append("def {field_name}({args}) -> None:".format(field_name=self.name, args=self.signature.setter_args))
363+
# docstring = self.remove_signatures(self.prop.__doc__)
364+
# if docstring:
365+
# result.append(self.indent('"""{}"""'.format(docstring)))
366+
# else:
367+
# result.append(self.indent("pass"))
364368

365369
return result
366370

@@ -405,7 +409,9 @@ def parse(self):
405409
elif name == "__doc__":
406410
self.doc_string = member
407411
elif name not in self.attributes_blacklist:
408-
logger.warn("Unknown member %s type : `%s` "%(name,str(type(member))))
412+
#logger.warn("Unknown member %s type : `%s` "%(name,str(type(member))))
413+
self.fields.append(AttributeStubsGenerator(name, member))
414+
#self.properties.append(PropertyStubsGenerator(name, member, self.klass.__module__))
409415

410416
for x in itertools.chain(self.methods,
411417
self.properties,
@@ -440,10 +446,18 @@ def strip_current_module_name(obj,module_name):
440446
base_classes_list=", ".join(base_classes_list)
441447
),
442448
]
443-
for f in self.methods:
444-
if f.member.__name__ not in self.methods_blacklist:
445-
result.extend(map(self.indent,f.to_lines()))
446449

450+
for f in self.fields:
451+
result.extend(map(self.indent, f.to_lines()))
452+
453+
result.append("")
454+
455+
for m in self.methods:
456+
if m.member.__name__ not in self.methods_blacklist:
457+
result.extend(map(self.indent, m.to_lines()))
458+
459+
result.append("")
460+
447461
for p in self.properties:
448462
result.extend(map(self.indent, p.to_lines()))
449463

@@ -593,42 +607,26 @@ def short_name(self):
593607
return self.module.__name__.split(".")[-1]
594608

595609
def write(self):
596-
if not os.path.exists(self.short_name + self.stub_suffix):
597-
logger.info("mkdir `%s`"%(self.short_name + self.stub_suffix))
598-
os.mkdir(self.short_name + self.stub_suffix)
599-
600-
with DirectoryWalkerGuard(self.short_name + self.stub_suffix):
601-
with open("__init__.pyi", "w") as init_pyi:
602-
init_pyi.write("\n".join(self.to_lines()))
603-
for m in self.submodules:
604-
m.write()
605-
606-
if self.write_setup_py:
607-
with open("setup.py","w") as setuppy:
608-
setuppy.write("""from setuptools import setup
609-
import os
610-
610+
if self.submodules:
611+
if not os.path.exists(self.short_name + self.stub_suffix):
612+
logger.info("mkdir `%s`"%(self.short_name + self.stub_suffix))
613+
os.mkdir(self.short_name + self.stub_suffix)
614+
with DirectoryWalkerGuard(self.short_name + self.stub_suffix):
615+
with open("__init__.pyi", "w") as init_pyi:
616+
init_pyi.write("\n".join(self.to_lines()))
617+
for m in self.submodules:
618+
m.write()
619+
else:
620+
with open(self.short_name + ".pyi", "w") as init_pyi:
621+
content = "\n".join(self.to_lines())
622+
content = content.replace("vec<2>", "vec2")
623+
content = content.replace("vec<3>", "vec3")
624+
content = content.replace("vec<4>", "vec4")
625+
content = content.replace("mat<2,2>", "mat2")
626+
content = content.replace("mat<3,3>", "mat3")
627+
content = content.replace("rlutilities.rlutilities", "rlutilities")
628+
init_pyi.write(content)
611629

612-
def find_stubs(package):
613-
stubs = []
614-
for root, dirs, files in os.walk(package):
615-
for file in files:
616-
path = os.path.join(root, file).replace(package + os.sep, '', 1)
617-
stubs.append(path)
618-
return dict(package=stubs)
619-
620-
621-
setup(
622-
name='{package_name}-stubs',
623-
maintainer="{package_name} Developers",
624-
maintainer_email="[email protected]",
625-
description="PEP 561 type stubs for {package_name}",
626-
version='1.0',
627-
packages=['{package_name}-stubs'],
628-
# PEP 561 requires these
629-
install_requires=['{package_name}'],
630-
package_data=find_stubs('{package_name}-stubs'),
631-
)""".format(package_name=self.short_name))
632630

633631

634632

rlutilities/__init__.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import *
2-
from typing import Iterable as iterable
3-
from typing import Iterator as iterator
4-
from numpy import float64
5-
_Shape = Tuple[int, ...]
6-
__all__ = [
7-
"linear_algebra",
8-
"mechanics",
9-
"simulation"
1+
from typing import *
2+
from typing import Iterable as iterable
3+
from typing import Iterator as iterator
4+
from numpy import float64
5+
_Shape = Tuple[int, ...]
6+
__all__ = [
7+
"linear_algebra",
8+
"mechanics",
9+
"simulation"
1010
]

0 commit comments

Comments
 (0)