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

Allow execute on enter for IW REPL #23440

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
de3ae76
Add native locator for finding pythons (#23208)
karthiknadig May 3, 2024
e0f58c7
Add `python.nativeLocator` experimental setting (#23324)
karthiknadig May 3, 2024
98cd475
Add more Windows based locators (#23325)
karthiknadig May 3, 2024
2e74d67
Add logging over JSON-RPC (#23326)
karthiknadig May 3, 2024
19b7884
Fix compilation error and use PathBuf::from (#23339)
DonJayamanne May 6, 2024
297d826
Conda and Known Python Tests (#23349)
DonJayamanne May 7, 2024
d307787
Fix typo in windows locator (#23355)
DonJayamanne May 7, 2024
dcbedd2
Support for pyenv locator (#23356)
DonJayamanne May 7, 2024
e357770
Use enum for category (#23357)
DonJayamanne May 7, 2024
76f358f
Adopt native pyenv locator in TS land (#23359)
DonJayamanne May 7, 2024
bac7d76
Add sysPrefixPath to native locator (#23360)
DonJayamanne May 7, 2024
a910ebf
Fix discovery of native conda locator (#23361)
DonJayamanne May 7, 2024
6ffaac6
Ensure all messages are JSON rpc payloads (#23362)
DonJayamanne May 7, 2024
5a84a9d
Add native homebrew locator on mac (#23363)
DonJayamanne May 7, 2024
7368e9f
Homebrew only on unix and not windows (#23364)
DonJayamanne May 7, 2024
5ca283d
Better py env version extraction (#23368)
DonJayamanne May 7, 2024
8d2b5e2
Remove unwanted test feature (#23371)
DonJayamanne May 8, 2024
d57cdee
Support for pyenv virtual-env in native locator (#23372)
DonJayamanne May 8, 2024
e5f90a3
Extract conda version where possible in native locator (#23374)
DonJayamanne May 8, 2024
0c16df9
Compute regex once in native locator (#23375)
DonJayamanne May 8, 2024
40ebe7a
Strip 'envs' prefix from conda env name (#23377)
DonJayamanne May 8, 2024
bf5af07
Update python env properties sent back to TS layer (#23378)
DonJayamanne May 8, 2024
e187cbe
Add support for pipenv environments (#23379)
DonJayamanne May 8, 2024
cdb58d4
Fixes to detection of conda version on windows (#23380)
DonJayamanne May 8, 2024
742cbfd
Tweek pyenv version detection on windows (#23383)
DonJayamanne May 8, 2024
c7410a4
Support virtualenvwrapper in nativelocator (#23388)
DonJayamanne May 8, 2024
a7d44e9
virtualenvwrapper support in ts layer of native locator (#23390)
DonJayamanne May 8, 2024
9800de6
Tweaks to how native finder is spawned and logging (#23387)
karthiknadig May 8, 2024
3ca8b6c
Drop jsonrpc connection after all messages are handled (#23391)
DonJayamanne May 9, 2024
1b72817
Use PathBufs to avoid regular conversions (#23393)
DonJayamanne May 9, 2024
a4c9895
Use structs instead of loose json in native test (#23394)
DonJayamanne May 9, 2024
cb50051
Support venv, virtualEnv in global folders (#23395)
DonJayamanne May 9, 2024
67328cf
End the passthrough stream instead of ending (#23399)
DonJayamanne May 9, 2024
66501c3
Refactor locators to implement a specific trait (#23404)
DonJayamanne May 10, 2024
860c774
Use logger formatter to send log msgs via json rpc (#23405)
DonJayamanne May 10, 2024
e21c3c8
Remove duplicate environment finder event handlers (#23406)
DonJayamanne May 10, 2024
f458bea
Remove duplicates from reported envs & refactor locators (#23407)
DonJayamanne May 10, 2024
c344804
Replace locator enum with struct (#23412)
DonJayamanne May 13, 2024
6ae88b6
Look for Python (PythonCore) in windows registry (#23414)
DonJayamanne May 13, 2024
61c55c8
Fix extraction of Python version for Conda environments (#23415)
DonJayamanne May 13, 2024
43581b9
Fixes to comparing of Python environments (#23417)
DonJayamanne May 13, 2024
9626124
Revised native conda locator (#23416)
DonJayamanne May 13, 2024
be95b61
Fix winreg locator & add conda registry locator on windows (#23422)
DonJayamanne May 14, 2024
6ddcc05
Updates to the native windows store locator (#23426)
DonJayamanne May 14, 2024
885d63b
Add more logging and some tweaks (#23425)
karthiknadig May 14, 2024
2729d84
Remove sysPrefixPath from native locator (#23427)
DonJayamanne May 14, 2024
aa4d805
Search for conda envs in known locations (#23428)
DonJayamanne May 15, 2024
9af31c8
Ignore native locator tests folder (#23436)
DonJayamanne May 15, 2024
225da4b
Add Interactive REPL Experiment (#23235)
anthonykim1 May 16, 2024
bb6ba77
Start implementing execute on enter
anthonykim1 May 16, 2024
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
7 changes: 7 additions & 0 deletions .github/actions/build-vsix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ runs:
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
Expand All @@ -44,6 +47,10 @@ runs:
run: nox --session install_python_libs
shell: bash

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

- name: Run npm ci
run: npm ci --prefer-offline
shell: bash
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,30 @@ jobs:
run: npm run test:functional
if: matrix.test-suite == 'functional'

native-tests:
name: Native 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 }}
defaults:
run:
working-directory: ${{ env.special-working-directory }}
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.
os: [ubuntu-latest, windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: ${{ env.special-working-directory-relative }}

- name: Native Locator tests
run: cargo test -- --nocapture
working-directory: ${{ env.special-working-directory }}/native_locator

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.
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ dist/**
*.xlf
package.nls.*.json
l10n/
native_locator/target/**
native_locator/Cargo.lock
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
],
"compounds": [
{
"name": "Debug Test Discovery",
"name": "Debug Python and Extension",
"configurations": ["Python: Attach Listen", "Extension"]
}
]
Expand Down
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
},
"editor.defaultFormatter": "charliermarsh.ruff",
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
Expand Down Expand Up @@ -67,5 +71,8 @@
"python_files/tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"rust-analyzer.linkedProjects": [
".\\native_locator\\Cargo.toml"
]
}
5 changes: 5 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ test/**
tmp/**
typings/**
types/**
native_locator/src/**
native_locator/tests/**
native_locator/bin/**
native_locator/target/**
native_locator/Cargo.*
19 changes: 19 additions & 0 deletions native_locator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "python-finder"
version = "0.1.0"
edition = "2021"

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"

[dependencies]
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
serde_repr = "0.1.10"
regex = "1.10.4"
log = "0.4.21"
env_logger = "0.10.2"


[lib]
doctest = false
91 changes: 91 additions & 0 deletions native_locator/src/common_python.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use crate::known::Environment;
use crate::locator::{Locator, LocatorResult};
use crate::messaging::PythonEnvironment;
use crate::utils::{self, PythonEnv};
use std::env;
use std::path::{Path, PathBuf};

fn get_env_path(python_executable_path: &PathBuf) -> Option<PathBuf> {
let parent = python_executable_path.parent()?;
if parent.file_name()? == "Scripts" {
return Some(parent.parent()?.to_path_buf());
} else {
return Some(parent.to_path_buf());
}
}

pub struct PythonOnPath<'a> {
pub environment: &'a dyn Environment,
}

impl PythonOnPath<'_> {
pub fn with<'a>(environment: &'a impl Environment) -> PythonOnPath {
PythonOnPath { environment }
}
}

impl Locator for PythonOnPath<'_> {
fn resolve(&self, env: &PythonEnv) -> Option<PythonEnvironment> {
let bin = if cfg!(windows) {
"python.exe"
} else {
"python"
};
if env.executable.file_name().unwrap().to_ascii_lowercase() != bin {
return None;
}
Some(PythonEnvironment {
display_name: None,
name: None,
python_executable_path: Some(env.executable.clone()),
version: env.version.clone(),
category: crate::messaging::PythonEnvironmentCategory::System,
env_path: env.path.clone(),
env_manager: None,
project_path: None,
python_run_command: Some(vec![env.executable.to_str().unwrap().to_string()]),
})
}

fn find(&mut self) -> Option<LocatorResult> {
let paths = self.environment.get_env_var("PATH".to_string())?;
let bin = if cfg!(windows) {
"python.exe"
} else {
"python"
};

// Exclude files from this folder, as they would have been discovered elsewhere (widows_store)
// Also the exe is merely a pointer to another file.
let home = self.environment.get_user_home()?;
let apps_path = Path::new(&home)
.join("AppData")
.join("Local")
.join("Microsoft")
.join("WindowsApps");
let mut environments: Vec<PythonEnvironment> = vec![];
env::split_paths(&paths)
.filter(|p| !p.starts_with(apps_path.clone()))
.map(|p| p.join(bin))
.filter(|p| p.exists())
.for_each(|full_path| {
let version = utils::get_version(&full_path);
let env_path = get_env_path(&full_path);
if let Some(env) = self.resolve(&PythonEnv::new(full_path, env_path, version)) {
environments.push(env);
}
});

if environments.is_empty() {
None
} else {
Some(LocatorResult {
environments,
managers: vec![],
})
}
}
}
Loading