Skip to content

Commit

Permalink
Appends location of built library to PYTHONPATH explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Dec 14, 2021
1 parent 382c2c2 commit df99715
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import re
import tempfile
import os

# Usage
if len(sys.argv) < 3:
Expand All @@ -17,7 +18,10 @@

# Create stubs, add PYTHONPATH to find the build module
# CWD to to extdir where the built module can be found to extract the types
subprocess.check_call(['stubgen', '-p', MODULE_NAME, '-o', f'{DIRECTORY}'], cwd=DIRECTORY)
env = os.environ
env['PYTHONPATH'] = f'{DIRECTORY}{os.pathsep}{env.get("PYTHONPATH", "")}'
print(f'PYTHONPATH set to {env["PYTHONPATH"]}')
subprocess.check_call(['stubgen', '-p', MODULE_NAME, '-o', f'{DIRECTORY}'], cwd=DIRECTORY, env=env)

# Add py.typed
open(f'{DIRECTORY}/depthai/py.typed', 'a').close()
Expand Down Expand Up @@ -48,7 +52,7 @@
with tempfile.NamedTemporaryFile() as config:
config.write('[mypy]\nignore_errors = True\n'.encode())
config.flush()
subprocess.check_call([sys.executable, '-m' 'mypy', f'{DIRECTORY}/{MODULE_NAME}', f'--config-file={config.name}'])
subprocess.check_call([sys.executable, '-m' 'mypy', f'{DIRECTORY}/{MODULE_NAME}', f'--config-file={config.name}'], env=env)

except subprocess.CalledProcessError as err:
exit(err.returncode)
Expand Down

0 comments on commit df99715

Please sign in to comment.