Skip to content

Commit

Permalink
Merge branch 'main' into users/merlinbot/1es-pt-auto-baselining-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 authored Feb 11, 2025
2 parents 0856a06 + ebeb53f commit f8da764
Show file tree
Hide file tree
Showing 28 changed files with 366 additions and 77 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/linux-homebrew/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ RUN curl https://raw.githubusercontent.com/DonJayamanne/vscode-jupyter/container
RUN echo "# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh." >> ~/.zshrc
RUN echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> ~/.zshrc

# Install Pythone
# Install Python
# homebrew/brew:4.4.6 broke running `brew install` as root.
# As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`.
RUN brew update || true
RUN brew install python@3.12 python@3.11

# Install Rust
Expand Down
54 changes: 38 additions & 16 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- release*
- release/*
- release-*
workflow_dispatch:

jobs:
tests:
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
- name: Set Python to PATH
uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version: "3.12"

- name: Homebrew Python
if: startsWith( matrix.os, 'macos')
Expand Down Expand Up @@ -133,7 +134,7 @@ jobs:
if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos')
run: |
pyenv install --list
pyenv install 3.12.6 3.8.19
pyenv install 3.13.0 3.12.8 3.8.20
shell: bash

# pyenv-win install list has not updated for a while
Expand Down Expand Up @@ -166,6 +167,23 @@ jobs:

# endregion venv

# region Pixi
- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
run-install: false

- name: Create Pixi environments
run: |
pixi init
pixi add python
pixi add --feature dev python
pixi project environment add --feature dev dev
pixi install --environment dev
shell: bash

# endregion Pixi

# Rust
- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable
Expand All @@ -179,7 +197,7 @@ jobs:

- name: Find Environments
if: matrix.run_cli == 'yes'
run: cargo run --release --target ${{ matrix.target }}
run: cargo run --release --target ${{ matrix.target }} -- find -v -l
shell: bash

- name: Run Tests
Expand Down Expand Up @@ -230,7 +248,7 @@ jobs:
if: startsWith( matrix.feature, 'ci-poetry')
uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version: "3.12"

- name: Set Python 3.12 to PATH
if: startsWith( matrix.feature, 'ci-poetry')
Expand Down Expand Up @@ -286,48 +304,48 @@ jobs:
virtualenvs-path: ~/my-custom-path
installer-parallel: true

- name: Petry exe
- name: Poetry exe
if: startsWith( matrix.feature, 'ci-poetry')
run: which poetry
shell: bash

- name: Petry config
- name: Poetry config
if: startsWith( matrix.feature, 'ci-poetry')
run: poetry config --list
shell: bash

- name: Petry setup
- name: Poetry setup
if: startsWith( matrix.feature, 'ci-poetry')
# We want to have 2 envs for this poetry project 3.12 and 3.11.
run: poetry init --name=pet-test --python=^3.11 -q -n
shell: bash

- name: Petry virtual env setup 3.12
- name: Poetry virtual env setup 3.12
if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu')
run: poetry env use 3.12
shell: bash

- name: Petry virtual env setup 3.12
- name: Poetry virtual env setup 3.12
if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows')
run: poetry env use $PYTHON_3_12_PATH
shell: bash

- name: Petry virtual env setup 3.11
- name: Poetry virtual env setup 3.11
if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu')
run: poetry env use 3.11
shell: bash

- name: Petry virtual env setup 3.11
- name: Poetry virtual env setup 3.11
if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows')
run: poetry env use $PYTHON_3_11_PATH
shell: bash

- name: Petry list envs
- name: Poetry list envs
if: startsWith( matrix.feature, 'ci-poetry')
run: poetry env list
shell: bash

- name: Petry pyproject.toml
- name: Poetry pyproject.toml
if: startsWith( matrix.feature, 'ci-poetry')
run: cat pyproject.toml
shell: bash
Expand All @@ -351,7 +369,7 @@ jobs:
shell: bash

- name: Find Environments
run: cargo run --release --target ${{ matrix.target }}
run: cargo run --release --target ${{ matrix.target }} -- find -v -l
shell: bash

- name: Run Tests
Expand Down Expand Up @@ -394,7 +412,11 @@ jobs:
# Homebrew
- name: Homebrew Python
if: startsWith( matrix.image, 'homebrew')
run: brew install python@3.12 python@3.11
run: |
# homebrew/brew:4.4.6 broke running `brew install` as root.
# As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`.
brew update || true
brew install python@3.12 python@3.11
shell: bash

# Rust
Expand All @@ -409,7 +431,7 @@ jobs:
shell: bash

- name: Find Environments
run: cargo run --release --target ${{ matrix.target }}
run: cargo run --release --target ${{ matrix.target }} -- find -v -l
shell: bash

- name: Run Tests
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Python environment tools for Visual Studio Code

Performant Python environment tooling and support, such as locating all global Python installs and virtual environments.
Performant Python environment tooling and support, such as locating all global Python installs and virtual environments.

This project will be consumed by the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) directly. You can find the code to consume `pet` in the Python extension [source code](https://github.com/microsoft/vscode-python/blob/main/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts). For more information on JSNORPC requests/notifications for this tool, please reference [/docs/JSONRPC.md](https://github.com/microsoft/python-environment-tools/blob/main/docs/JSONRPC.md).

## Environment Types Supported

Expand Down
18 changes: 9 additions & 9 deletions azure-pipelines/pre-release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Run on a schedule
trigger: none
trigger:
branches:
include:
- main
pr: none

schedules:
- cron: "0 10 * * 1-5" # 10AM UTC (2AM PDT) MON-FRI (VS Code Pre-release builds at 9PM PDT)
displayName: Nightly Pre-Release Schedule
always: false # only run if there are source code changes
branches:
include:
- main

resources:
repositories:
- repository: templates
Expand All @@ -26,6 +21,11 @@ extends:
signing: true
buildWasm: false
apiScanSoftwareVersion: 2024 # major version of `pet` for internal reporting
tsa:
enabled: true
config:
areaPath: "Visual Studio Code Python Extensions"
serviceTreeID: 6e6194bc-7baa-4486-86d0-9f5419626d46

buildPlatforms:
- name: Linux
Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ extends:
binaryName: "pet"
signing: true
buildWasm: false
apiScanPublishSymbols: true
apiScanSoftwareVersion: 2024 # major version of `pet` for internal reporting
tsa:
enabled: true
config:
areaPath: "Visual Studio Code Python Extensions"
serviceTreeID: 6e6194bc-7baa-4486-86d0-9f5419626d46

buildPlatforms:
- name: Linux
Expand Down
5 changes: 0 additions & 5 deletions crates/pet-conda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
- Thus using the `history` file we can find the conda installation folder.
This is useful in cases where conda environments are created using `-p` option.

## Known issues

- Note: pixi seems to use conda envs internall, hence its possible to falsely identify a pixi env as a conda env.
- However pixi is not supported by this tool, hence thats not a concern.

## Miscellanous

- What if conda is installed in some custom locations that we have no idea about?
Expand Down
1 change: 1 addition & 0 deletions crates/pet-conda/src/conda_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ fn get_conda_conda_rc_from_path(conda_rc: &PathBuf) -> Option<Condarc> {
if env_dirs.is_empty() && files.is_empty() {
None
} else {
trace!("conda_rc: {:?} with env_dirs {:?}", conda_rc, env_dirs);
Some(Condarc { env_dirs, files })
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/pet-conda/src/environment_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec<Pat
let mut env_dirs = vec![];
for rc_file_dir in get_conda_rc_search_paths(env_vars) {
if !rc_file_dir.exists() {
trace!(".condarc not found ({:?})", rc_file_dir);
continue;
}

Expand Down Expand Up @@ -111,7 +112,7 @@ fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec<Pat
);
env_dirs.append(&mut conda_rc.env_dirs.clone());
} else {
trace!("No Conda environments in .condarc");
trace!("No Conda environments in .condarc {:?}", env_dirs);
}
env_dirs
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pet-conda/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
let conda_exe = resolve_symlink(&conda_exe).unwrap_or(conda_exe);
if let Some(cmd_line) = conda_exe.parent() {
if let Some(conda_dir) = cmd_line.file_name() {
if conda_dir.to_ascii_lowercase() == "bin"
|| conda_dir.to_ascii_lowercase() == "scripts"
if conda_dir.to_string_lossy().to_lowercase() == "bin"
|| conda_dir.to_string_lossy().to_lowercase() == "scripts"
{
if let Some(conda_dir) = cmd_line.parent() {
// Ensure the casing of the paths are correct.
Expand Down
23 changes: 22 additions & 1 deletion crates/pet-conda/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ use std::path::{Path, PathBuf};

/// conda-meta must exist as this contains a mandatory `history` file.
pub fn is_conda_install(path: &Path) -> bool {
(path.join("condabin").exists() || path.join("envs").exists())
if (path.join("condabin").exists() || path.join("envs").exists())
&& path.join("conda-meta").exists()
{
// For https://github.com/microsoft/vscode-python/issues/24247
// Possible the env has a condabin or envs folder but its not the install directory.
// & in fact its just a regular conda env.
// Easy way is to check if the grand parent folder is a conda install directory.
if let Some(parent) = path.parent() {
if let Some(parent) = parent.parent() {
// If the grand parent is a conda install directory,
// then this is definitely not a conda install dir.
if (parent.join("condabin").exists() || parent.join("envs").exists())
&& parent.join("conda-meta").exists()
{
return false;
}
}
}

return true;
}

false
}

/// conda-meta must exist as this contains a mandatory `history` file.
Expand Down
1 change: 1 addition & 0 deletions crates/pet-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum LocatorKind {
MacPythonOrg,
MacXCode,
PipEnv,
Pixi,
Poetry,
PyEnv,
Venv,
Expand Down
12 changes: 11 additions & 1 deletion crates/pet-core/src/os_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,18 @@ impl Environment for EnvironmentApi {
}
}

#[cfg(windows)]
fn get_user_home() -> Option<PathBuf> {
let home = env::var("USERPROFILE").or_else(|_| env::var("HOME"));
match home {
Ok(home) => Some(norm_case(PathBuf::from(home))),
Err(_) => None,
}
}

#[cfg(unix)]
fn get_user_home() -> Option<PathBuf> {
let home = env::var("HOME").or_else(|_| env::var("USERPROFILE"));
let home = env::var("HOME");
match home {
Ok(home) => Some(norm_case(PathBuf::from(home))),
Err(_) => None,
Expand Down
1 change: 1 addition & 0 deletions crates/pet-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{arch::Architecture, manager::EnvManager};
#[derive(Parser, ValueEnum, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum PythonEnvironmentKind {
Conda,
Pixi,
Homebrew,
Pyenv,
GlobalPaths, // Python found in global locations like PATH, /usr/bin etc.
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-homebrew/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn get_prefix(_resolved_file: &Path) -> Option<PathBuf> {
// let captures = reg_ex.captures(resolved_file)?;
// let version = captures.get(1).map(|m| m.as_str()).unwrap_or_default();
// let full_version = captures.get(2).map(|m| m.as_str()).unwrap_or_default();
// // SysPrefix- /usr/local/Cellar/python@3.8/3.8.19/Frameworks/Python.framework/Versions/3.8
// // SysPrefix- /usr/local/Cellar/python@3.8/3.8.20/Frameworks/Python.framework/Versions/3.8
// let sys_prefix = PathBuf::from(format!(
// "/usr/local/Cellar/python@{}/{}/Frameworks/Python.framework/Versions/{}",
// version, full_version, version
Expand Down
6 changes: 3 additions & 3 deletions crates/pet-homebrew/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ fn from(env: &PythonEnv) -> Option<PythonEnvironment> {
} else if resolved_file.starts_with("/usr/local/Cellar") {
// Symlink - /usr/local/bin/python3.8
// Symlink - /usr/local/opt/python@3.8/bin/python3.8
// Symlink - /usr/local/Cellar/python@3.8/3.8.19/bin/python3.8
// Real exe - /usr/local/Cellar/python@3.8/3.8.19/Frameworks/Python.framework/Versions/3.8/bin/python3.8
// SysPrefix- /usr/local/Cellar/python@3.8/3.8.19/Frameworks/Python.framework/Versions/3.8
// Symlink - /usr/local/Cellar/python@3.8/3.8.20/bin/python3.8
// Real exe - /usr/local/Cellar/python@3.8/3.8.20/Frameworks/Python.framework/Versions/3.8/bin/python3.8
// SysPrefix- /usr/local/Cellar/python@3.8/3.8.20/Frameworks/Python.framework/Versions/3.8
get_python_info(
&PathBuf::from("/usr/local/bin").join(exe_file_name),
&resolved_file,
Expand Down
Loading

0 comments on commit f8da764

Please sign in to comment.