Skip to content

Commit

Permalink
Merge pull request #231 from unihd-cag/issue-230
Browse files Browse the repository at this point in the history
Repair static completion after mypy behavior change
  • Loading branch information
TM90 authored Aug 1, 2023
2 parents 36e5323 + b9c25a5 commit 2dd833c
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions skillbridge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from keyword import iskeyword
from os import chdir
from pathlib import Path
from re import fullmatch, sub
from sys import executable, version_info

from .client.functions import FunctionCollection, keys
from .client.globals import Globals, GlobalVar
Expand Down Expand Up @@ -38,19 +42,47 @@


def generate_static_completion() -> None:
from keyword import iskeyword
from pathlib import Path
from re import fullmatch
from subprocess import run
from mypy.stubgen import Options, generate_stubs

ident = r'[a-zA-Z_][a-zA-Z0-9_]*'
base = Path(__file__).parent.absolute() / 'client'
annotation = base / 'workspace.pyi'

try:
annotation.unlink()
except FileNotFoundError:
pass

chdir(base)

o = Options(
(version_info.major, version_info.minor),
no_import=True,
doc_dir='',
search_path=[],
interpreter=executable,
parse_only=False,
ignore_errors=False,
include_private=False,
output_dir='.',
modules=['workspace'],
packages=[],
files=[],
verbose=True,
quiet=False,
export_less=False,
)

client = Path(__file__).parent.absolute() / 'client'
chdir(client)
run(['stubgen', 'workspace.py', '-o', '.'])
generate_stubs(o)

ident = r'[a-zA-Z_][a-zA-Z0-9_]*'

ws = Workspace.open()
with open('workspace.pyi', 'a') as fout:

text = annotation.read_text()
text = sub(r' {4}[a-z][a-zA-Z]+: FunctionCollection\n', '', text)
annotation.write_text(text)

with open(annotation, 'a') as fout:
for key, value in ws.__dict__.items():
if not isinstance(value, FunctionCollection):
continue
Expand Down

0 comments on commit 2dd833c

Please sign in to comment.