Fix priority for .python-versions files in uv python install (#6382)

In https://github.com/astral-sh/uv/pull/6359, I accidentally made `uv
python install` prefer `.python-version` files over `.python-versions`
files -.-, kind of niche but it's a regression.
This commit is contained in:
Zanie Blue 2024-08-21 17:17:14 -05:00 committed by GitHub
parent 7140cdec79
commit 7d90c29552
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 23 additions and 16 deletions

View file

@ -25,7 +25,9 @@ impl PythonVersionFile {
/// Find a Python version file in the given directory.
pub async fn discover(
working_directory: impl AsRef<Path>,
// TODO(zanieb): Create a `DiscoverySettings` struct for these options
no_config: bool,
prefer_versions: bool,
) -> Result<Option<Self>, std::io::Error> {
let versions_path = working_directory.as_ref().join(PYTHON_VERSIONS_FILENAME);
let version_path = working_directory.as_ref().join(PYTHON_VERSION_FILENAME);
@ -39,12 +41,16 @@ impl PythonVersionFile {
return Ok(None);
}
if let Some(result) = Self::try_from_path(version_path).await? {
return Ok(Some(result));
};
if let Some(result) = Self::try_from_path(versions_path).await? {
return Ok(Some(result));
let paths = if prefer_versions {
[versions_path, version_path]
} else {
[version_path, versions_path]
};
for path in paths {
if let Some(result) = Self::try_from_path(path).await? {
return Ok(Some(result));
};
}
Ok(None)
}