Skip to content

Commit

Permalink
Fixes Windows use of NamedTemporaryFile
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Dec 14, 2021
1 parent df99715 commit 78cc6bb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@
sys.stdout.flush()

# Check syntax
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}'], env=env)
# Windows limitation - another process cannot normally read temporary file that is opened by this process
# Close first and delete manually afterwards
config = tempfile.NamedTemporaryFile(mode='w', delete=False)
config.write('[mypy]\nignore_errors = True\n')
config.close()
print(f'Mypy config file: {config.name}')
subprocess.check_call([sys.executable, '-m' 'mypy', f'{DIRECTORY}/{MODULE_NAME}', f'--config-file={config.name}'], env=env)
os.unlink(config.name)

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

0 comments on commit 78cc6bb

Please sign in to comment.