Generate Python stubs file for linters (#214)

* Generate Python stubs file for linters

* Sort members of ads namespace in generated __init__.py
This commit is contained in:
Nicolas Elie 2020-07-02 07:47:18 +02:00 committed by GitHub
parent 281127c2c3
commit 6d0f14e1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -168,6 +168,7 @@ class build_ext(sipdistutils.build_ext):
return os.path.join(sys.prefix, 'sip', 'PyQt5')
def _sip_compile(self, sip_bin, source, sbf):
pyi = os.path.join(self.build_lib, "PyQtAds", "QtAds", "ads.pyi")
cmd = [sip_bin]
if hasattr(self, 'sip_opts'):
cmd += self.sip_opts
@ -180,11 +181,20 @@ class build_ext(sipdistutils.build_ext):
"-I", self.inc_dir,
"-c", self._sip_output_dir(),
"-b", sbf,
"-y", pyi,
"-w", "-o"]
cmd += shlex.split(self.pyqt_sip_flags) # use same SIP flags as for PyQt5
cmd.append(source)
self.spawn(cmd)
if os.path.exists(pyi):
with open(pyi) as f:
content = f.readlines()
with open(pyi, "w") as f:
for line in content:
if not line.startswith("class ads"):
f.write(line)
def swig_sources (self, sources, extension=None):
if not self.extensions:
@ -293,6 +303,17 @@ class build_ext(sipdistutils.build_ext):
ext.sources.append(out_file)
sipdistutils.build_ext.build_extension(self, ext)
import inspect
sys.path.append(os.path.join(self.build_lib, 'PyQtAds', 'QtAds'))
import ads
with open(os.path.join(self.build_lib, 'PyQtAds', 'QtAds', '__init__.py'), 'w') as f:
f.write('from .._version import *\n')
f.write('from .ads import ads\n')
for name, member in sorted(inspect.getmembers(ads.ads)):
if not name.startswith('_'):
f.write('{0} = ads.{0}\n'.format(name))
class ProcessResourceCommand(cmd.Command):