diff --git a/.github/workflows/rust-compile.yml b/.github/workflows/rust-compile.yml index 677052e0..7bdc7264 100644 --- a/.github/workflows/rust-compile.yml +++ b/.github/workflows/rust-compile.yml @@ -121,3 +121,35 @@ jobs: ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} -- --nocapture + + + # test if venv works properly on windows + # using old and newest python version + # our implementation will fail on 3.7.4 + # and we emit warning + - name: Install pixi + uses: prefix-dev/setup-pixi@v0.4.1 + with: + run-install: false + + - name: Run pixi python==3.7.5 test + if: contains(matrix.name, 'Windows') + shell: bash + run: | + mkdir pixi_old + cd pixi_old + pixi init + pixi add "python==3.7.5" + cd ../ + cargo run -- boltons --only-sdists -p /d/a/rip/rip/pixi_old/.pixi/env/python.exe + + - name: Run pixi latest python test + if: contains(matrix.name, 'Windows') + shell: bash + run: | + mkdir pixi_new + cd pixi_new + pixi init + pixi add python + cd ../ + cargo run -- boltons --only-sdists -p /d/a/rip/rip/pixi_new/.pixi/env/python.exe diff --git a/crates/rattler_installs_packages/src/python_env/venv.rs b/crates/rattler_installs_packages/src/python_env/venv.rs index 6cdd0181..a59f5c17 100644 --- a/crates/rattler_installs_packages/src/python_env/venv.rs +++ b/crates/rattler_installs_packages/src/python_env/venv.rs @@ -154,16 +154,10 @@ impl VEnv { let exe_path = install_paths.scripts().join(base_python_name); let abs_exe_path = venv_abs_dir.join(exe_path); - #[cfg(not(windows))] { Self::setup_python(&abs_exe_path, &base_python_path, base_python_version)?; } - #[cfg(windows)] - { - Self::setup_python(&abs_exe_path, &base_python_path)?; - } - Ok(VEnv::new(venv_abs_dir.to_path_buf(), install_paths)) } @@ -245,18 +239,18 @@ prompt = {}"#, pub fn setup_python( venv_exe_path: &Path, original_python_exe: &Path, - #[cfg(not(windows))] python_version: PythonInterpreterVersion, + python_version: PythonInterpreterVersion, ) -> std::io::Result<()> { - if !venv_exe_path.exists() { - copy_file(original_python_exe, venv_exe_path)?; - } - let venv_bin = venv_exe_path .parent() .expect("venv exe binary should have parent folder"); #[cfg(not(windows))] { + if !venv_exe_path.exists() { + copy_file(original_python_exe, venv_exe_path)?; + } + let python_bins = [ "python", "python3", @@ -273,6 +267,11 @@ prompt = {}"#, #[cfg(windows)] { + if python_version.major <= 3 && python_version.minor <= 7 && python_version.patch <= 4 { + tracing::warn!( + "Creation of venv for <=3.7.4 on windows may fail. Please use newer version" + ); + } let base_exe_name = venv_exe_path .file_name() .expect("cannot get windows venv exe name"); @@ -291,11 +290,32 @@ prompt = {}"#, .expect("cannot get system python parent folder"); for bin_name in python_bins.into_iter() { let original_python_bin = original_python_bin_dir.join(bin_name); + let original_python_scripts = original_python_bin_dir + .join("Lib/venv/scripts/nt") + .join(bin_name); + let venv_python_bin = venv_bin.join(bin_name); - if original_python_bin.exists() { - let venv_python_bin = venv_bin.join(bin_name); - if !venv_python_bin.exists() { - copy_file(venv_exe_path, &venv_python_bin)?; + if original_python_bin.exists() && !venv_python_bin.exists() { + if original_python_scripts.is_file() { + copy_file(original_python_scripts, &venv_python_bin)?; + } else { + // If used python is built from source code + // or we are using a python from venv which + // was created using python from source code + // we need to move venvlauncher + // and venvwlauncher as python.exe and pythonw.exe + // instead of using the python.exe shipped with /venv/scripts/nt + let launcher_bin_name = if bin_name.contains("python") { + bin_name.replace("python", "venvlauncher") + } else if bin_name.contains("pythonw") { + bin_name.replace("pythonw", "venvwlauncher") + } else { + bin_name.to_owned() + }; + let original_launcher_bin = original_python_bin_dir.join(launcher_bin_name); + if original_launcher_bin.exists() { + copy_file(original_launcher_bin, &venv_python_bin)?; + } } } }