← Back to issue list

`plugin: python` uses `$CRAFT_PART_INSTALL` in console-script polyglot shebangs that is broken on long build paths

View original Github issue

Metadata

Project
rockcraft
Number
#1385
Type
issue
State
open
Author
himax16
Labels
Status: Triaged
Created
Updated
Closed
—

Current evaluation

Python plugin console scripts embed build-time $CRAFT_PART_INSTALL shebangs; long paths trigger pip polyglot shebang not rewritten, causing runtime exit 127. Triaged, awaiting fix.

Suggested action: keep open

Reason: Maintainer acknowledged the report and an internal Jira ticket ROCKCRAFT-326 was created. The existing _python_v2_shebang_fix only matches plain #! lines pointing at install/stage dirs, so the pip polyglot shebang described here is unhandled; the issue has a clear reproducer and expected output.

Evaluated by: mr-cal-bot

Impact: 60 Quick Win: 24 Complexity: 50 Confidence: 80 Actionability: 80

Issue body

### Check existing issues - [x] I've verified that this bug isn't described by any existing issues. ### Bug description For a part uses `plugin: python` with a stage-packages Python interpreter (i.e. a non-venv install), `pip` writes console-script shebangs using `sys.executable`, which at build time is the staged interpreter under `$CRAFT_PART_INSTALL`. That absolute path will not exist in the primed ROCK, so the command fails at runtime with exit 127. When that path exceeds 127 bytes, pip emits its "long shebang" fallback (`#!/bin/sh + '''exec' ...`) instead of a plain `#! line. ### Steps to reproduce Minimal `rockcraft.yaml`: ```yaml name: repro version: "0" base: ubuntu@26.04 parts: repro: plugin: python source: https://github.com/canonical/openstack-images-sync/ source-type: git source-commit: 89f18a706b369892b418125fae7879e5550c4827 stage-packages: - python3 - python3-venv - python3-dev ``` Build on a host whose build directory is long (e.g. GitHub Actions / oci-factory, where the path is `/home/buildd/gh-rocks-<run-id>/...`). **Outcome** The primed `usr/bin/openstack-images-sync` starts with the pip polyglot, pointing at the build-time interpreter: ```sh #!/bin/sh '''exec' /home/buildd/gh-rocks-37491200797-1-5e169020-openstack-images-sync/rocks/openstack-images-sync/parts/openstack-images-sync/install/usr/bin/python3 "$0" "$@" ' ''' # -*- coding: utf-8 -*- import re import sys from openstack_images_sync.__main__ import cli ``` At runtime the service exits: ```sh /usr/bin/openstack-images-sync: 2: exec: /home/buildd/gh-rocks-…/parts/openstack-images-sync/install/usr/bin/python3: not found ``` **Expected** A portable shebang, e.g.: ```sh #!/usr/bin/python3 ``` (or `#!/usr/bin/env python3`), with the body unchanged. ### Environment Reproduced in [canonical/ubuntu-openstack-rocks](https://github.com/canonical/ubuntu-openstack-rocks) `rocks/openstack-images-sync` (PR [#177](https://github.com/canonical/ubuntu-openstack-rocks/pull/177) shipped an override-build workaround).

Evaluation history

Date Model Scores Action Summary
~deepseek/deepseek-pro-latest
Impact: 60
Quick Win: 24
Complexity: 50
Confidence: 80
Actionability: 80
keep open Python plugin console scripts embed build-time $CRAFT_PART_INSTALL shebangs; long paths trigger pip polyglot shebang not rewritten, causing runtime exit 127. Triaged, awaiting fix.
~deepseek/deepseek-pro-latest
Impact: 65
Quick Win: 23
Complexity: 55
Confidence: 75
Actionability: 80
needs triage Python plugin console-script shebangs point at build-time $CRAFT_PART_INSTALL; pip's >127-byte polyglot shebang is not rewritten, causing runtime exit 127. New, unlabelled, no maintainer response.

Update history

Date Change
updated
created

Related issues

No related issues found above the similarity threshold.