mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-15 04:49:41 +00:00
Use cached current directory everywhere (#5574)
This commit is contained in:
parent
37388f0987
commit
51a03738a2
14 changed files with 43 additions and 45 deletions
|
@ -1,7 +1,6 @@
|
|||
use fs2::FileExt;
|
||||
use std::fmt::Display;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use fs2::FileExt;
|
||||
use tempfile::NamedTempFile;
|
||||
use tracing::{debug, error, trace, warn};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ use pypi_types::VerbatimParsedUrl;
|
|||
use requirements_txt::{RequirementsTxt, RequirementsTxtRequirement};
|
||||
use uv_client::BaseClientBuilder;
|
||||
use uv_configuration::{NoBinary, NoBuild};
|
||||
use uv_fs::Simplified;
|
||||
use uv_fs::{Simplified, CWD};
|
||||
use uv_normalize::{ExtraName, PackageName};
|
||||
use uv_workspace::pyproject::PyProjectToml;
|
||||
|
||||
|
@ -86,8 +86,7 @@ impl RequirementsSpecification {
|
|||
) -> Result<Self> {
|
||||
Ok(match source {
|
||||
RequirementsSource::Package(name) => {
|
||||
let requirement =
|
||||
RequirementsTxtRequirement::parse(name, std::env::current_dir()?, false)
|
||||
let requirement = RequirementsTxtRequirement::parse(name, &*CWD, false)
|
||||
.with_context(|| format!("Failed to parse: `{name}`"))?;
|
||||
Self {
|
||||
requirements: vec![UnresolvedRequirementSpecification::from(requirement)],
|
||||
|
@ -95,8 +94,7 @@ impl RequirementsSpecification {
|
|||
}
|
||||
}
|
||||
RequirementsSource::Editable(name) => {
|
||||
let requirement =
|
||||
RequirementsTxtRequirement::parse(name, std::env::current_dir()?, true)
|
||||
let requirement = RequirementsTxtRequirement::parse(name, &*CWD, true)
|
||||
.with_context(|| format!("Failed to parse: `{name}`"))?;
|
||||
Self {
|
||||
requirements: vec![UnresolvedRequirementSpecification::from(
|
||||
|
@ -114,8 +112,7 @@ impl RequirementsSpecification {
|
|||
return Err(anyhow::anyhow!("File not found: `{}`", path.user_display()));
|
||||
}
|
||||
|
||||
let requirements_txt =
|
||||
RequirementsTxt::parse(path, std::env::current_dir()?, client_builder).await?;
|
||||
let requirements_txt = RequirementsTxt::parse(path, &*CWD, client_builder).await?;
|
||||
Self {
|
||||
requirements: requirements_txt
|
||||
.requirements
|
||||
|
@ -313,7 +310,7 @@ impl RequirementsSpecification {
|
|||
|
||||
/// Parse an individual package requirement.
|
||||
pub fn parse_package(name: &str) -> Result<UnresolvedRequirementSpecification> {
|
||||
let requirement = RequirementsTxtRequirement::parse(name, std::env::current_dir()?, false)
|
||||
let requirement = RequirementsTxtRequirement::parse(name, &*CWD, false)
|
||||
.with_context(|| format!("Failed to parse: `{name}`"))?;
|
||||
Ok(UnresolvedRequirementSpecification::from(requirement))
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use anyhow::Result;
|
|||
use requirements_txt::RequirementsTxt;
|
||||
use uv_client::{BaseClientBuilder, Connectivity};
|
||||
use uv_configuration::Upgrade;
|
||||
use uv_fs::CWD;
|
||||
use uv_git::ResolvedRepositoryReference;
|
||||
use uv_resolver::{Lock, Preference, PreferenceError};
|
||||
|
||||
|
@ -34,7 +35,7 @@ pub async fn read_requirements_txt(
|
|||
// Parse the requirements from the lockfile.
|
||||
let requirements_txt = RequirementsTxt::parse(
|
||||
output_file,
|
||||
std::env::current_dir()?,
|
||||
&*CWD,
|
||||
&BaseClientBuilder::new().connectivity(Connectivity::Offline),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Create a virtual environment.
|
||||
|
||||
use std::env;
|
||||
use std::env::consts::EXE_SUFFIX;
|
||||
use std::io;
|
||||
use std::io::{BufWriter, Write};
|
||||
|
@ -12,7 +11,7 @@ use itertools::Itertools;
|
|||
use tracing::info;
|
||||
|
||||
use pypi_types::Scheme;
|
||||
use uv_fs::{cachedir, Simplified};
|
||||
use uv_fs::{cachedir, Simplified, CWD};
|
||||
use uv_python::{Interpreter, VirtualEnvironment};
|
||||
use uv_version::version;
|
||||
|
||||
|
@ -131,7 +130,7 @@ pub(crate) fn create(
|
|||
};
|
||||
let scripts = location.join(&interpreter.virtualenv().scripts);
|
||||
let prompt = match prompt {
|
||||
Prompt::CurrentDirectoryName => env::current_dir()?
|
||||
Prompt::CurrentDirectoryName => CWD
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().to_string()),
|
||||
Prompt::Static(value) => Some(value),
|
||||
|
|
|
@ -7,6 +7,7 @@ use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClient
|
|||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, SetupPyStrategy};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_distribution::DistributionDatabase;
|
||||
use uv_fs::CWD;
|
||||
use uv_normalize::PackageName;
|
||||
use uv_python::{PythonFetch, PythonPreference, PythonRequest};
|
||||
use uv_requirements::{NamedRequirementsResolver, RequirementsSource, RequirementsSpecification};
|
||||
|
@ -55,12 +56,12 @@ pub(crate) async fn add(
|
|||
|
||||
// Find the project in the workspace.
|
||||
let project = if let Some(package) = package {
|
||||
Workspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default())
|
||||
Workspace::discover(&CWD, &DiscoveryOptions::default())
|
||||
.await?
|
||||
.with_current_project(package.clone())
|
||||
.with_context(|| format!("Package `{package}` not found in workspace"))?
|
||||
} else {
|
||||
ProjectWorkspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default()).await?
|
||||
ProjectWorkspace::discover(&CWD, &DiscoveryOptions::default()).await?
|
||||
};
|
||||
|
||||
// Discover or create the virtual environment.
|
||||
|
|
|
@ -3,12 +3,13 @@ use std::path::Path;
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use owo_colors::OwoColorize;
|
||||
|
||||
use pep440_rs::Version;
|
||||
use pep508_rs::PackageName;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::{BaseClientBuilder, Connectivity};
|
||||
use uv_configuration::PreviewMode;
|
||||
use uv_fs::{absolutize_path, Simplified};
|
||||
use uv_fs::{absolutize_path, Simplified, CWD};
|
||||
use uv_python::{
|
||||
EnvironmentPreference, PythonFetch, PythonInstallation, PythonPreference, PythonRequest,
|
||||
VersionRequest,
|
||||
|
@ -46,7 +47,7 @@ pub(crate) async fn init(
|
|||
|
||||
// Default to the current directory if a path was not provided.
|
||||
let path = match explicit_path {
|
||||
None => std::env::current_dir()?.canonicalize()?,
|
||||
None => CWD.to_path_buf(),
|
||||
Some(ref path) => absolutize_path(Path::new(path))?.to_path_buf(),
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
|||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_distribution::DEV_DEPENDENCIES;
|
||||
use uv_fs::{Simplified, CWD};
|
||||
use uv_git::ResolvedRepositoryReference;
|
||||
use uv_normalize::PackageName;
|
||||
use uv_python::{Interpreter, PythonFetch, PythonPreference, PythonRequest};
|
||||
|
@ -63,9 +64,9 @@ pub(crate) async fn lock(
|
|||
}
|
||||
|
||||
let directory = if let Some(directory) = directory {
|
||||
directory
|
||||
directory.simple_canonicalize()?
|
||||
} else {
|
||||
std::env::current_dir()?
|
||||
CWD.to_path_buf()
|
||||
};
|
||||
|
||||
// Find the project requirements.
|
||||
|
|
|
@ -4,6 +4,7 @@ use pep508_rs::PackageName;
|
|||
use uv_cache::Cache;
|
||||
use uv_client::Connectivity;
|
||||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
|
||||
use uv_fs::CWD;
|
||||
use uv_python::{PythonFetch, PythonPreference, PythonRequest};
|
||||
use uv_warnings::{warn_user, warn_user_once};
|
||||
use uv_workspace::pyproject::DependencyType;
|
||||
|
@ -39,12 +40,12 @@ pub(crate) async fn remove(
|
|||
|
||||
// Find the project in the workspace.
|
||||
let project = if let Some(package) = package {
|
||||
Workspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default())
|
||||
Workspace::discover(&CWD, &DiscoveryOptions::default())
|
||||
.await?
|
||||
.with_current_project(package.clone())
|
||||
.with_context(|| format!("Package `{package}` not found in workspace"))?
|
||||
} else {
|
||||
ProjectWorkspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default()).await?
|
||||
ProjectWorkspace::discover(&CWD, &DiscoveryOptions::default()).await?
|
||||
};
|
||||
|
||||
let mut pyproject = PyProjectTomlMut::from_toml(project.current_project().pyproject_toml())?;
|
||||
|
|
|
@ -14,7 +14,7 @@ use uv_cache::Cache;
|
|||
use uv_cli::ExternalCommand;
|
||||
use uv_client::{BaseClientBuilder, Connectivity};
|
||||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
|
||||
use uv_fs::{PythonExt, Simplified};
|
||||
use uv_fs::{PythonExt, Simplified, CWD};
|
||||
use uv_installer::{SatisfiesResult, SitePackages};
|
||||
use uv_normalize::PackageName;
|
||||
use uv_python::{
|
||||
|
@ -93,7 +93,7 @@ pub(crate) async fn run(
|
|||
let directory = if let Some(directory) = directory {
|
||||
directory.simple_canonicalize()?
|
||||
} else {
|
||||
std::env::current_dir()?
|
||||
CWD.to_path_buf()
|
||||
};
|
||||
|
||||
// Determine whether the command to execute is a PEP 723 script.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use uv_auth::store_credentials_from_url;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||
|
@ -8,6 +10,7 @@ use uv_configuration::{
|
|||
};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_distribution::DEV_DEPENDENCIES;
|
||||
use uv_fs::{Simplified, CWD};
|
||||
use uv_installer::SitePackages;
|
||||
use uv_python::{PythonEnvironment, PythonFetch, PythonPreference, PythonRequest};
|
||||
use uv_resolver::{FlatIndex, Lock};
|
||||
|
@ -47,9 +50,9 @@ pub(crate) async fn sync(
|
|||
}
|
||||
|
||||
let directory = if let Some(directory) = directory {
|
||||
directory
|
||||
directory.simple_canonicalize()?
|
||||
} else {
|
||||
std::env::current_dir()?
|
||||
CWD.to_path_buf()
|
||||
};
|
||||
|
||||
// Identify the project
|
||||
|
|
|
@ -8,6 +8,7 @@ use pep508_rs::PackageName;
|
|||
use uv_cache::Cache;
|
||||
use uv_client::Connectivity;
|
||||
use uv_configuration::{Concurrency, PreviewMode};
|
||||
use uv_fs::CWD;
|
||||
use uv_python::{PythonFetch, PythonPreference, PythonRequest};
|
||||
use uv_warnings::warn_user_once;
|
||||
use uv_workspace::{DiscoveryOptions, Workspace};
|
||||
|
@ -47,8 +48,7 @@ pub(crate) async fn tree(
|
|||
}
|
||||
|
||||
// Find the project requirements.
|
||||
let workspace =
|
||||
Workspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default()).await?;
|
||||
let workspace = Workspace::discover(&CWD, &DiscoveryOptions::default()).await?;
|
||||
|
||||
// Find an interpreter for the project
|
||||
let interpreter = FoundInterpreter::discover(
|
||||
|
|
|
@ -11,6 +11,7 @@ use tracing::debug;
|
|||
use uv_cache::Cache;
|
||||
use uv_client::Connectivity;
|
||||
use uv_configuration::PreviewMode;
|
||||
use uv_fs::CWD;
|
||||
use uv_python::downloads::{DownloadResult, ManagedPythonDownload, PythonDownloadRequest};
|
||||
use uv_python::managed::{ManagedPythonInstallation, ManagedPythonInstallations};
|
||||
use uv_python::{
|
||||
|
@ -55,7 +56,7 @@ pub(crate) async fn install(
|
|||
}
|
||||
None
|
||||
} else {
|
||||
requests_from_version_file(&std::env::current_dir()?).await?
|
||||
requests_from_version_file(&CWD).await?
|
||||
};
|
||||
version_file_requests.unwrap_or_else(|| vec![PythonRequest::Any])
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,7 @@ use tracing::debug;
|
|||
|
||||
use uv_cache::Cache;
|
||||
use uv_configuration::PreviewMode;
|
||||
use uv_fs::Simplified;
|
||||
use uv_fs::{Simplified, CWD};
|
||||
use uv_python::{
|
||||
request_from_version_file, requests_from_version_file, write_version_file,
|
||||
EnvironmentPreference, PythonInstallation, PythonPreference, PythonRequest,
|
||||
|
@ -36,9 +36,7 @@ pub(crate) async fn pin(
|
|||
let virtual_project = if isolated {
|
||||
None
|
||||
} else {
|
||||
match VirtualProject::discover(&std::env::current_dir()?, &DiscoveryOptions::default())
|
||||
.await
|
||||
{
|
||||
match VirtualProject::discover(&CWD, &DiscoveryOptions::default()).await {
|
||||
Ok(virtual_project) => Some(virtual_project),
|
||||
Err(err) => {
|
||||
debug!("Failed to discover virtual project: {err}");
|
||||
|
@ -49,7 +47,7 @@ pub(crate) async fn pin(
|
|||
|
||||
let Some(request) = request else {
|
||||
// Display the current pinned Python version
|
||||
if let Some(pins) = requests_from_version_file(&std::env::current_dir()?).await? {
|
||||
if let Some(pins) = requests_from_version_file(&CWD).await? {
|
||||
for pin in pins {
|
||||
writeln!(printer.stdout(), "{}", pin.to_canonical_string())?;
|
||||
if let Some(virtual_project) = &virtual_project {
|
||||
|
@ -126,10 +124,7 @@ pub(crate) async fn pin(
|
|||
request.to_canonical_string()
|
||||
};
|
||||
|
||||
let existing = request_from_version_file(&std::env::current_dir()?)
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
let existing = request_from_version_file(&CWD).await.ok().flatten();
|
||||
write_version_file(&output).await?;
|
||||
|
||||
if let Some(existing) = existing
|
||||
|
|
|
@ -21,6 +21,7 @@ use uv_cli::{PythonCommand, PythonNamespace, ToolCommand, ToolNamespace};
|
|||
#[cfg(feature = "self-update")]
|
||||
use uv_cli::{SelfCommand, SelfNamespace};
|
||||
use uv_configuration::Concurrency;
|
||||
use uv_fs::CWD;
|
||||
use uv_requirements::RequirementsSource;
|
||||
use uv_settings::{Combine, FilesystemOptions};
|
||||
use uv_workspace::{DiscoveryOptions, Workspace};
|
||||
|
@ -73,14 +74,12 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
|
|||
Some(FilesystemOptions::from_file(config_file)?)
|
||||
} else if cli.global_args.isolated || cli.no_config {
|
||||
None
|
||||
} else if let Ok(project) =
|
||||
Workspace::discover(&std::env::current_dir()?, &DiscoveryOptions::default()).await
|
||||
{
|
||||
} else if let Ok(project) = Workspace::discover(&CWD, &DiscoveryOptions::default()).await {
|
||||
let project = FilesystemOptions::from_directory(project.install_path())?;
|
||||
let user = FilesystemOptions::user()?;
|
||||
project.combine(user)
|
||||
} else {
|
||||
let project = FilesystemOptions::find(std::env::current_dir()?)?;
|
||||
let project = FilesystemOptions::find(&*CWD)?;
|
||||
let user = FilesystemOptions::user()?;
|
||||
project.combine(user)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue