Respect --isolated in uv python install (#4938)

We ignore Python version files when `--isolated` is used, logging that
we skipped them if they exist.
This commit is contained in:
Zanie Blue 2024-07-10 11:36:25 -04:00 committed by GitHub
parent acfb57b072
commit a4044be95b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 18 deletions

View file

@ -13,9 +13,11 @@ pub use crate::pointer_size::PointerSize;
pub use crate::prefix::Prefix;
pub use crate::python_version::PythonVersion;
pub use crate::target::Target;
pub use crate::version_files::{request_from_version_file, requests_from_version_file};
pub use crate::version_files::{
request_from_version_file, requests_from_version_file, version_file_exists,
versions_file_exists, PYTHON_VERSIONS_FILENAME, PYTHON_VERSION_FILENAME,
};
pub use crate::virtualenv::{Error as VirtualEnvError, PyVenvConfiguration, VirtualEnvironment};
mod discovery;
pub mod downloads;
mod environment;

View file

@ -4,6 +4,12 @@ use tracing::debug;
use crate::PythonRequest;
/// The file name for Python version pins.
pub static PYTHON_VERSION_FILENAME: &str = ".python-version";
/// The file name for multiple Python version declarations.
pub static PYTHON_VERSIONS_FILENAME: &str = ".python-versions";
/// Read [`PythonRequest`]s from a version file, if present.
///
/// Prefers `.python-versions` then `.python-version`.
@ -41,12 +47,16 @@ pub async fn request_from_version_file() -> Result<Option<PythonRequest>, io::Er
}
}
pub fn versions_file_exists() -> Result<bool, io::Error> {
PathBuf::from(PYTHON_VERSIONS_FILENAME).try_exists()
}
async fn read_versions_file() -> Result<Option<Vec<String>>, io::Error> {
if !PathBuf::from(".python-versions").try_exists()? {
if !versions_file_exists()? {
return Ok(None);
}
debug!("Reading requests from `.python-versions`");
let lines: Vec<String> = fs::tokio::read_to_string(".python-versions")
debug!("Reading requests from `{PYTHON_VERSIONS_FILENAME}`");
let lines: Vec<String> = fs::tokio::read_to_string(PYTHON_VERSIONS_FILENAME)
.await?
.lines()
.map(ToString::to_string)
@ -54,12 +64,16 @@ async fn read_versions_file() -> Result<Option<Vec<String>>, io::Error> {
Ok(Some(lines))
}
pub fn version_file_exists() -> Result<bool, io::Error> {
PathBuf::from(PYTHON_VERSION_FILENAME).try_exists()
}
async fn read_version_file() -> Result<Option<String>, io::Error> {
if !PathBuf::from(".python-version").try_exists()? {
if !version_file_exists()? {
return Ok(None);
}
debug!("Reading requests from `.python-version`");
Ok(fs::tokio::read_to_string(".python-version")
debug!("Reading requests from `{PYTHON_VERSION_FILENAME}`");
Ok(fs::tokio::read_to_string(PYTHON_VERSION_FILENAME)
.await?
.lines()
.next()