Skip to content

Commit d134601

Browse files
authored
Record the file encoding of .python-version and runtime.txt (#1948)
To help work out what file encodings are present in the wild, in order to improve the UX for file parsing related errors that are believe to be due to encoding issues. The `file --brief` command will return values like: - `ASCII text` - `Unicode text, UTF-8 (with BOM) text` - `Unicode text, UTF-16, little-endian text, with CRLF line terminators` These metrics will be removed later. See: https://manpages.ubuntu.com/manpages/noble/en/man1/file.1.html GUS-W-20049083.
1 parent 3b25a5b commit d134601

File tree

5 files changed

+7
-0
lines changed

5 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Improved the error message when a `.python-version` or `runtime.txt` file contains invisible Unicode whitespace characters. ([#1947](https://github.com/heroku/heroku-buildpack-python/pull/1947))
6+
- Added metrics for the file encoding of `.python-version` and `runtime.txt` files. ([#1948](https://github.com/heroku/heroku-buildpack-python/pull/1948))
67

78
## [v315] - 2025-10-22
89

lib/python_version.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function python_version::read_requested_python_version() {
6464

6565
local runtime_txt_path="${build_dir}/runtime.txt"
6666
if [[ -f "${runtime_txt_path}" ]]; then
67+
# For example: "ASCII text" or "Unicode text, UTF-16, little-endian text, with CRLF line terminators"
68+
build_data::set_string "runtime_txt_encoding" "$(file --brief "${runtime_txt_path}" || true)"
6769
contents="$(utils::read_file_with_special_chars_substituted "${runtime_txt_path}")"
6870
version="$(python_version::parse_runtime_txt "${contents}")"
6971
origin="runtime.txt"
@@ -72,6 +74,7 @@ function python_version::read_requested_python_version() {
7274

7375
local python_version_file_path="${build_dir}/.python-version"
7476
if [[ -f "${python_version_file_path}" ]]; then
77+
build_data::set_string "python_version_file_encoding" "$(file --brief "${python_version_file_path}" || true)"
7578
contents="$(utils::read_file_with_special_chars_substituted "${python_version_file_path}")"
7679
version="$(python_version::parse_python_version_file "${contents}")"
7780
origin=".python-version"

spec/hatchet/pip_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
remote: "pre_compile_hook": false,
7373
remote: "python_install_duration": [0-9.]+,
7474
remote: "python_version": "#{DEFAULT_PYTHON_FULL_VERSION}",
75+
remote: "python_version_file_encoding": "ASCII text",
7576
remote: "python_version_files": ".python-version,",
7677
remote: "python_version_major": "3.13",
7778
remote: "python_version_origin": ".python-version",

spec/hatchet/poetry_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
remote: "pre_compile_hook": false,
7575
remote: "python_install_duration": [0-9.]+,
7676
remote: "python_version": "#{DEFAULT_PYTHON_FULL_VERSION}",
77+
remote: "python_version_file_encoding": "ASCII text",
7778
remote: "python_version_files": ".python-version,",
7879
remote: "python_version_major": "3.13",
7980
remote: "python_version_origin": ".python-version",

spec/hatchet/uv_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
remote: "pre_compile_hook": false,
8080
remote: "python_install_duration": [0-9.]+,
8181
remote: "python_version": "#{DEFAULT_PYTHON_FULL_VERSION}",
82+
remote: "python_version_file_encoding": "ASCII text",
8283
remote: "python_version_files": ".python-version,",
8384
remote: "python_version_major": "3.13",
8485
remote: "python_version_origin": ".python-version",

0 commit comments

Comments
 (0)