Skip to content

Commit e9427bd

Browse files
committed
unix: add a python symlink to the pythonX.Y executable
We're apparently permitted to do this according to PEP 394. And it was requested by an end user. Seems like a nice usability win. Closes astral-sh#212.
1 parent 79314de commit e9427bd

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

‎cpython-unix/build-cpython.sh

+4
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ if [ ! -f ${ROOT}/out/python/install/bin/python3 ]; then
772772
exit 1
773773
fi
774774

775+
ln -sf \
776+
"$(readlink ${ROOT}/out/python/install/bin/python3)" \
777+
${ROOT}/out/python/install/bin/python
778+
775779
# Fixup shebangs in Python scripts to reference the local python interpreter.
776780
cat > ${ROOT}/fix_shebangs.py << EOF
777781
import os

‎src/validation.rs

+50
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,9 @@ fn validate_distribution(
16691669
));
16701670
}
16711671

1672+
let mut bin_python = None;
1673+
let mut bin_python3 = None;
1674+
16721675
for entry in entries {
16731676
let mut entry = entry.map_err(|e| anyhow!("failed to iterate over archive: {}", e))?;
16741677
let path = entry.path()?.to_path_buf();
@@ -1743,6 +1746,53 @@ fn validate_distribution(
17431746
.errors
17441747
.push("python/PYTHON.json seen twice".to_string());
17451748
}
1749+
1750+
if path == PathBuf::from("python/install/bin/python") {
1751+
if let Some(link) = entry.link_name()? {
1752+
bin_python = Some(link.to_string_lossy().to_string());
1753+
} else {
1754+
context
1755+
.errors
1756+
.push("python/install/bin/python is not a symlink".to_string());
1757+
}
1758+
}
1759+
1760+
if path == PathBuf::from("python/install/bin/python3") {
1761+
if let Some(link) = entry.link_name()? {
1762+
bin_python3 = Some(link.to_string_lossy().to_string());
1763+
} else {
1764+
context
1765+
.errors
1766+
.push("python/install/bin/python3 is not a symlink".to_string());
1767+
}
1768+
}
1769+
}
1770+
1771+
match (bin_python, bin_python3) {
1772+
(None, None) => {
1773+
if !triple.contains("-windows-") {
1774+
context
1775+
.errors
1776+
.push("install/bin/python and python3 entries missing".to_string());
1777+
}
1778+
}
1779+
(None, Some(_)) => {
1780+
context
1781+
.errors
1782+
.push("install/bin/python symlink missing".to_string());
1783+
}
1784+
(Some(_), None) => {
1785+
context
1786+
.errors
1787+
.push("install/bin/python3 symlink missing".to_string());
1788+
}
1789+
(Some(python), Some(python3)) => {
1790+
if python != python3 {
1791+
context.errors.push(format!(
1792+
"symlink targets of install/bin/python and python3 vary: {python} !+ {python3}"
1793+
));
1794+
}
1795+
}
17461796
}
17471797

17481798
// We've now read the contents of the archive. Move on to analyzing the results.

0 commit comments

Comments
 (0)