Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finding Python within virtualenv on Windows #2034

Merged
merged 12 commits into from
Dec 20, 2024

Conversation

denik
Copy link
Contributor

@denik denik commented Dec 18, 2024

Changes

Simplify logic for selecting Python to run when calculating default whl build command: "python" on Windows and "python3" everywhere.

Python installers from python.org do not install python3.exe. In virtualenv there is no python3.exe.

Tests

Added new unit tests to create real venv with uv and simulate activation by prepending venv/bin to PATH.

@denik denik temporarily deployed to test-trigger-is December 18, 2024 19:51 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 18, 2024 19:52 — with GitHub Actions Inactive
@denik denik force-pushed the DECO-24194--fix-venv-windows branch from a1fc119 to 7fbd9fe Compare December 18, 2024 20:14
@denik denik temporarily deployed to test-trigger-is December 18, 2024 20:14 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 18, 2024 20:14 — with GitHub Actions Inactive
@denik denik force-pushed the DECO-24194--fix-venv-windows branch from 7fbd9fe to 3c3c172 Compare December 18, 2024 20:15
@denik denik temporarily deployed to test-trigger-is December 18, 2024 20:15 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 18, 2024 20:15 — with GitHub Actions Inactive
@denik denik enabled auto-merge December 18, 2024 20:44
@denik denik disabled auto-merge December 19, 2024 08:24
internal/testutil/env.go Outdated Show resolved Hide resolved
internal/testutil/env.go Outdated Show resolved Hide resolved

// On Windows when virtualenv is created, the <env>/Scripts directory
// contains python.exe but no python3.exe. However, system python does have python3 entry
// and it is also added to PATH, so it is found first.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this regress the non-venv cases where python.exe resolves to a system-wide Python 2 installation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, if they somehow managed to have Python2 installed in the first place, but why would they have that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see python3 mentioned in another place in this module - it also won't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter which Windows terminal is being used? Some users might use Git Bash for example and maybe the behaviour is different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should not matter

libs/python/detect.go Outdated Show resolved Hide resolved
libs/python/pythontest/pythontest.go Outdated Show resolved Hide resolved
libs/python/pythontest/pythontest.go Outdated Show resolved Hide resolved
)

func TestVenv(t *testing.T) {
// Test at least two version to ensure we capture a case where venv version does not match system one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart :)

@denik denik temporarily deployed to test-trigger-is December 19, 2024 09:14 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 09:14 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 09:30 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 09:30 — with GitHub Actions Inactive
@denik denik requested a review from pietern December 19, 2024 09:30
@eng-dev-ecosystem-bot
Copy link
Collaborator

Test Details: go/deco-tests/12409928666

libs/python/pythontest/pythontest.go Show resolved Hide resolved

// On Windows when virtualenv is created, the <env>/Scripts directory
// contains python.exe but no python3.exe. However, system python does have python3 entry
// and it is also added to PATH, so it is found first.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter which Windows terminal is being used? Some users might use Git Bash for example and maybe the behaviour is different?

libs/python/pythontest/pythontest.go Show resolved Hide resolved
libs/python/pythontest/pythontest.go Show resolved Hide resolved
@denik denik requested a review from andrewnester December 19, 2024 10:07
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:17 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:17 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:25 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:25 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:30 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 13:30 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:26 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:26 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:27 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:27 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:42 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:42 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:49 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 19, 2024 14:49 — with GitHub Actions Inactive
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 2034
  • Commit SHA: 3bf36aaedd4a4f6eb166adc300a1f11ed6c65638

Checks will be approved automatically on success.

@denik denik enabled auto-merge December 19, 2024 17:05
@denik denik added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit 2fee243 Dec 20, 2024
9 checks passed
@denik denik deleted the DECO-24194--fix-venv-windows branch December 20, 2024 07:49
pietern added a commit that referenced this pull request Jan 8, 2025
Bundles:
 * Fix finding Python within virtualenv on Windows ([#2034](#2034)).
 * Include missing field descriptions in JSON schema ([#2045](#2045)).
 * Add validation for volume referenced from `artifact_path` ([#2050](#2050)).
 * Handle `${workspace.file_path}` references in source-linked deployments ([#2046](#2046)).
 * Set the write bit for files written during template initialization ([#2068](#2068)).
github-merge-queue bot pushed a commit that referenced this pull request Jan 8, 2025
Bundles:
* Fix finding Python within virtualenv on Windows
([#2034](#2034)).
* Include missing field descriptions in JSON schema
([#2045](#2045)).
* Add validation for volume referenced from `artifact_path`
([#2050](#2050)).
* Handle `${workspace.file_path}` references in source-linked
deployments ([#2046](#2046)).
* Set the write bit for files written during template initialization
([#2068](#2068)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants