asdf-community / asdf-community/asdf-python

For Python, stop using the exec format in reshim when using runpy.

Open
#114 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
729
Forks
65
PR merge metrics
No merged PRs in 30d

Description

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,

```python
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
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.