Skip to content

Commit 4fd8b29

Browse files
committed
Fix ID'ing of version-specific executable names on Windows
1 parent a46dc31 commit 4fd8b29

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Fixed
2+
-----
3+
4+
* Strip the executable extension (like ``.exe``) before removing version numbers
5+
when identifying a file type based on its hashbang.
6+
7+
This resolves a bug that prevented identification of version-specific
8+
executable names, like ``python3.14.exe``, on Windows platforms.

src/chipshot/reader/identity.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ def handle(info: FileInfo, config: dict[str, typing.Any]) -> None:
3838
info.identity = config["interpreters"][name]
3939
return
4040

41-
# Look for a version-less name.
42-
name_without_version = name.rstrip("0123456789.")
43-
if name_without_version in config["interpreters"]:
44-
log.debug(f"{info.path}: Found versioned interpreter '{name}'")
45-
info.identity = config["interpreters"][name_without_version]
46-
return
47-
48-
# Try removing the extension (such as "python.exe" on Windows).
41+
# Try removing the extension (such as ".exe" on Windows).
4942
stem = path.stem
5043
if stem in config["interpreters"]:
5144
log.debug(f"{info.path}: Found base interpreter '{name}'")
5245
info.identity = config["interpreters"][stem]
5346
return
47+
48+
# Look for a version-less name.
49+
name_without_version = stem.rstrip("0123456789.")
50+
if name_without_version in config["interpreters"]:
51+
log.debug(f"{info.path}: Found versioned interpreter '{name}'")
52+
info.identity = config["interpreters"][name_without_version]
53+
return

tests/test_reader_identity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
pytest.param("#!/usr/bin/python", "python", id="base executable name"),
2020
pytest.param("#!/usr/bin/python3.11", "python", id="trailing version"),
2121
pytest.param("#!/usr/bin/env python", "python", id="env"),
22-
pytest.param(r"#!C:\Program Files\Python39\python.exe", "python", id="windows"),
22+
pytest.param(
23+
r'#!"C:\Program Files\Python39\python3.9.exe"', "python", id="windows"
24+
),
2325
pytest.param(
2426
"#!/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -File",
2527
"powershell",

0 commit comments

Comments
 (0)