Skip to content

Conversation

@lingyaochu
Copy link
Contributor

@lingyaochu lingyaochu commented Jan 18, 2026

Closes #47098

The root cause of this issue is related to how Poetry (and the upstream pet-poetry library) handles path hashing. While perhaps it's an upstream behavior, we can easily fix it on the Zed side.

The related code are

impl ToolchainLister for PythonToolchainProvider {
async fn list(
&self,
worktree_root: PathBuf,
subroot_relative_path: Arc<RelPath>,
project_env: Option<HashMap<String, String>>,
fs: &dyn Fs,
) -> ToolchainList {
let env = project_env.unwrap_or_default();
let environment = EnvironmentApi::from_env(&env);
let locators = pet::locators::create_locators(
Arc::new(pet_conda::Conda::from(&environment)),
Arc::new(pet_poetry::Poetry::from(&environment)),
&environment,
);
let mut config = Configuration::default();
// `.ancestors()` will yield at least one path, so in case of empty `subroot_relative_path`, we'll just use
// worktree root as the workspace directory.
config.workspace_directories = Some(
subroot_relative_path
.ancestors()
.map(|ancestor| worktree_root.join(ancestor.as_std_path()))
.collect(),
);
for locator in locators.iter() {
locator.configure(&config);
}
let reporter = pet_reporter::collect::create_reporter();
pet::find::find_and_report_envs(&reporter, config, &locators, &environment, None);

In my debugging, I found that worktree_root takes the form /home/user/project, but config.workspace_directories often ends up as /home/user/project/(with a trailing slash). Normally this wouldn't be an issue, but Poetry generates environment names based on the hash of the absolute path. Since the hashes for /home/user/project and /home/user/project/ are different, pet-poetry fails to find the environment.

The fix is straightforward: we just need to ensure the trailing / is removed so the hashes match.

Release Notes:

  • Fixed poetry environment not discovered on linux
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 18, 2026
@lingyaochu
Copy link
Contributor Author

It appears that upstream has addressed the trailing path separator issue in microsoft/python-environment-tools#279, Additionally, microsoft/python-environment-tools#283 should potentially resolve the Poetry-related issue where in-project virtual environments are misidentified as Venv (microsoft/python-environment-tools#282)

I’m converting this PR to a draft for now. If these upstream PRs indeed fix the issues, we can simply update the pet version later instead of maintaining this manual fix.

@lingyaochu lingyaochu marked this pull request as draft January 20, 2026 07:07
@lingyaochu lingyaochu marked this pull request as ready for review January 21, 2026 11:25
@lingyaochu
Copy link
Contributor Author

lingyaochu commented Jan 21, 2026

Upstream only fixed the in-project Poetry detection, so we still need the manual fix for trailing slashes here. I've updated the pet version to incorporate the upstream fix and kept my logic for the path handling.

Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Veykril Veykril enabled auto-merge (squash) January 21, 2026 12:53
@Veykril Veykril merged commit 5751aeb into zed-industries:main Jan 21, 2026
27 checks passed
@lingyaochu lingyaochu deleted the pet-version branch January 21, 2026 13:07
zcg pushed a commit to zcg/zed that referenced this pull request Jan 29, 2026
…s#47100)

Closes zed-industries#47098 

The root cause of this issue is related to how `Poetry` (and the
upstream `pet-poetry` library) handles path hashing. While perhaps it's
an upstream behavior, we can easily fix it on the Zed side.

The related code are

https://github.com/zed-industries/zed/blob/7ce845210d3af82a57a7518e0abe8c167d60cc6a/crates/languages/src/python.rs#L1181-L1211

In my debugging, I found that `worktree_root` takes the form
`/home/user/project`, but `config.workspace_directories` often ends up
as `/home/user/project/`(with a trailing slash). Normally this wouldn't
be an issue, but `Poetry` generates environment names based on the hash
of the absolute path. Since the hashes for `/home/user/project` and
`/home/user/project/` are different, `pet-poetry` fails to find the
environment.

The fix is straightforward: we just need to ensure the trailing `/` is
removed so the hashes match.

Release Notes:

- Fixed poetry environment not discovered on linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

2 participants