mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-17 22:07:47 +00:00
Serialize Python requests for tools as canonicalized strings (#14109)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / lint (push) Waiting to run
CI / cargo clippy | ubuntu (push) Blocked by required conditions
CI / cargo clippy | windows (push) Blocked by required conditions
CI / cargo dev generate-all (push) Blocked by required conditions
CI / cargo shear (push) Waiting to run
CI / cargo test | ubuntu (push) Blocked by required conditions
CI / cargo test | macos (push) Blocked by required conditions
CI / cargo test | windows (push) Blocked by required conditions
CI / check windows trampoline | aarch64 (push) Blocked by required conditions
CI / check windows trampoline | i686 (push) Blocked by required conditions
CI / check windows trampoline | x86_64 (push) Blocked by required conditions
CI / test windows trampoline | i686 (push) Blocked by required conditions
CI / test windows trampoline | x86_64 (push) Blocked by required conditions
CI / typos (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / build binary | linux libc (push) Blocked by required conditions
CI / build binary | linux musl (push) Blocked by required conditions
CI / build binary | macos aarch64 (push) Blocked by required conditions
CI / build binary | macos x86_64 (push) Blocked by required conditions
CI / build binary | windows x86_64 (push) Blocked by required conditions
CI / build binary | windows aarch64 (push) Blocked by required conditions
CI / ecosystem test | pydantic/pydantic-core (push) Blocked by required conditions
CI / ecosystem test | prefecthq/prefect (push) Blocked by required conditions
CI / ecosystem test | pallets/flask (push) Blocked by required conditions
CI / smoke test | linux (push) Blocked by required conditions
CI / check system | alpine (push) Blocked by required conditions
CI / smoke test | macos (push) Blocked by required conditions
CI / smoke test | windows x86_64 (push) Blocked by required conditions
CI / smoke test | windows aarch64 (push) Blocked by required conditions
CI / integration test | conda on ubuntu (push) Blocked by required conditions
CI / integration test | deadsnakes python3.9 on ubuntu (push) Blocked by required conditions
CI / integration test | free-threaded on windows (push) Blocked by required conditions
CI / integration test | pypy on ubuntu (push) Blocked by required conditions
CI / integration test | pypy on windows (push) Blocked by required conditions
CI / integration test | graalpy on ubuntu (push) Blocked by required conditions
CI / integration test | graalpy on windows (push) Blocked by required conditions
CI / check system | python on debian (push) Blocked by required conditions
CI / check system | python on fedora (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / build binary | freebsd (push) Blocked by required conditions
CI / integration test | pyodide on ubuntu (push) Blocked by required conditions
CI / integration test | github actions (push) Blocked by required conditions
CI / integration test | free-threaded python on github actions (push) Blocked by required conditions
CI / integration test | determine publish changes (push) Blocked by required conditions
CI / integration test | uv publish (push) Blocked by required conditions
CI / integration test | uv_build (push) Blocked by required conditions
CI / check cache | ubuntu (push) Blocked by required conditions
CI / check cache | macos aarch64 (push) Blocked by required conditions
CI / check system | python on ubuntu (push) Blocked by required conditions
CI / check system | python on rocky linux 8 (push) Blocked by required conditions
CI / check system | python on rocky linux 9 (push) Blocked by required conditions
CI / check system | graalpy on ubuntu (push) Blocked by required conditions
CI / check system | pypy on ubuntu (push) Blocked by required conditions
CI / check system | pyston (push) Blocked by required conditions
CI / check system | python on macos aarch64 (push) Blocked by required conditions
CI / check system | homebrew python on macos aarch64 (push) Blocked by required conditions
CI / check system | python on macos x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86 (push) Blocked by required conditions
CI / check system | python3.13 on windows x86-64 (push) Blocked by required conditions
CI / check system | x86-64 python3.13 on windows aarch64 (push) Blocked by required conditions
CI / check system | windows registry (push) Blocked by required conditions
CI / check system | python3.12 via chocolatey (push) Blocked by required conditions
CI / check system | python3.9 via pyenv (push) Blocked by required conditions
CI / check system | python3.13 (push) Blocked by required conditions
CI / check system | conda3.11 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.8 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.11 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.8 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.11 on windows x86-64 (push) Blocked by required conditions
CI / check system | conda3.8 on windows x86-64 (push) Blocked by required conditions
CI / check system | amazonlinux (push) Blocked by required conditions
CI / check system | embedded python3.10 on windows x86-64 (push) Blocked by required conditions
CI / benchmarks | walltime aarch64 linux (push) Blocked by required conditions
CI / benchmarks | instrumented (push) Blocked by required conditions
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / lint (push) Waiting to run
CI / cargo clippy | ubuntu (push) Blocked by required conditions
CI / cargo clippy | windows (push) Blocked by required conditions
CI / cargo dev generate-all (push) Blocked by required conditions
CI / cargo shear (push) Waiting to run
CI / cargo test | ubuntu (push) Blocked by required conditions
CI / cargo test | macos (push) Blocked by required conditions
CI / cargo test | windows (push) Blocked by required conditions
CI / check windows trampoline | aarch64 (push) Blocked by required conditions
CI / check windows trampoline | i686 (push) Blocked by required conditions
CI / check windows trampoline | x86_64 (push) Blocked by required conditions
CI / test windows trampoline | i686 (push) Blocked by required conditions
CI / test windows trampoline | x86_64 (push) Blocked by required conditions
CI / typos (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / build binary | linux libc (push) Blocked by required conditions
CI / build binary | linux musl (push) Blocked by required conditions
CI / build binary | macos aarch64 (push) Blocked by required conditions
CI / build binary | macos x86_64 (push) Blocked by required conditions
CI / build binary | windows x86_64 (push) Blocked by required conditions
CI / build binary | windows aarch64 (push) Blocked by required conditions
CI / ecosystem test | pydantic/pydantic-core (push) Blocked by required conditions
CI / ecosystem test | prefecthq/prefect (push) Blocked by required conditions
CI / ecosystem test | pallets/flask (push) Blocked by required conditions
CI / smoke test | linux (push) Blocked by required conditions
CI / check system | alpine (push) Blocked by required conditions
CI / smoke test | macos (push) Blocked by required conditions
CI / smoke test | windows x86_64 (push) Blocked by required conditions
CI / smoke test | windows aarch64 (push) Blocked by required conditions
CI / integration test | conda on ubuntu (push) Blocked by required conditions
CI / integration test | deadsnakes python3.9 on ubuntu (push) Blocked by required conditions
CI / integration test | free-threaded on windows (push) Blocked by required conditions
CI / integration test | pypy on ubuntu (push) Blocked by required conditions
CI / integration test | pypy on windows (push) Blocked by required conditions
CI / integration test | graalpy on ubuntu (push) Blocked by required conditions
CI / integration test | graalpy on windows (push) Blocked by required conditions
CI / check system | python on debian (push) Blocked by required conditions
CI / check system | python on fedora (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / build binary | freebsd (push) Blocked by required conditions
CI / integration test | pyodide on ubuntu (push) Blocked by required conditions
CI / integration test | github actions (push) Blocked by required conditions
CI / integration test | free-threaded python on github actions (push) Blocked by required conditions
CI / integration test | determine publish changes (push) Blocked by required conditions
CI / integration test | uv publish (push) Blocked by required conditions
CI / integration test | uv_build (push) Blocked by required conditions
CI / check cache | ubuntu (push) Blocked by required conditions
CI / check cache | macos aarch64 (push) Blocked by required conditions
CI / check system | python on ubuntu (push) Blocked by required conditions
CI / check system | python on rocky linux 8 (push) Blocked by required conditions
CI / check system | python on rocky linux 9 (push) Blocked by required conditions
CI / check system | graalpy on ubuntu (push) Blocked by required conditions
CI / check system | pypy on ubuntu (push) Blocked by required conditions
CI / check system | pyston (push) Blocked by required conditions
CI / check system | python on macos aarch64 (push) Blocked by required conditions
CI / check system | homebrew python on macos aarch64 (push) Blocked by required conditions
CI / check system | python on macos x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86 (push) Blocked by required conditions
CI / check system | python3.13 on windows x86-64 (push) Blocked by required conditions
CI / check system | x86-64 python3.13 on windows aarch64 (push) Blocked by required conditions
CI / check system | windows registry (push) Blocked by required conditions
CI / check system | python3.12 via chocolatey (push) Blocked by required conditions
CI / check system | python3.9 via pyenv (push) Blocked by required conditions
CI / check system | python3.13 (push) Blocked by required conditions
CI / check system | conda3.11 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.8 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.11 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.8 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.11 on windows x86-64 (push) Blocked by required conditions
CI / check system | conda3.8 on windows x86-64 (push) Blocked by required conditions
CI / check system | amazonlinux (push) Blocked by required conditions
CI / check system | embedded python3.10 on windows x86-64 (push) Blocked by required conditions
CI / benchmarks | walltime aarch64 linux (push) Blocked by required conditions
CI / benchmarks | instrumented (push) Blocked by required conditions
When working on support for reading global Python pins in tool operations, I noticed that we weren't using the canonicalized Python request in receipts — we were using the raw string provided by the user. Since we'll need to compare these values, we should be using the canonicalized string. The `Tool` and `ToolReceipt` types have been updated to hold a `PythonRequest` instead of a `String`, and `Serialize` was implemented for `PythonRequest` so canonicalization can happen at the edge instead of being the caller's responsibility.
This commit is contained in:
parent
6c096246d8
commit
47c522f9be
5 changed files with 46 additions and 13 deletions
|
@ -67,6 +67,26 @@ pub enum PythonRequest {
|
||||||
Key(PythonDownloadRequest),
|
Key(PythonDownloadRequest),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> serde::Deserialize<'a> for PythonRequest {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'a>,
|
||||||
|
{
|
||||||
|
let s = String::deserialize(deserializer)?;
|
||||||
|
Ok(PythonRequest::parse(&s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serde::Serialize for PythonRequest {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let s = self.to_canonical_string();
|
||||||
|
serializer.serialize_str(&s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||||
|
|
|
@ -7,6 +7,7 @@ use toml_edit::{Array, Item, Table, Value, value};
|
||||||
use uv_distribution_types::Requirement;
|
use uv_distribution_types::Requirement;
|
||||||
use uv_fs::{PortablePath, Simplified};
|
use uv_fs::{PortablePath, Simplified};
|
||||||
use uv_pypi_types::VerbatimParsedUrl;
|
use uv_pypi_types::VerbatimParsedUrl;
|
||||||
|
use uv_python::PythonRequest;
|
||||||
use uv_settings::ToolOptions;
|
use uv_settings::ToolOptions;
|
||||||
|
|
||||||
/// A tool entry.
|
/// A tool entry.
|
||||||
|
@ -22,7 +23,7 @@ pub struct Tool {
|
||||||
/// The build constraints requested by the user during installation.
|
/// The build constraints requested by the user during installation.
|
||||||
build_constraints: Vec<Requirement>,
|
build_constraints: Vec<Requirement>,
|
||||||
/// The Python requested by the user during installation.
|
/// The Python requested by the user during installation.
|
||||||
python: Option<String>,
|
python: Option<PythonRequest>,
|
||||||
/// A mapping of entry point names to their metadata.
|
/// A mapping of entry point names to their metadata.
|
||||||
entrypoints: Vec<ToolEntrypoint>,
|
entrypoints: Vec<ToolEntrypoint>,
|
||||||
/// The [`ToolOptions`] used to install this tool.
|
/// The [`ToolOptions`] used to install this tool.
|
||||||
|
@ -40,7 +41,7 @@ struct ToolWire {
|
||||||
overrides: Vec<Requirement>,
|
overrides: Vec<Requirement>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
build_constraint_dependencies: Vec<Requirement>,
|
build_constraint_dependencies: Vec<Requirement>,
|
||||||
python: Option<String>,
|
python: Option<PythonRequest>,
|
||||||
entrypoints: Vec<ToolEntrypoint>,
|
entrypoints: Vec<ToolEntrypoint>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
options: ToolOptions,
|
options: ToolOptions,
|
||||||
|
@ -164,7 +165,7 @@ impl Tool {
|
||||||
constraints: Vec<Requirement>,
|
constraints: Vec<Requirement>,
|
||||||
overrides: Vec<Requirement>,
|
overrides: Vec<Requirement>,
|
||||||
build_constraints: Vec<Requirement>,
|
build_constraints: Vec<Requirement>,
|
||||||
python: Option<String>,
|
python: Option<PythonRequest>,
|
||||||
entrypoints: impl Iterator<Item = ToolEntrypoint>,
|
entrypoints: impl Iterator<Item = ToolEntrypoint>,
|
||||||
options: ToolOptions,
|
options: ToolOptions,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -280,7 +281,13 @@ impl Tool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref python) = self.python {
|
if let Some(ref python) = self.python {
|
||||||
table.insert("python", value(python));
|
table.insert(
|
||||||
|
"python",
|
||||||
|
value(serde::Serialize::serialize(
|
||||||
|
&python,
|
||||||
|
toml_edit::ser::ValueSerializer::new(),
|
||||||
|
)?),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.insert("entrypoints", {
|
table.insert("entrypoints", {
|
||||||
|
@ -327,7 +334,7 @@ impl Tool {
|
||||||
&self.build_constraints
|
&self.build_constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn python(&self) -> &Option<String> {
|
pub fn python(&self) -> &Option<PythonRequest> {
|
||||||
&self.python
|
&self.python
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,14 +158,18 @@ pub(crate) async fn refine_interpreter(
|
||||||
Ok(Some(interpreter))
|
Ok(Some(interpreter))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Installs tool executables for a given package and handles any conflicts.
|
/// Finalizes a tool installation, after creation of an environment.
|
||||||
pub(crate) fn install_executables(
|
///
|
||||||
|
/// Installs tool executables for a given package, handling any conflicts.
|
||||||
|
///
|
||||||
|
/// Adds a receipt for the tool.
|
||||||
|
pub(crate) fn finalize_tool_install(
|
||||||
environment: &PythonEnvironment,
|
environment: &PythonEnvironment,
|
||||||
name: &PackageName,
|
name: &PackageName,
|
||||||
installed_tools: &InstalledTools,
|
installed_tools: &InstalledTools,
|
||||||
options: ToolOptions,
|
options: ToolOptions,
|
||||||
force: bool,
|
force: bool,
|
||||||
python: Option<String>,
|
python: Option<PythonRequest>,
|
||||||
requirements: Vec<Requirement>,
|
requirements: Vec<Requirement>,
|
||||||
constraints: Vec<Requirement>,
|
constraints: Vec<Requirement>,
|
||||||
overrides: Vec<Requirement>,
|
overrides: Vec<Requirement>,
|
||||||
|
|
|
@ -33,7 +33,9 @@ use crate::commands::project::{
|
||||||
EnvironmentSpecification, PlatformState, ProjectError, resolve_environment, resolve_names,
|
EnvironmentSpecification, PlatformState, ProjectError, resolve_environment, resolve_names,
|
||||||
sync_environment, update_environment,
|
sync_environment, update_environment,
|
||||||
};
|
};
|
||||||
use crate::commands::tool::common::{install_executables, refine_interpreter, remove_entrypoints};
|
use crate::commands::tool::common::{
|
||||||
|
finalize_tool_install, refine_interpreter, remove_entrypoints,
|
||||||
|
};
|
||||||
use crate::commands::tool::{Target, ToolRequest};
|
use crate::commands::tool::{Target, ToolRequest};
|
||||||
use crate::commands::{diagnostics, reporters::PythonDownloadReporter};
|
use crate::commands::{diagnostics, reporters::PythonDownloadReporter};
|
||||||
use crate::printer::Printer;
|
use crate::printer::Printer;
|
||||||
|
@ -592,13 +594,13 @@ pub(crate) async fn install(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
install_executables(
|
finalize_tool_install(
|
||||||
&environment,
|
&environment,
|
||||||
&from.name,
|
&from.name,
|
||||||
&installed_tools,
|
&installed_tools,
|
||||||
options,
|
options,
|
||||||
force || invalid_tool_receipt,
|
force || invalid_tool_receipt,
|
||||||
python,
|
python_request,
|
||||||
requirements,
|
requirements,
|
||||||
constraints,
|
constraints,
|
||||||
overrides,
|
overrides,
|
||||||
|
|
|
@ -29,7 +29,7 @@ use crate::commands::project::{
|
||||||
};
|
};
|
||||||
use crate::commands::reporters::PythonDownloadReporter;
|
use crate::commands::reporters::PythonDownloadReporter;
|
||||||
use crate::commands::tool::common::remove_entrypoints;
|
use crate::commands::tool::common::remove_entrypoints;
|
||||||
use crate::commands::{ExitStatus, conjunction, tool::common::install_executables};
|
use crate::commands::{ExitStatus, conjunction, tool::common::finalize_tool_install};
|
||||||
use crate::printer::Printer;
|
use crate::printer::Printer;
|
||||||
use crate::settings::{NetworkSettings, ResolverInstallerSettings};
|
use crate::settings::{NetworkSettings, ResolverInstallerSettings};
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ async fn upgrade_tool(
|
||||||
remove_entrypoints(&existing_tool_receipt);
|
remove_entrypoints(&existing_tool_receipt);
|
||||||
|
|
||||||
// If we modified the target tool, reinstall the entrypoints.
|
// If we modified the target tool, reinstall the entrypoints.
|
||||||
install_executables(
|
finalize_tool_install(
|
||||||
&environment,
|
&environment,
|
||||||
name,
|
name,
|
||||||
installed_tools,
|
installed_tools,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue