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

python: use Python Environment Tools for interpreter discovery #5897

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2d1658c
install PET in CI
isabelizimm Jan 7, 2025
72ce282
install nox into ci
isabelizimm Jan 7, 2025
5d4a4cf
take into account different wd for ts tests
isabelizimm Jan 7, 2025
3e317cb
specify which noxfile
isabelizimm Jan 7, 2025
9c2ddba
use actions for smoke tests to build vsix
isabelizimm Jan 8, 2025
c8db8b0
correct path name
isabelizimm Jan 8, 2025
06d13d4
cd into positron-python every time(?)
isabelizimm Jan 8, 2025
f1d2c1f
format yml
isabelizimm Jan 8, 2025
8b247ed
place pet in project dir
isabelizimm Jan 8, 2025
8ba5db2
do not clone with special-working-dir
isabelizimm Jan 9, 2025
77efe40
debug where vsix is
isabelizimm Jan 9, 2025
55b7461
rm tmate session
isabelizimm Jan 9, 2025
c0ddffb
move to ext dir
isabelizimm Jan 9, 2025
b01e189
try quotes perhaps
isabelizimm Jan 9, 2025
383cf53
try to move file again
isabelizimm Jan 9, 2025
c5a64c9
using working-directory arg
isabelizimm Jan 9, 2025
018cd9f
no working dir for upload
isabelizimm Jan 9, 2025
2d9ca1b
use cp instead of mv
isabelizimm Jan 10, 2025
c57dca8
upload vsix for smoke tests
isabelizimm Jan 10, 2025
db5cf4c
update paths for smoke tests
isabelizimm Jan 10, 2025
69dbdb1
include version in interpreter name
isabelizimm Jan 13, 2025
aed1167
add pet specific tests
isabelizimm Jan 13, 2025
5dcf7bf
include PROJECT_DIR for cargo tests
isabelizimm Jan 13, 2025
ad4dbb1
scripts to download and unzip python-env-tools
isabelizimm Jan 14, 2025
8fc277c
script to build pet
isabelizimm Jan 14, 2025
b6f7586
copyright headers
isabelizimm Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/install-pet/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Setup Python Environment Tools"
description: "Install and build microsoft/python-environment-tools"

runs:
using: "composite"
steps:
- name: Checkout Python Environment Tools
uses: actions/checkout@v4
with:
repository: 'microsoft/python-environment-tools'
path: 'extensions/positron-python/python-env-tools'
sparse-checkout: |
crates
Cargo.toml
Cargo.lock
sparse-checkout-cone-mode: false

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

- name: Build Native Binaries
run: nox --noxfile extensions/positron-python/noxfile.py --session native_build
shell: bash
1 change: 1 addition & 0 deletions .github/actions/install-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ runs:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install ipykernel trcli
python -m pip install nox

- name: Verify Python Version
shell: bash
Expand Down
104 changes: 104 additions & 0 deletions .github/actions/python-build-vsix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: 'Build VSIX'
description: "Build the extension's VSIX"

inputs:
node_version:
description: 'Version of Node to install'
required: true
vsix_name:
description: 'Name to give the final VSIX'
required: true
artifact_name:
description: 'Name to give the artifact containing the VSIX'
required: true
cargo_target:
description: 'Cargo build target for the native build'
required: true
vsix_target:
description: 'vsix build target for the native build'
required: true

runs:
using: 'composite'
steps:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
cache: 'npm'

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

# Jedi LS depends on dataclasses which is not in the stdlib in Python 3.7.
- name: Use Python 3.8 for JediLSP
uses: actions/setup-python@v5
with:
python-version: 3.8
cache: 'pip'
cache-dependency-path: |
extensions/positron-python/requirements.txt
Copy link
Contributor Author

@isabelizimm isabelizimm Jan 10, 2025

Choose a reason for hiding this comment

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

is there a way to add a working directory for files in .github/actions/? It doesn't look like the way we set it in the Python CI works in this directory.

defaults:
run:
working-directory: 'extensions/positron-python'

extensions/positron-python/python_files/jedilsp_requirements/requirements.txt

- name: Upgrade Pip
run: python -m pip install -U pip
shell: bash

# For faster/better builds of sdists.
- name: Install build pre-requisite
run: python -m pip install wheel nox
shell: bash

- name: Install Python Extension dependencies (jedi, etc.)
run: nox --noxfile extensions/positron-python/noxfile.py --session install_python_libs
shell: bash

- name: Add Rustup target
run: rustup target add ${{ inputs.cargo_target }}
shell: bash

- name: Build Native Binaries
run: nox --noxfile extensions/positron-python/noxfile.py --session native_build
shell: bash
env:
CARGO_TARGET: ${{ inputs.cargo_target }}

- name: Run npm ci
run: |
cd extensions/positron-python
npm ci --prefer-offline
shell: bash

- name: Update optional extension dependencies
run: |
cd extensions/positron-python
npm run addExtensionPackDependencies
shell: bash

- name: Build Webpack
run: |
cd extensions/positron-python
npx gulp clean
npx gulp prePublishBundle
shell: bash

- name: Build VSIX
run: |
cd extensions/positron-python
npx vsce package --target ${{ inputs.vsix_target }} --out positron-python-dev.vsix --pre-release
shell: bash

- name: Rename VSIX
working-directory: extensions/positron-python
# Move to a temp name in case the specified name happens to match the default name.
run: |
cp positron-python-dev.vsix positron-python-dev-temp.vsix && mv positron-python-dev-temp.vsix ${{ inputs.vsix_name }}
shell: bash

- name: Upload VSIX
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: extensions/positron-python/${{ inputs.vsix_name }}
if-no-files-found: error
retention-days: 2
70 changes: 70 additions & 0 deletions .github/actions/python-smoke-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: 'Smoke tests'
description: 'Run smoke tests'

inputs:
node_version:
description: 'Version of Node to install'
required: true
artifact_name:
description: 'Name of the artifact containing the VSIX'
required: true

runs:
using: 'composite'
steps:
- name: Update working directory
run: cd extensions/positron-python
shell: bash

- name: Install Node
uses: actions/setup-node@v2
with:
node-version: ${{ inputs.node_version }}
cache: 'npm'

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
cache: 'pip'
cache-dependency-path: |
extensions/positron-python/build/test-requirements.txt
extensions/positron-python/equirements.txt

- name: Install dependencies (npm ci)
run: npm ci --prefer-offline
shell: bash

- name: Install Python requirements
uses: brettcannon/pip-secure-install@v1
with:
options: '-t extensions/positron-python/python_files/lib/python --implementation py'

- name: pip install system test requirements
run: |
python -m pip install --upgrade -r extensions/positron-python/build/test-requirements.txt
shell: bash

# Bits from the VSIX are reused by smokeTest.ts to speed things up.
- name: Download VSIX
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact_name }}

- name: Prepare for smoke tests
run: npx tsc -p ./
shell: bash

- name: Set CI_PYTHON_PATH and CI_DISABLE_AUTO_SELECTION
run: |
echo "CI_PYTHON_PATH=python" >> $GITHUB_ENV
echo "CI_DISABLE_AUTO_SELECTION=1" >> $GITHUB_ENV
shell: bash

- name: Run smoke tests
env:
DISPLAY: 10
INSTALL_JUPYTER_EXTENSION: true
uses: GabrielBB/[email protected]
with:
run: node --no-force-async-hooks-checks ./extensions/positron-python/out/test/smokeTest.js
3 changes: 3 additions & 0 deletions .github/actions/setup-test-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ runs:
with:
version: "3.10"

- name: Setup Python Environment Tools
uses: ./.github/actions/install-pet

- name: Setup R
uses: ./.github/actions/install-r
with:
Expand Down
109 changes: 103 additions & 6 deletions .github/workflows/positron-python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defaults:
env:
NODE_VERSION: '20.12.1'
PYTHON_VERSION: '3.10'
ARTIFACT_NAME_VSIX: positron-python-dev-vsix
PROJECT_DIR: 'extensions/positron-python'
PYTHON_SRC_DIR: 'extensions/positron-python/python_files'
# Force a path with spaces and to test extension works in these scenarios
Expand Down Expand Up @@ -244,6 +245,17 @@ jobs:
with:
path: ${{ env.special-working-directory-relative }}

