From 7ca90bc4ce3dd894b62638a6bfbeebf3002e4d4b Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 10:41:28 +1100 Subject: [PATCH 01/13] Prefer windows vars on windows OS and more logging --- crates/pet-conda/src/conda_rc.rs | 1 + crates/pet-conda/src/environment_locations.rs | 3 ++- crates/pet-core/src/os_environment.rs | 12 +++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/pet-conda/src/conda_rc.rs b/crates/pet-conda/src/conda_rc.rs index 98990f8c..eb8fdb03 100644 --- a/crates/pet-conda/src/conda_rc.rs +++ b/crates/pet-conda/src/conda_rc.rs @@ -216,6 +216,7 @@ fn get_conda_conda_rc_from_path(conda_rc: &PathBuf) -> Option { 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 }) } } diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index 4bd65c31..744da92c 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -75,6 +75,7 @@ fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec Vec Option { + 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 { - 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, From 6c5f25a402cff502faa9e473b4f09fce5752fc47 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 11:34:29 +1100 Subject: [PATCH 02/13] fix linter --- crates/pet-conda/src/environments.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pet-conda/src/environments.rs b/crates/pet-conda/src/environments.rs index f615544c..9a9fe4de 100644 --- a/crates/pet-conda/src/environments.rs +++ b/crates/pet-conda/src/environments.rs @@ -186,8 +186,8 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option { 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. From 7531a3f0ffe1155bf5790eaf3502311d614f64dc Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 11:40:32 +1100 Subject: [PATCH 03/13] version --- .github/workflows/pr-check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a133f1b2..b6711b8a 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -45,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') @@ -248,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') @@ -414,7 +414,7 @@ jobs: if: startsWith( matrix.image, 'homebrew') 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`. + # 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 From 1b0f058cdce0ede7dfed912626d09741240e96b6 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 11:46:17 +1100 Subject: [PATCH 04/13] fix --- crates/pet/tests/ci_homebrew_container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 1e16e3ec..f8d1fbe6 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -88,7 +88,7 @@ fn verify_python_in_homebrew_contaner() { let python3_11 = PythonEnvironment { kind: Some(PythonEnvironmentKind::Homebrew), executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.11")), - version: Some("3.11.10".to_string()), // This can change on CI, so we don't check it + version: Some("3.11.11".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ // For older versions of Python, we do not have a tonne of symlinks, // E.g. for 3.12.7 (which was the latest at some point, at a lot of symlinks) From 68304a65b52b1ee922fbc943b821e5d356b866c7 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 11:48:17 +1100 Subject: [PATCH 05/13] fix --- crates/pet/tests/ci_homebrew_container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index f8d1fbe6..9b0e67ea 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -72,7 +72,7 @@ fn verify_python_in_homebrew_contaner() { let python3_12 = PythonEnvironment { kind: Some(PythonEnvironmentKind::Homebrew), executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12")), - version: Some("3.12.7".to_string()), // This can change on CI, so we don't check it + version: Some("3.12.8".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ // For older versions of Python, we do not have a tonne of symlinks, // E.g. for 3.12.7 (which was the latest at some point, at a lot of symlinks) From 5c3ee112dd35119a998885a6a6c65ac367f4cb52 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:05:58 +1100 Subject: [PATCH 06/13] wip --- .github/workflows/pr-check.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index b6711b8a..ccfa6af4 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -320,6 +320,12 @@ jobs: run: poetry init --name=pet-test --python=^3.11 -q -n shell: bash + - name: Post + if: startsWith( matrix.feature, 'ci-poetry') + # We want to have 2 envs for this poetry project 3.12 and 3.11. + run: ls + shell: bash + - name: Petry virtual env setup 3.12 if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') run: poetry env use 3.12 From 97baef1496a0bedd6ede00838a1531514c168c34 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:15:34 +1100 Subject: [PATCH 07/13] wip --- .github/workflows/pr-check.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index ccfa6af4..c93ff28b 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -304,54 +304,60 @@ 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: Post + if: startsWith( matrix.feature, 'ci-poetry') + # We want to have 2 envs for this poetry project 3.12 and 3.11. + run: pwd + shell: bash + - name: Post if: startsWith( matrix.feature, 'ci-poetry') # We want to have 2 envs for this poetry project 3.12 and 3.11. run: ls 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 From d4f67bcb198803fbb936d2a745857b23e7759bdf Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:17:05 +1100 Subject: [PATCH 08/13] logging --- crates/pet-poetry/src/environment_locations.rs | 6 ++++++ crates/pet-poetry/src/pyproject_toml.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/crates/pet-poetry/src/environment_locations.rs b/crates/pet-poetry/src/environment_locations.rs index 5895be66..a4d69ced 100644 --- a/crates/pet-poetry/src/environment_locations.rs +++ b/crates/pet-poetry/src/environment_locations.rs @@ -34,6 +34,12 @@ pub fn list_environments( let workspace_dirs = workspace_dirs .iter() + .inspect(|workspace_dir| { + trace!( + "Inspecting workspace directory for pyproject.toml: {:?}", + workspace_dir + ) + }) .map(|workspace_dir| (workspace_dir, PyProjectToml::find(workspace_dir))) .filter_map(|(workspace_dir, pyproject_toml)| { pyproject_toml.map(|pyproject_toml| (workspace_dir, pyproject_toml)) diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index c110f3f8..35536f80 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -18,11 +18,13 @@ impl PyProjectToml { PyProjectToml { name } } pub fn find(path: &Path) -> Option { + trace!("Finding poetry file in {:?}", path); parse(&path.join("pyproject.toml")) } } fn parse(file: &Path) -> Option { + trace!("Parsing poetry file: {:?}", file); let contents = fs::read_to_string(file).ok()?; parse_contents(&contents, file) } From 83f1e37e0dce6fc9dea4b04601cb4e6e336e7662 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:25:42 +1100 Subject: [PATCH 09/13] wip --- crates/pet-poetry/src/pyproject_toml.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index 35536f80..32a7d6b3 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -25,11 +25,33 @@ impl PyProjectToml { fn parse(file: &Path) -> Option { trace!("Parsing poetry file: {:?}", file); + match fs::read_to_string(file) { + Ok(contents) => { + trace!( + "Parsed contents of poetry file: {:?} is {:?}", + file, + &contents + ); + } + Err(e) => { + error!("Error reading poetry file: {:?}", e); + } + }; let contents = fs::read_to_string(file).ok()?; + trace!( + "Parsed contents of poetry file: {:?} is {:?}", + file, + &contents + ); parse_contents(&contents, file) } fn parse_contents(contents: &str, file: &Path) -> Option { + trace!( + "Parsing contents of poetry file: {:?} with contents {:?}", + file, + contents + ); match toml::from_str::(contents) { Ok(value) => { let mut name = None; @@ -40,6 +62,7 @@ fn parse_contents(contents: &str, file: &Path) -> Option { } } } + trace!("Successfully parsed TOML value: {:?}", value); name.map(|name| PyProjectToml::new(name, file.into())) } Err(e) => { From 2c401c490970afec824e19e8866a915cd7a1cad7 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:32:36 +1100 Subject: [PATCH 10/13] wip --- crates/pet-poetry/src/environment_locations.rs | 5 +++++ crates/pet-poetry/src/pyproject_toml.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/crates/pet-poetry/src/environment_locations.rs b/crates/pet-poetry/src/environment_locations.rs index a4d69ced..55e89964 100644 --- a/crates/pet-poetry/src/environment_locations.rs +++ b/crates/pet-poetry/src/environment_locations.rs @@ -42,6 +42,11 @@ pub fn list_environments( }) .map(|workspace_dir| (workspace_dir, PyProjectToml::find(workspace_dir))) .filter_map(|(workspace_dir, pyproject_toml)| { + trace!( + "Found pyproject.toml in workspace directory: {:?} and pyproject.toml: {:?}", + workspace_dir, + pyproject_toml + ); pyproject_toml.map(|pyproject_toml| (workspace_dir, pyproject_toml)) }) .collect::>(); diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index 32a7d6b3..c8a986f7 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -8,6 +8,7 @@ use std::{ use log::{error, trace}; +#[derive(Debug)] pub struct PyProjectToml { pub name: String, } From 9b40d6b3f85cee928349fe921d64692769f1df90 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:50:13 +1100 Subject: [PATCH 11/13] New format for pyproject.toml --- crates/pet-poetry/src/pyproject_toml.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index c8a986f7..25f10c75 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -63,8 +63,23 @@ fn parse_contents(contents: &str, file: &Path) -> Option { } } } - trace!("Successfully parsed TOML value: {:?}", value); - name.map(|name| PyProjectToml::new(name, file.into())) + + match name { + Some(name) => Some(PyProjectToml::new(name, file.into())), + None => { + trace!( + "Poetry project name not found in {:?}, trying the new format", + file + ); + let mut name = None; + if let Some(project) = value.get("project") { + if let Some(name_value) = project.get("name") { + name = name_value.as_str().map(|s| s.to_string()); + } + } + name.map(|name| PyProjectToml::new(name, file.into())) + } + } } Err(e) => { error!("Error parsing toml file: {:?}", e); From e07aa1f826ea0ce9fce2eaf20fdb8a77a9ef98bf Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 12:58:27 +1100 Subject: [PATCH 12/13] Revert --- .github/workflows/pr-check.yml | 12 ---------- .../pet-poetry/src/environment_locations.rs | 11 ---------- crates/pet-poetry/src/pyproject_toml.rs | 22 ------------------- 3 files changed, 45 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index c93ff28b..9d3cd7cc 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -320,18 +320,6 @@ jobs: run: poetry init --name=pet-test --python=^3.11 -q -n shell: bash - - name: Post - if: startsWith( matrix.feature, 'ci-poetry') - # We want to have 2 envs for this poetry project 3.12 and 3.11. - run: pwd - shell: bash - - - name: Post - if: startsWith( matrix.feature, 'ci-poetry') - # We want to have 2 envs for this poetry project 3.12 and 3.11. - run: ls - shell: bash - - name: Poetry virtual env setup 3.12 if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') run: poetry env use 3.12 diff --git a/crates/pet-poetry/src/environment_locations.rs b/crates/pet-poetry/src/environment_locations.rs index 55e89964..5895be66 100644 --- a/crates/pet-poetry/src/environment_locations.rs +++ b/crates/pet-poetry/src/environment_locations.rs @@ -34,19 +34,8 @@ pub fn list_environments( let workspace_dirs = workspace_dirs .iter() - .inspect(|workspace_dir| { - trace!( - "Inspecting workspace directory for pyproject.toml: {:?}", - workspace_dir - ) - }) .map(|workspace_dir| (workspace_dir, PyProjectToml::find(workspace_dir))) .filter_map(|(workspace_dir, pyproject_toml)| { - trace!( - "Found pyproject.toml in workspace directory: {:?} and pyproject.toml: {:?}", - workspace_dir, - pyproject_toml - ); pyproject_toml.map(|pyproject_toml| (workspace_dir, pyproject_toml)) }) .collect::>(); diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index 25f10c75..de5dc69c 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -26,33 +26,11 @@ impl PyProjectToml { fn parse(file: &Path) -> Option { trace!("Parsing poetry file: {:?}", file); - match fs::read_to_string(file) { - Ok(contents) => { - trace!( - "Parsed contents of poetry file: {:?} is {:?}", - file, - &contents - ); - } - Err(e) => { - error!("Error reading poetry file: {:?}", e); - } - }; let contents = fs::read_to_string(file).ok()?; - trace!( - "Parsed contents of poetry file: {:?} is {:?}", - file, - &contents - ); parse_contents(&contents, file) } fn parse_contents(contents: &str, file: &Path) -> Option { - trace!( - "Parsing contents of poetry file: {:?} with contents {:?}", - file, - contents - ); match toml::from_str::(contents) { Ok(value) => { let mut name = None; From c2f552c2218bee4ee68696a6be2152207a10818b Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 10 Feb 2025 13:08:32 +1100 Subject: [PATCH 13/13] Updates --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9d3cd7cc..ea4631e6 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -134,7 +134,7 @@ jobs: if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos') run: | pyenv install --list - pyenv install 3.13.0 3.12.7 3.8.20 + pyenv install 3.13.0 3.12.8 3.8.20 shell: bash # pyenv-win install list has not updated for a while