`shiv -c <script>` builds a broken pyz when the console script declares extras (e.g. `blackd`)

Aperta Adatta ai principianti
#289 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Inizia da shiv.cli.find_entry_point, dove l’issue indica che viene selezionato il valore grezzo dello script console, e controlla come viene scritto in environment.json. Esamina i test esistenti per la gestione dell’entry point e aggiungi un caso di regressione per un valore con un marker extras finale. Il lavoro è completato quando il pyz creato memorizza un semplice module:attr ed esegue correttamente l’entry point blackd.

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

Descrizione

Summary

When a console script in entry_points.txt carries an extras marker, find_entry_point returns the raw value including the marker, and it is written verbatim into environment.json as entry_point. The build succeeds, but every run of the resulting pyz fails in import_string.

A real example is black's blackd. black 26.10.1's entry_points.txt contains:

[console_scripts]
black = black:patched_main
blackd = blackd:patched_main [d]
Reproduction (shiv main @ ff542cb, Python 3.12, macOS arm64)
shiv -q -c blackd -o blackd.pyz 'black[d]==26.10.1'      # exit 0
unzip -p blackd.pyz environment.json | python -c "import json,sys; print(json.load(sys.stdin)['entry_point'])"
# blackd:patched_main [d]
python blackd.pyz --help; echo $?

Output:

  File ".../blackd.pyz/_bootstrap/__init__.py", line 87, in import_string
ImportError: module 'blackd' has no attribute 'patched_main [d]'
1

Control: shiv -c black -o black.pyz 'black==26.10.1' (no extras on that script) works; python black.pyz --version prints black.pyz, 26.10.1 and exits 0.

Expected

Extras are not part of the import target. pip's generated bin/blackd script (in the same staged site-packages) is from blackd import patched_main and prints its usage for --help. importlib.metadata parses the same entry as module='blackd', attr='patched_main', extras=['d'], and ep.load() returns the function. The pyz should resolve to blackd:patched_main too.

Any console script declared with an extras marker hits this. -e blackd:patched_main works around it.

Proposed fix

Strip a trailing [...] extras group from the value in shiv.cli.find_entry_point at build time, so environment.json holds a plain module:attr. This is independent of #284 (which changes the ConfigParser delimiters in the same function). I have a small patch with a regression test and can open a PR if that approach is OK.

This issue was drafted with Claude Code (claude-opus-5-5); the results above are from the runs described.

Lingua principale
Python
Stelle
2k
Fork
118
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di linkedin/shiv

Tutte le issue di linkedin/shiv

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.