|
12 | 12 | //! The fix adds fallback path-based detection that checks: |
13 | 13 | //! 1. If the environment path matches Poetry's cache naming pattern |
14 | 14 | //! ({name}-{8-char-hash}-py{version}) in "pypoetry/virtualenvs" |
15 | | -//! 2. If the environment is an in-project .venv with a pyproject.toml |
16 | | -//! containing Poetry configuration |
| 15 | +//! 2. If the environment is an in-project .venv with Poetry configuration: |
| 16 | +//! - poetry.toml exists in the parent directory, OR |
| 17 | +//! - pyproject.toml contains [tool.poetry] or poetry-core build backend |
17 | 18 |
|
18 | 19 | use std::fs; |
19 | 20 | use std::path::PathBuf; |
@@ -50,8 +51,15 @@ mod tests { |
50 | 51 | return false; |
51 | 52 | } |
52 | 53 |
|
53 | | - // Check if the parent directory has a pyproject.toml with Poetry configuration |
| 54 | + // Check if the parent directory has Poetry configuration |
54 | 55 | if let Some(parent) = path.parent() { |
| 56 | + // Check for poetry.toml - a local Poetry configuration file |
| 57 | + let poetry_toml = parent.join("poetry.toml"); |
| 58 | + if poetry_toml.is_file() { |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + // Check if pyproject.toml contains Poetry configuration |
55 | 63 | let pyproject_toml = parent.join("pyproject.toml"); |
56 | 64 | if pyproject_toml.is_file() { |
57 | 65 | if let Ok(contents) = std::fs::read_to_string(&pyproject_toml) { |
@@ -217,18 +225,50 @@ build-backend = "setuptools.build_meta" |
217 | 225 | } |
218 | 226 |
|
219 | 227 | #[test] |
220 | | - fn test_in_project_env_no_pyproject_rejected() { |
| 228 | + fn test_in_project_env_no_poetry_config_rejected() { |
221 | 229 | let temp_dir = tempfile::tempdir().unwrap(); |
222 | 230 | let project_dir = temp_dir.path(); |
223 | 231 | let venv_dir = project_dir.join(".venv"); |
224 | 232 |
|
225 | | - // Create .venv directory without pyproject.toml |
| 233 | + // Create .venv directory without any Poetry configuration files |
226 | 234 | fs::create_dir(&venv_dir).unwrap(); |
227 | 235 |
|
228 | 236 | // Test that the .venv is NOT recognized as a Poetry environment |
229 | 237 | assert!(!test_in_project_poetry_env(&venv_dir)); |
230 | 238 | } |
231 | 239 |
|
| 240 | + #[test] |
| 241 | + fn test_in_project_poetry_env_with_poetry_toml() { |
| 242 | + let temp_dir = tempfile::tempdir().unwrap(); |
| 243 | + let project_dir = temp_dir.path(); |
| 244 | + let venv_dir = project_dir.join(".venv"); |
| 245 | + |
| 246 | + // Create .venv directory |
| 247 | + fs::create_dir(&venv_dir).unwrap(); |
| 248 | + |
| 249 | + // Create poetry.toml with in-project setting (no pyproject.toml with Poetry config) |
| 250 | + let poetry_toml_content = r#" |
| 251 | +[virtualenvs] |
| 252 | +in-project = true |
| 253 | +"#; |
| 254 | + fs::write(project_dir.join("poetry.toml"), poetry_toml_content).unwrap(); |
| 255 | + |
| 256 | + // Create minimal pyproject.toml without Poetry-specific config |
| 257 | + let pyproject_content = r#" |
| 258 | +[project] |
| 259 | +name = "my-project" |
| 260 | +version = "0.1.0" |
| 261 | +
|
| 262 | +[build-system] |
| 263 | +requires = ["setuptools>=45"] |
| 264 | +build-backend = "setuptools.build_meta" |
| 265 | +"#; |
| 266 | + fs::write(project_dir.join("pyproject.toml"), pyproject_content).unwrap(); |
| 267 | + |
| 268 | + // Test that the .venv is recognized as a Poetry environment due to poetry.toml |
| 269 | + assert!(test_in_project_poetry_env(&venv_dir)); |
| 270 | + } |
| 271 | + |
232 | 272 | #[test] |
233 | 273 | fn test_non_venv_directory_rejected() { |
234 | 274 | let temp_dir = tempfile::tempdir().unwrap(); |
|
0 commit comments