asdf-community / asdf-community/asdf-python

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

Aperta
#114 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Shell
Stelle
729
Fork
65
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia esaminando l’entry point generato ~/.asdf/shims/pytest e il comportamento di reshim che lo crea, quindi confronta tale comportamento con Python runpy.run_path come mostrato nel report. Il lavoro è completato quando i moduli Python possono essere avviati tramite gli shim di asdf senza che la sintassi della shell venga analizzata come Python, mentre la normale esecuzione degli shim continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, shell
Ambito
cli, tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.