asdf-python
asdf-python copied to clipboard
For Python, stop using the exec format in reshim when using runpy.
related issue: https://github.com/asdf-vm/asdf/issues/1059
Is your feature request related to a problem? Please describe
If you run a python library which uses runpy like below,
pyannotate run pytest
monkeytype run pytest
The all failed with below error.
❯ monkeytype run "/Users/kohei.murakami/.asdf/shims/pytest"
Traceback (most recent call last):
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/bin/monkeytype", line 8, in <module>
sys.exit(entry_point_main())
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/lib/python3.9/site-packages/monkeytype/cli.py", line 396, in entry_point_main
sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/lib/python3.9/site-packages/monkeytype/cli.py", line 381, in main
handler(args, stdout, stderr)
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/lib/python3.9/site-packages/monkeytype/cli.py", line 224, in run_handler
runpy.run_path(args.script_path, run_name='__main__')
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/lib/python3.9/runpy.py", line 267, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "/Users/kohei.murakami/.asdf/installs/python/3.9.1/lib/python3.9/runpy.py", line 242, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "/Users/kohei.murakami/.asdf/shims/pytest", line 4
exec /usr/local/opt/asdf/bin/asdf exec "pytest" "$@"
^
SyntaxError: Missing parentheses in call to 'exec'
It's because ${HOME}/.asdf/shims/pytest
is written for bash syntax. However, runpy expect it works as python like this https://github.com/Instagram/MonkeyType/blob/47f42377419680f518556c7d823540b8852378e9/monkeytype/cli.py#L221-L224 .
Describe the proposed solution
I would suggest replacing bash entrypoint into python code for python modules.
Describe similar asdf
features and why they are not sufficient
I searched but there is not any similar one.
Describe other workarounds you've considered
Currently I install python library without asdf, and import them each time for runpy.