Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sip pyi generated #3

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,8 +1297,8 @@ def cmd_sip(options, args):
continue

# Leave it turned off for now. TODO: Experiment with this...
# pyi_extract = posixjoin(cfg.PKGDIR, base[1:]) + '.pyi'
pyi_extract = None
pyi_extract = posixjoin(cfg.PKGDIR, base[1:]) + '.pyi'
# pyi_extract = None

# SIP extracts are used to pull python snippets and put them into the
# module's .py file
Expand All @@ -1320,13 +1320,14 @@ def cmd_sip(options, args):
tracing = {tracing}
protected-is-public = false
generate-extracts = [\'{extracts}\']
pep484-pyi = false
pep484-pyi = true

[tool.sip.project]
abi-version = "{abi_version}"
sip-files-dir = '{sip_gen_dir}'
sip-include-dirs = ['{src_dir}']
sip-module = "wx.siplib"
dunder-init = true
""".format(
base=base,
abi_version=cfg.SIP_ABI,
Expand Down Expand Up @@ -2131,7 +2132,7 @@ def cmd_cleanall(options, args):
cmdTimer = CommandTimer('cleanall')
assert os.getcwd() == phoenixDir()
files = list()
for wc in ['sip/cpp/*.h', 'sip/cpp/*.cpp', 'sip/cpp/*.sbf', 'sip/gen/*.sip']:
for wc in ['sip/cpp/*.h', 'sip/cpp/*.cpp', 'sip/cpp/*.pyi', 'sip/cpp/*.sbf', 'sip/gen/*.sip']:
files += glob.glob(wc)
delFiles(files)

Expand Down Expand Up @@ -2209,6 +2210,15 @@ def _archive_submodules(root, dest):
copyFile(name, destdir)
sip_h_dir = posixjoin(cfg.PKGDIR, 'include', 'wxPython')
copyFile(posixjoin(sip_h_dir, 'sip.h'), posixjoin(PDEST, sip_h_dir))
print("Copy sip-generated pyi files")
# Copy sip-generated pyi files
for sip_pyi in glob.glob(posixjoin('sip','cpp','*.py*')):
print(f"Found {sip_pyi}")
destdir = posixjoin(PDEST, cfg.PKGDIR)
if not os.path.isdir(sip_pyi):
copyFile(sip_pyi, destdir)
print(f"Copied '{sip_pyi}' to dir '{destdir}'")
print("Finished copying sip-generated pyi files")
for wc in ['*.py', '*.pi', '*.pyi']:
destdir = posixjoin(PDEST, cfg.PKGDIR)
for name in glob.glob(posixjoin(cfg.PKGDIR, wc)):
Expand Down
15 changes: 13 additions & 2 deletions etg/dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,19 @@ def run():
c.addPyCode('DC.GetGdkDrawable = wx.deprecated(DC.GetGdkDrawable, "Use GetHandle instead.")')

# context manager methods
c.addPyMethod('__enter__', '(self)', 'return self')
c.addPyMethod('__exit__', '(self, exc_type, exc_val, exc_tb)', 'self.Destroy()')
c.module.addPyCode("""
from types import TracebackType
from typing import TYPE_CHECKING, Literal
if TYPE_CHECKING:
import sys
if sys.version_info >=(3,11):
from typing import Self
else:
from typing import TypeVar
import wx.core.DC
Self = TypeVar("Self", bound="wx.core.DC")""")
c.addPyMethod('__enter__', '(self: Self) -> Self', 'return self')
c.addPyMethod('__exit__', '(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> Literal[False]', 'self.Destroy()')


# This file contains implementations of functions for quickly drawing
Expand Down
25 changes: 23 additions & 2 deletions etgtools/pi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,18 @@ def generateTypedef(self, typedef, stream, indent=''):
bases = [self.fixWxPrefix(b, True) for b in bases]
name = self.fixWxPrefix(typedef.name)

print(f"Vars of typedef : {vars(typedef)}")
baseClassSip = None
if hasattr(typedef, "module"):
print(f"Vars of typedef.module : {vars(typedef.module)}")
baseClassSip = typedef.module.module+"."+name
bases += [baseClassSip]
else:
print("typedef doesn't have a modules attribute")

# Now write the Python equivalent class for the typedef
if not bases:
bases = ['object'] # this should not happen, but just in case...
bases = ['object'] # this should not happen, but just in case...
stream.write('%sclass %s(%s):\n' % (indent, name, ', '.join(bases)))
indent2 = indent + ' '*4
if typedef.briefDoc:
Expand Down Expand Up @@ -407,14 +416,26 @@ def generateClass(self, klass, stream, indent=''):

# write class declaration
klassName = klass.pyName or klass.name
print(f"Vars of klass : {vars(klass)}")
baseClassSip = None
if hasattr(klass, "module"):
print(f"Vars of klass.module : {vars(klass.module)}")
baseClassSip = klass.module.module+"."+klassName
else:
print("klass doesn't have a modules attribute")
stream.write('\n%sclass %s' % (indent, klassName))
if bases:
stream.write('(')
bases = [self.fixWxPrefix(b, True) for b in bases]
if baseClassSip is not None:
bases += [baseClassSip]
stream.write(', '.join(bases))
stream.write(')')
else:
stream.write('(object)')
if baseClassSip is None:
stream.write(f'(object)')
else:
stream.write(f'(object, {baseClassSip})')
stream.write(':\n')
indent2 = indent + ' '*4

Expand Down
2 changes: 2 additions & 0 deletions etgtools/sip_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def generateModule(self, module, stream):

%%DefaultDocstringFormat(name="deindented")

%%DefaultDocstringSignature(name="appended")

""" % (module.package, module.name))

if module.name.startswith('_'):
Expand Down
15 changes: 13 additions & 2 deletions wx/lib/busy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@
A class like :class:`wx.BusyInfo` but which doesn't take up so much space by default
and which has a nicer look.
"""
from __future__ import annotations

import wx
from wx.lib.stattext import GenStaticText as StaticText
from types import TracebackType
from typing import TYPE_CHECKING, Literal
if TYPE_CHECKING:
import sys
if sys.version_info >=(3,11):
from typing import Self
else:
from typing import TypeVar
import wx.lib.busy
Self = TypeVar("Self", bound="wx.lib.busy.BusyInfo")

#---------------------------------------------------------------------------

Expand Down Expand Up @@ -68,9 +79,9 @@ def Close(self):


# Magic methods for using this class as a Context Manager
def __enter__(self):
def __enter__(self: Self) -> Self:
return self
def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> Literal[False]:
self.Close()
return False

Expand Down
1 change: 1 addition & 0 deletions wx/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial
Loading