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

Open Beginner friendly
#289 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

Research direction

Start in shiv.cli.find_entry_point, where the issue says the raw console script value is selected, and inspect how it is written to environment.json. Check the existing tests for entry point handling and add a regression case for a value with a trailing extras marker. Done means the built pyz stores a plain module:attr and runs the blackd entry point successfully.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
2k
Forks
118
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linkedin/shiv

All issues in linkedin/shiv

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.