Skip to content

Commit

Permalink
Reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 20, 2024
1 parent b5fd991 commit 24fe0f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 124 deletions.
68 changes: 34 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -689,40 +689,6 @@ jobs:
- name: "Validate global Python install"
run: py -3.13 ./scripts/check_system_python.py --uv ./uv.exe

system-test-windows-embedded-python-310:
needs: build-binary-windows
name: "check system | embedded python3.10 on windows"
runs-on: windows-latest
env:
# Avoid debug build stack overflows.
UV_STACK_SIZE: 2000000 # 2 megabyte, double the default on windows
steps:
- uses: actions/checkout@v4

- name: "Download binary"
uses: actions/download-artifact@v4
with:
name: uv-windows-${{ github.sha }}

# Download embedded Python.
- name: "Download embedded Python"
run: curl -LsSf https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip -o python-3.11.8-embed-amd64.zip

- name: "Unzip embedded Python"
run: 7z x python-3.11.8-embed-amd64.zip -oembedded-python

- name: "Show embedded Python contents"
run: ls embedded-python

- name: "Set PATH"
run: echo "${{ github.workspace }}\embedded-python" >> $env:GITHUB_PATH

- name: "Print Python path"
run: echo $(which python)

- name: "Validate global Python install"
run: python ./scripts/check_embedded_python.py --uv ./uv.exe

system-test-choco:
needs: build-binary-windows
name: "check system | python3.12 via chocolatey"
Expand Down Expand Up @@ -848,3 +814,37 @@ jobs:

- name: "Validate global Python install"
run: python3 scripts/check_system_python.py --uv ./uv

system-test-windows-embedded-python-310:
needs: build-binary-windows
name: "check system | embedded python3.10 on windows"
runs-on: windows-latest
env:
# Avoid debug build stack overflows.
UV_STACK_SIZE: 2000000 # 2 megabyte, double the default on windows
steps:
- uses: actions/checkout@v4

- name: "Download binary"
uses: actions/download-artifact@v4
with:
name: uv-windows-${{ github.sha }}

# Download embedded Python.
- name: "Download embedded Python"
run: curl -LsSf https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip -o python-3.11.8-embed-amd64.zip

- name: "Unzip embedded Python"
run: 7z x python-3.11.8-embed-amd64.zip -oembedded-python

- name: "Show embedded Python contents"
run: ls embedded-python

- name: "Set PATH"
run: echo "${{ github.workspace }}\embedded-python" >> $env:GITHUB_PATH

- name: "Print Python path"
run: echo $(which python)

- name: "Validate embedded Python install"
run: python ./scripts/check_embedded_python.py --uv ./uv.exe
110 changes: 20 additions & 90 deletions crates/uv-virtualenv/src/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ pub fn create_bare_venv(
// Create a `.gitignore` file to ignore all files in the venv.
fs::write(location.join(".gitignore"), "*")?;

// Per PEP 405, the Python `home` is the parent directory of the interpreter.
let python_home = base_python.parent().ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
"The Python interpreter needs to have a parent directory",
)
})?;

// Different names for the python interpreter
fs::create_dir(&scripts)?;
let executable = scripts.join(format!("python{EXE_SUFFIX}"));
Expand Down Expand Up @@ -175,10 +167,8 @@ pub fn create_bare_venv(
{
// https://github.com/python/cpython/blob/d457345bbc6414db0443819290b04a9a4333313d/Lib/venv/__init__.py#L261-L267
// https://github.com/pypa/virtualenv/blob/d9fdf48d69f0d0ca56140cf0381edbb5d6fe09f5/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py#L78-L83
// There's two kinds of applications on windows: Those that allocate a console (python.exe)
// and those that don't because they use window(s) (pythonw.exe).

// First priority: the `python.exe` and `pythonw.exe` shims.
// There's two kinds of applications on windows: Those that allocate a console (python.exe) and those that
// don't because they use window(s) (pythonw.exe).
for python_exe in ["python.exe", "pythonw.exe"] {
let shim = interpreter
.stdlib()
Expand All @@ -189,96 +179,27 @@ pub fn create_bare_venv(
match fs_err::copy(shim, scripts.join(python_exe)) {
Ok(_) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
// Second priority: the `venvlauncher.exe` and `venvwlauncher.exe` shims.
// These are equivalent to the `python.exe` and `pythonw.exe` shims, which were
// renamed in Python 3.13.
let launcher = match python_exe {
"python.exe" => "venvlauncher.exe",
"pythonw.exe" => "venvwlauncher.exe",
_ => unreachable!(),
};

// If `python.exe` doesn't exist, try the `venvlauncher.exe` shim.
let shim = interpreter
.stdlib()
.join("venv")
.join("scripts")
.join("nt")
.join(launcher);

// If the `venvlauncher.exe` shim doesn't exist, then on Conda at least, we
// can look for it next to the Python executable itself.
match fs_err::copy(shim, scripts.join(python_exe)) {
Ok(_) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
// Third priority: on Conda at least, we can look for the launcher shim next to
// the Python executable itself.
let shim = base_python.with_file_name(launcher);
match fs_err::copy(shim, scripts.join(python_exe)) {
Ok(_) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
// Fourth priority: if the launcher shim doesn't exist, assume this is
// an embedded Python. Copy the Python executable itself, along with
// the DLLs, `.pyd` files, and `.zip` files in the same directory.
fs_err::copy(
base_python.with_file_name(python_exe),
scripts.join(python_exe),
)?;

// Copy `.dll` and `.pyd` files from the top-level, and from the
// `DLLs` subdirectory (if it exists).
for directory in [
python_home,
interpreter.base_prefix().join("DLLs").as_path(),
] {
let entries = match fs_err::read_dir(directory) {
Ok(read_dir) => read_dir,
Err(err) if err.kind() == io::ErrorKind::NotFound => {
continue;
}
Err(err) => {
return Err(err.into());
}
};
for entry in entries {
let entry = entry?;
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "dll" || ext == "pyd" {
if let Some(file_name) = path.file_name() {
fs_err::copy(
&path,
scripts.join(file_name),
)?;
}
}
}
}
}

// Copy `.zip` files from the top-level.
let entries = match fs_err::read_dir(python_home) {
Ok(read_dir) => read_dir,
Err(err) if err.kind() == io::ErrorKind::NotFound => {
continue;
}
Err(err) => {
return Err(err.into());
}
};

for entry in entries {
let entry = entry?;
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "zip" {
if let Some(file_name) = path.file_name() {
fs_err::copy(&path, scripts.join(file_name))?;
}
}
}
}
}
Err(err) => {
return Err(err.into());
}
}
fs_err::copy(shim, scripts.join(python_exe))?;
}
Err(err) => {
return Err(err.into());
Expand Down Expand Up @@ -321,6 +242,18 @@ pub fn create_bare_venv(
fs::write(scripts.join(name), activator)?;
}

// Per PEP 405, the Python `home` is the parent directory of the interpreter.
let python_home = base_python
.parent()
.ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
"The Python interpreter needs to have a parent directory",
)
})?
.simplified_display()
.to_string();

// Validate extra_cfg
let reserved_keys = [
"home",
Expand All @@ -339,10 +272,7 @@ pub fn create_bare_venv(
}

let mut pyvenv_cfg_data: Vec<(String, String)> = vec![
(
"home".to_string(),
python_home.simplified_display().to_string(),
),
("home".to_string(), python_home),
(
"implementation".to_string(),
interpreter.markers().platform_python_implementation.clone(),
Expand Down

0 comments on commit 24fe0f6

Please sign in to comment.