Skip to content

Declare the file encoding in sitecustomize.py so it parses on Python 2.7#37

Merged
mmanciop merged 3 commits into
mainfrom
python2.7
Jul 23, 2026
Merged

Declare the file encoding in sitecustomize.py so it parses on Python 2.7#37
mmanciop merged 3 commits into
mainfrom
python2.7

Conversation

@mmanciop

@mmanciop mmanciop commented Jul 23, 2026

Copy link
Copy Markdown
Member

Fixes #36.

What

  • Add the PEP-263 encoding declaration (# -*- coding: utf-8 -*-) as the first line of the injector bootstrap script (sitecustomize.py), and extend its header comment to state that the declaration must stay on line 1 or 2.
  • Add a sitecustomize-python27 CI job that byte-compiles the script under python:2.7.18-buster and runs the issue's end-to-end scenario: a Python 2.7 process with the injected directory on PYTHONPATH must emit the "unsupported Python version" warning, self-deactivate, and keep running — and must not log 'import sitecustomize' failed.
  • Bump dash0-opentelemetry-distro to 0.2.1 (the script ships in the wheel) and add the chloggen entry.

Why

The script's header comments contain em-dashes (U+2014). Without an encoding declaration, Python 2.7 rejects the whole file at parse time with SyntaxError: Non-ASCII character '\xe2', so the self-deactivation logic never runs. This defeats the script's stated contract of parsing on unsupported interpreters and deactivating gracefully, and breaks consumers whose fleet includes Python 2.7 processes reached by the OpenTelemetry injector (e.g. the dash0-operator's python-2.7 dont-crash instrumentation-image test, dash0hq/dash0-operator#1248).

mmanciop added 3 commits July 23, 2026 18:35
The injector bootstrap script contains em-dashes in its header comments
but declared no encoding, so Python 2.7 rejected the file at parse time
(PEP 263) and the self-deactivation logic never ran: injected processes
logged "'import sitecustomize' failed" instead of the warn-and-continue
behavior the script promises.

Add the PEP-263 declaration, bump the distro to 0.2.1, and add a CI job
that byte-compiles the script under Python 2.7 and verifies end to end
that an injected 2.7 process warns, self-deactivates, and keeps running.

Fixes #36
The inline shell version shipped a broken grep pattern (a leading double
quote that never occurs in the warn message), failing the job even though
the script behaved correctly. Replace it with
scripts/check_sitecustomize_python27.py: the assertion logic is a pure
function covered by the scripts-test suite, and the workflow job shrinks
to a single python3 invocation (the script is stdlib-only, so no uv).
@mmanciop
mmanciop merged commit 6197997 into main Jul 23, 2026
10 checks passed
@mmanciop
mmanciop deleted the python2.7 branch July 23, 2026 18:43
@mmanciop mmanciop mentioned this pull request Jul 23, 2026
mmanciop added a commit to dash0hq/dash0-operator that referenced this pull request Jul 23, 2026
…-fix commit

Adopts dash0hq/opentelemetry-python-distribution#37, which adds a PEP-263
encoding declaration to the packaged sitecustomize.py so it parses on
Python 2.7 and can self-deactivate on unsupported interpreters (see
dash0hq/opentelemetry-python-distribution#36 for the failure mode).

Pinned to main HEAD (6197997e) because no v0.2.1 release has been cut yet;
bump to the tag when it lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sitecustomize.py fails to parse on Python 2.7 (missing PEP-263 encoding declaration)

1 participant