mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 18:38:21 +00:00
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:
parent
7140cdec79
commit
7d90c29552
8 changed files with 23 additions and 16 deletions
|
@ -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? {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ pub(crate) async fn add(
|
|||
let python_request = if let Some(request) = python.as_deref() {
|
||||
// (1) Explicit request from user
|
||||
PythonRequest::parse(request)
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false)
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version)
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ pub(crate) async fn add(
|
|||
let python_request = if let Some(request) = python.as_deref() {
|
||||
// (1) Explicit request from user
|
||||
Some(PythonRequest::parse(request))
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false)
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version)
|
||||
{
|
||||
|
|
|
@ -177,7 +177,8 @@ impl WorkspacePython {
|
|||
let python_request = if let Some(request) = python_request {
|
||||
Some(request)
|
||||
// (2) Request from `.python-version`
|
||||
} else if let Some(request) = PythonVersionFile::discover(workspace.install_path(), false)
|
||||
} else if let Some(request) =
|
||||
PythonVersionFile::discover(workspace.install_path(), false, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version)
|
||||
{
|
||||
|
|
|
@ -109,7 +109,7 @@ pub(crate) async fn run(
|
|||
let python_request = if let Some(request) = python.as_deref() {
|
||||
Some(PythonRequest::parse(request))
|
||||
// (2) Request from `.python-version`
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false)
|
||||
} else if let Some(request) = PythonVersionFile::discover(&*CWD, false, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version)
|
||||
{
|
||||
|
@ -449,7 +449,7 @@ pub(crate) async fn run(
|
|||
Some(PythonRequest::parse(request))
|
||||
// (2) Request from `.python-version`
|
||||
} else {
|
||||
PythonVersionFile::discover(&*CWD, no_config)
|
||||
PythonVersionFile::discover(&*CWD, no_config, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version)
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ pub(crate) async fn find(
|
|||
|
||||
// (2) Request from `.python-version`
|
||||
if request.is_none() {
|
||||
request = PythonVersionFile::discover(&*CWD, no_config)
|
||||
request = PythonVersionFile::discover(&*CWD, no_config, false)
|
||||
.await?
|
||||
.and_then(PythonVersionFile::into_version);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn install(
|
|||
|
||||
let targets = targets.into_iter().collect::<BTreeSet<_>>();
|
||||
let requests: Vec<_> = if targets.is_empty() {
|
||||
PythonVersionFile::discover(&*CWD, no_config)
|
||||
PythonVersionFile::discover(&*CWD, no_config, true)
|
||||
.await?
|
||||
.map(uv_python::PythonVersionFile::into_versions)
|
||||
.unwrap_or_else(|| vec![PythonRequest::Any])
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn pin(
|
|||
}
|
||||
};
|
||||
|
||||
let version_file = PythonVersionFile::discover(&*CWD, false).await;
|
||||
let version_file = PythonVersionFile::discover(&*CWD, false, false).await;
|
||||
|
||||
let Some(request) = request else {
|
||||
// Display the current pinned Python version
|
||||
|
|
|
@ -146,7 +146,7 @@ async fn venv_impl(
|
|||
// (2) Request from `.python-version`
|
||||
if interpreter_request.is_none() {
|
||||
// TODO(zanieb): Support `--no-config` here
|
||||
interpreter_request = PythonVersionFile::discover(&*CWD, false)
|
||||
interpreter_request = PythonVersionFile::discover(&*CWD, false, false)
|
||||
.await
|
||||
.into_diagnostic()?
|
||||
.and_then(PythonVersionFile::into_version);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue