mirror of https://github.com/astral-sh/uv
Support remote `pylock.toml` files (#17119)
## Summary Closes https://github.com/astral-sh/uv/issues/17112.
This commit is contained in:
parent
4f6f56b070
commit
e603761862
|
|
@ -335,7 +335,7 @@ impl RequirementsSpecification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RequirementsSource::PylockToml(path) => {
|
RequirementsSource::PylockToml(path) => {
|
||||||
if !path.is_file() {
|
if !(path.starts_with("http://") || path.starts_with("https://") || path.exists()) {
|
||||||
return Err(anyhow::anyhow!("File not found: `{}`", path.user_display()));
|
return Err(anyhow::anyhow!("File not found: `{}`", path.user_display()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -500,10 +500,28 @@ pub(crate) async fn pip_install(
|
||||||
);
|
);
|
||||||
|
|
||||||
let (resolution, hasher) = if let Some(pylock) = pylock {
|
let (resolution, hasher) = if let Some(pylock) = pylock {
|
||||||
// Read the `pylock.toml` from disk, and deserialize it from TOML.
|
// Read the `pylock.toml` from disk or URL, and deserialize it from TOML.
|
||||||
|
let (install_path, content) =
|
||||||
|
if pylock.starts_with("http://") || pylock.starts_with("https://") {
|
||||||
|
// Fetch the `pylock.toml` over HTTP(S).
|
||||||
|
let url = uv_redacted::DisplaySafeUrl::parse(&pylock.to_string_lossy())?;
|
||||||
|
let client = client_builder.build();
|
||||||
|
let response = client
|
||||||
|
.for_host(&url)
|
||||||
|
.get(url::Url::from(url.clone()))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
response.error_for_status_ref()?;
|
||||||
|
let content = response.text().await?;
|
||||||
|
// Use the current working directory as the install path for remote lock files.
|
||||||
|
let install_path = std::env::current_dir()?;
|
||||||
|
(install_path, content)
|
||||||
|
} else {
|
||||||
let install_path = std::path::absolute(&pylock)?;
|
let install_path = std::path::absolute(&pylock)?;
|
||||||
let install_path = install_path.parent().unwrap();
|
let install_path = install_path.parent().unwrap().to_path_buf();
|
||||||
let content = fs_err::tokio::read_to_string(&pylock).await?;
|
let content = fs_err::tokio::read_to_string(&pylock).await?;
|
||||||
|
(install_path, content)
|
||||||
|
};
|
||||||
let lock = toml::from_str::<PylockToml>(&content).with_context(|| {
|
let lock = toml::from_str::<PylockToml>(&content).with_context(|| {
|
||||||
format!("Not a valid `pylock.toml` file: {}", pylock.user_display())
|
format!("Not a valid `pylock.toml` file: {}", pylock.user_display())
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -537,7 +555,7 @@ pub(crate) async fn pip_install(
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let resolution = lock.to_resolution(
|
let resolution = lock.to_resolution(
|
||||||
install_path,
|
&install_path,
|
||||||
marker_env.markers(),
|
marker_env.markers(),
|
||||||
&extras,
|
&extras,
|
||||||
&groups,
|
&groups,
|
||||||
|
|
|
||||||
|
|
@ -840,7 +840,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
|
||||||
.combine(Refresh::from(args.settings.upgrade.clone())),
|
.combine(Refresh::from(args.settings.upgrade.clone())),
|
||||||
);
|
);
|
||||||
|
|
||||||
commands::pip_install(
|
Box::pin(commands::pip_install(
|
||||||
&requirements,
|
&requirements,
|
||||||
&constraints,
|
&constraints,
|
||||||
&overrides,
|
&overrides,
|
||||||
|
|
@ -892,7 +892,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
|
||||||
args.dry_run,
|
args.dry_run,
|
||||||
printer,
|
printer,
|
||||||
globals.preview,
|
globals.preview,
|
||||||
)
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
Commands::Pip(PipNamespace {
|
Commands::Pip(PipNamespace {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue