Skip to content

Commit ebeb53f

Browse files
authored
Prefer windows vars on windows OS and more logging (#188)
For #185
1 parent 1abe5ce commit ebeb53f

File tree

7 files changed

+51
-20
lines changed

7 files changed

+51
-20
lines changed

.github/workflows/pr-check.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Set Python to PATH
4646
uses: actions/setup-python@v5
4747
with:
48-
python-version: "3.x"
48+
python-version: "3.12"
4949

5050
- name: Homebrew Python
5151
if: startsWith( matrix.os, 'macos')
@@ -134,7 +134,7 @@ jobs:
134134
if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos')
135135
run: |
136136
pyenv install --list
137-
pyenv install 3.13.0 3.12.7 3.8.20
137+
pyenv install 3.13.0 3.12.8 3.8.20
138138
shell: bash
139139

140140
# pyenv-win install list has not updated for a while
@@ -248,7 +248,7 @@ jobs:
248248
if: startsWith( matrix.feature, 'ci-poetry')
249249
uses: actions/setup-python@v5
250250
with:
251-
python-version: "3.x"
251+
python-version: "3.12"
252252

253253
- name: Set Python 3.12 to PATH
254254
if: startsWith( matrix.feature, 'ci-poetry')
@@ -304,48 +304,48 @@ jobs:
304304
virtualenvs-path: ~/my-custom-path
305305
installer-parallel: true
306306

307-
- name: Petry exe
307+
- name: Poetry exe
308308
if: startsWith( matrix.feature, 'ci-poetry')
309309
run: which poetry
310310
shell: bash
311311

312-
- name: Petry config
312+
- name: Poetry config
313313
if: startsWith( matrix.feature, 'ci-poetry')
314314
run: poetry config --list
315315
shell: bash
316316

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

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

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

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

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

343-
- name: Petry list envs
343+
- name: Poetry list envs
344344
if: startsWith( matrix.feature, 'ci-poetry')
345345
run: poetry env list
346346
shell: bash
347347

348-
- name: Petry pyproject.toml
348+
- name: Poetry pyproject.toml
349349
if: startsWith( matrix.feature, 'ci-poetry')
350350
run: cat pyproject.toml
351351
shell: bash
@@ -414,7 +414,7 @@ jobs:
414414
if: startsWith( matrix.image, 'homebrew')
415415
run: |
416416
# homebrew/brew:4.4.6 broke running `brew install` as root.
417-
# As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`.
417+
# As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`.
418418
brew update || true
419419
420420
shell: bash

crates/pet-conda/src/conda_rc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ fn get_conda_conda_rc_from_path(conda_rc: &PathBuf) -> Option<Condarc> {
216216
if env_dirs.is_empty() && files.is_empty() {
217217
None
218218
} else {
219+
trace!("conda_rc: {:?} with env_dirs {:?}", conda_rc, env_dirs);
219220
Some(Condarc { env_dirs, files })
220221
}
221222
}

crates/pet-conda/src/environment_locations.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec<Pat
7575
let mut env_dirs = vec![];
7676
for rc_file_dir in get_conda_rc_search_paths(env_vars) {
7777
if !rc_file_dir.exists() {
78+
trace!(".condarc not found ({:?})", rc_file_dir);
7879
continue;
7980
}
8081

@@ -111,7 +112,7 @@ fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec<Pat
111112
);
112113
env_dirs.append(&mut conda_rc.env_dirs.clone());
113114
} else {
114-
trace!("No Conda environments in .condarc");
115+
trace!("No Conda environments in .condarc {:?}", env_dirs);
115116
}
116117
env_dirs
117118
}

crates/pet-conda/src/environments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
186186
let conda_exe = resolve_symlink(&conda_exe).unwrap_or(conda_exe);
187187
if let Some(cmd_line) = conda_exe.parent() {
188188
if let Some(conda_dir) = cmd_line.file_name() {
189-
if conda_dir.to_ascii_lowercase() == "bin"
190-
|| conda_dir.to_ascii_lowercase() == "scripts"
189+
if conda_dir.to_string_lossy().to_lowercase() == "bin"
190+
|| conda_dir.to_string_lossy().to_lowercase() == "scripts"
191191
{
192192
if let Some(conda_dir) = cmd_line.parent() {
193193
// Ensure the casing of the paths are correct.

crates/pet-core/src/os_environment.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,18 @@ impl Environment for EnvironmentApi {
133133
}
134134
}
135135

136+
#[cfg(windows)]
137+
fn get_user_home() -> Option<PathBuf> {
138+
let home = env::var("USERPROFILE").or_else(|_| env::var("HOME"));
139+
match home {
140+
Ok(home) => Some(norm_case(PathBuf::from(home))),
141+
Err(_) => None,
142+
}
143+
}
144+
145+
#[cfg(unix)]
136146
fn get_user_home() -> Option<PathBuf> {
137-
let home = env::var("HOME").or_else(|_| env::var("USERPROFILE"));
147+
let home = env::var("HOME");
138148
match home {
139149
Ok(home) => Some(norm_case(PathBuf::from(home))),
140150
Err(_) => None,

crates/pet-poetry/src/pyproject_toml.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88

99
use log::{error, trace};
1010

11+
#[derive(Debug)]
1112
pub struct PyProjectToml {
1213
pub name: String,
1314
}
@@ -18,11 +19,13 @@ impl PyProjectToml {
1819
PyProjectToml { name }
1920
}
2021
pub fn find(path: &Path) -> Option<Self> {
22+
trace!("Finding poetry file in {:?}", path);
2123
parse(&path.join("pyproject.toml"))
2224
}
2325
}
2426

2527
fn parse(file: &Path) -> Option<PyProjectToml> {
28+
trace!("Parsing poetry file: {:?}", file);
2629
let contents = fs::read_to_string(file).ok()?;
2730
parse_contents(&contents, file)
2831
}
@@ -38,7 +41,23 @@ fn parse_contents(contents: &str, file: &Path) -> Option<PyProjectToml> {
3841
}
3942
}
4043
}
41-
name.map(|name| PyProjectToml::new(name, file.into()))
44+
45+
match name {
46+
Some(name) => Some(PyProjectToml::new(name, file.into())),
47+
None => {
48+
trace!(
49+
"Poetry project name not found in {:?}, trying the new format",
50+
file
51+
);
52+
let mut name = None;
53+
if let Some(project) = value.get("project") {
54+
if let Some(name_value) = project.get("name") {
55+
name = name_value.as_str().map(|s| s.to_string());
56+
}
57+
}
58+
name.map(|name| PyProjectToml::new(name, file.into()))
59+
}
60+
}
4261
}
4362
Err(e) => {
4463
error!("Error parsing toml file: {:?}", e);

crates/pet/tests/ci_homebrew_container.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn verify_python_in_homebrew_contaner() {
7272
let python3_12 = PythonEnvironment {
7373
kind: Some(PythonEnvironmentKind::Homebrew),
7474
executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12")),
75-
version: Some("3.12.7".to_string()), // This can change on CI, so we don't check it
75+
version: Some("3.12.8".to_string()), // This can change on CI, so we don't check it
7676
symlinks: Some(vec![
7777
// For older versions of Python, we do not have a tonne of symlinks,
7878
// E.g. for 3.12.7 (which was the latest at some point, at a lot of symlinks)
@@ -88,7 +88,7 @@ fn verify_python_in_homebrew_contaner() {
8888
let python3_11 = PythonEnvironment {
8989
kind: Some(PythonEnvironmentKind::Homebrew),
9090
executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.11")),
91-
version: Some("3.11.10".to_string()), // This can change on CI, so we don't check it
91+
version: Some("3.11.11".to_string()), // This can change on CI, so we don't check it
9292
symlinks: Some(vec![
9393
// For older versions of Python, we do not have a tonne of symlinks,
9494
// E.g. for 3.12.7 (which was the latest at some point, at a lot of symlinks)

0 commit comments

Comments
 (0)