- name: Checkout Python Environment Tools
uses: actions/checkout@v4
with:
repository: 'microsoft/python-environment-tools'
path: ${{ env.special-working-directory }}/${{ env.PROJECT_DIR}}/python-env-tools
sparse-checkout: |
crates
Cargo.toml
Cargo.lock
sparse-checkout-cone-mode: false

- name: Install Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
Expand All @@ -267,7 +279,16 @@ jobs:
run: npx @vscode/l10n-dev@latest export ./src

- name: Install test requirements
run: python -m pip install --upgrade -r ./build/test-requirements.txt
run: |
python -m pip install --upgrade -r ./build/test-requirements.txt
python -m pip install nox

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

- name: Build Native Binaries
run: nox --session native_build
shell: bash

- name: Install functional test requirements
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
Expand Down Expand Up @@ -404,8 +425,84 @@ jobs:
run: npm run test:functional
if: matrix.test-suite == 'functional'

- name: Run smoke tests
env:
POSITRON_GITHUB_PAT: ${{ github.token }}
run: npx tsc && node ./out/test/smokeTest.js
if: matrix.test-suite == 'smoke'
build-vsix:
name: Create VSIX
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# - os: windows-latest
# target: x86_64-pc-windows-msvc
# vsix-target: win32-x64
# - os: windows-latest
# target: aarch64-pc-windows-msvc
# vsix-target: win32-arm64
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
vsix-target: linux-x64
# - os: ubuntu-latest
# target: x86_64-unknown-linux-musl
# vsix-target: alpine-x64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Checkout Python Environment Tools
uses: actions/checkout@v4
with:
repository: 'microsoft/python-environment-tools'
path: '${{ env.PROJECT_DIR}}/python-env-tools'
sparse-checkout: |
crates
Cargo.toml
Cargo.lock
sparse-checkout-cone-mode: false

- name: Build VSIX
uses: ./.github/actions/python-build-vsix
with:
node_version: ${{ env.NODE_VERSION}}
vsix_name: 'positron-python-dev-${{ matrix.vsix-target }}.vsix'
artifact_name: '${{ env.ARTIFACT_NAME_VSIX }}-${{ matrix.vsix-target }}'
cargo_target: ${{ matrix.target }}
vsix_target: ${{ matrix.vsix-target }}
path: '${{ env.PROJECT_DIR}}/python-env-tools'

smoke-tests:
name: Smoke tests
# The value of runs-on is the OS of the current job (specified in the strategy matrix below) instead of being hardcoded.
runs-on: ${{ matrix.os }}
needs: [build-vsix]
strategy:
fail-fast: false
matrix:
# We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
# macOS runners are expensive, and we assume that Ubuntu is enough to cover the UNIX case.
include:
# - os: windows-latest
# vsix-target: win32-x64
- os: ubuntu-latest
vsix-target: linux-x64

steps:
# Need the source to have the tests available.
- name: Checkout
uses: actions/checkout@v4

- name: Checkout Python Environment Tools
uses: actions/checkout@v4
with:
repository: 'microsoft/python-environment-tools'
path: '${{ env.special-working-directory }}/${{ env.PROJECT_DIR}}/python-env-tools'
sparse-checkout: |
crates
Cargo.toml
Cargo.lock
sparse-checkout-cone-mode: false

- name: Smoke tests
uses: ./.github/actions/python-smoke-tests
with:
node_version: ${{ env.NODE_VERSION }}
artifact_name: '${{ env.ARTIFACT_NAME_VSIX }}-${{ matrix.vsix-target }}'
2 changes: 1 addition & 1 deletion extensions/positron-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
"type": "string"
},
"python.locator": {
"default": "js",
"default": "native",
Copy link
Contributor Author

@isabelizimm isabelizimm Jan 7, 2025

Choose a reason for hiding this comment

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

Right now, the rust locator is considered experimental and is opt-in only for upstream. I've swapped it for testing purposes, but we'll want to decide what we want as the default. I've played around with it locally, and it seems to be finding everything and is MUCH FASTER, eg, 1-3 seconds to find my 80+ envs. We should do a bit more robust testing before deciding though.

"description": "%python.locator.description%",
"enum": [
"js",
Expand Down
Loading