mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Clean up some function signatures (#633)
This commit is contained in:
parent
920e10fc8f
commit
cbfd39093e
10 changed files with 30 additions and 35 deletions
|
@ -20,7 +20,7 @@ pub(crate) fn freeze(cache: &Cache, _printer: Printer) -> Result<ExitStatus> {
|
|||
);
|
||||
|
||||
// Build the installed index.
|
||||
let site_packages = SitePackages::try_from_executable(&python)?;
|
||||
let site_packages = SitePackages::from_executable(&python)?;
|
||||
for dist in site_packages.distributions() {
|
||||
#[allow(clippy::print_stdout)]
|
||||
{
|
||||
|
|
|
@ -77,7 +77,7 @@ pub(crate) async fn pip_compile(
|
|||
requirements,
|
||||
constraints,
|
||||
extras: used_extras,
|
||||
} = RequirementsSpecification::try_from_sources(requirements, constraints, &extras)?;
|
||||
} = RequirementsSpecification::from_sources(requirements, constraints, &extras)?;
|
||||
|
||||
// Check that all provided extras are used
|
||||
if let ExtrasSpecification::Some(extras) = extras {
|
||||
|
@ -102,7 +102,7 @@ pub(crate) async fn pip_compile(
|
|||
.map(Path::to_path_buf)
|
||||
.map(RequirementsSource::from)
|
||||
.as_ref()
|
||||
.map(|source| RequirementsSpecification::try_from_source(source, &extras))
|
||||
.map(|source| RequirementsSpecification::from_source(source, &extras))
|
||||
.transpose()?
|
||||
.map(|spec| spec.requirements)
|
||||
.unwrap_or_default();
|
||||
|
|
|
@ -137,7 +137,7 @@ fn specification(
|
|||
}
|
||||
|
||||
// Read all requirements from the provided sources.
|
||||
let spec = RequirementsSpecification::try_from_sources(requirements, constraints, extras)?;
|
||||
let spec = RequirementsSpecification::from_sources(requirements, constraints, extras)?;
|
||||
|
||||
// Check that all provided extras are used
|
||||
if let ExtrasSpecification::Some(extras) = extras {
|
||||
|
@ -161,7 +161,7 @@ fn specification(
|
|||
|
||||
/// Returns `true` if the requirements are already satisfied.
|
||||
fn satisfied(spec: &RequirementsSpecification, venv: &Virtualenv) -> Result<bool> {
|
||||
SitePackages::try_from_executable(venv)?.satisfies(&spec.requirements, &spec.constraints)
|
||||
SitePackages::from_executable(venv)?.satisfies(&spec.requirements, &spec.constraints)
|
||||
}
|
||||
|
||||
/// Resolve a set of requirements, similar to running `pip-compile`.
|
||||
|
@ -191,10 +191,10 @@ async fn resolve(
|
|||
// Respect preferences from the existing environments.
|
||||
let preferences: Vec<Requirement> = match reinstall {
|
||||
Reinstall::All => vec![],
|
||||
Reinstall::None => SitePackages::try_from_executable(venv)?
|
||||
Reinstall::None => SitePackages::from_executable(venv)?
|
||||
.requirements()
|
||||
.collect(),
|
||||
Reinstall::Packages(packages) => SitePackages::try_from_executable(venv)?
|
||||
Reinstall::Packages(packages) => SitePackages::from_executable(venv)?
|
||||
.requirements()
|
||||
.filter(|requirement| !packages.contains(&requirement.name))
|
||||
.collect(),
|
||||
|
@ -452,7 +452,7 @@ async fn install(
|
|||
|
||||
/// Validate the installed packages in the virtual environment.
|
||||
fn validate(resolution: &Resolution, venv: &Virtualenv, mut printer: Printer) -> Result<()> {
|
||||
let site_packages = SitePackages::try_from_executable(venv)?;
|
||||
let site_packages = SitePackages::from_executable(venv)?;
|
||||
let diagnostics = site_packages.diagnostics()?;
|
||||
for diagnostic in diagnostics {
|
||||
// Only surface diagnostics that are "relevant" to the current resolution.
|
||||
|
|
|
@ -22,7 +22,7 @@ use pypi_types::{IndexUrls, Yanked};
|
|||
use crate::commands::reporters::{DownloadReporter, FinderReporter, InstallReporter};
|
||||
use crate::commands::{elapsed, ChangeEvent, ChangeEventKind, ExitStatus};
|
||||
use crate::printer::Printer;
|
||||
use crate::requirements::{ExtrasSpecification, RequirementsSource, RequirementsSpecification};
|
||||
use crate::requirements::{RequirementsSource, RequirementsSpecification};
|
||||
|
||||
/// Install a set of locked requirements into the current Python environment.
|
||||
pub(crate) async fn pip_sync(
|
||||
|
@ -35,12 +35,7 @@ pub(crate) async fn pip_sync(
|
|||
mut printer: Printer,
|
||||
) -> Result<ExitStatus> {
|
||||
// Read all requirements from the provided sources.
|
||||
let RequirementsSpecification {
|
||||
project: _,
|
||||
requirements,
|
||||
constraints: _,
|
||||
extras: _,
|
||||
} = RequirementsSpecification::try_from_sources(sources, &[], &ExtrasSpecification::None)?;
|
||||
let requirements = RequirementsSpecification::requirements(sources)?;
|
||||
|
||||
if requirements.is_empty() {
|
||||
writeln!(printer, "No requirements found")?;
|
||||
|
|
|
@ -11,7 +11,7 @@ use puffin_interpreter::Virtualenv;
|
|||
|
||||
use crate::commands::{elapsed, ExitStatus};
|
||||
use crate::printer::Printer;
|
||||
use crate::requirements::{ExtrasSpecification, RequirementsSource, RequirementsSpecification};
|
||||
use crate::requirements::{RequirementsSource, RequirementsSpecification};
|
||||
|
||||
/// Uninstall packages from the current environment.
|
||||
pub(crate) async fn pip_uninstall(
|
||||
|
@ -22,12 +22,7 @@ pub(crate) async fn pip_uninstall(
|
|||
let start = std::time::Instant::now();
|
||||
|
||||
// Read all requirements from the provided sources.
|
||||
let RequirementsSpecification {
|
||||
project: _,
|
||||
requirements,
|
||||
constraints: _,
|
||||
extras: _,
|
||||
} = RequirementsSpecification::try_from_sources(sources, &[], &ExtrasSpecification::None)?;
|
||||
let requirements = RequirementsSpecification::requirements(sources)?;
|
||||
|
||||
// Detect the current Python interpreter.
|
||||
let platform = Platform::current()?;
|
||||
|
@ -38,7 +33,7 @@ pub(crate) async fn pip_uninstall(
|
|||
);
|
||||
|
||||
// Index the current `site-packages` directory.
|
||||
let site_packages = puffin_installer::SitePackages::try_from_executable(&venv)?;
|
||||
let site_packages = puffin_installer::SitePackages::from_executable(&venv)?;
|
||||
|
||||
// Sort and deduplicate the requirements.
|
||||
let packages = {
|
||||
|
|
|
@ -70,7 +70,7 @@ pub(crate) struct RequirementsSpecification {
|
|||
|
||||
impl RequirementsSpecification {
|
||||
/// Read the requirements and constraints from a source.
|
||||
pub(crate) fn try_from_source(
|
||||
pub(crate) fn from_source(
|
||||
source: &RequirementsSource,
|
||||
extras: &ExtrasSpecification,
|
||||
) -> Result<Self> {
|
||||
|
@ -138,7 +138,7 @@ impl RequirementsSpecification {
|
|||
}
|
||||
|
||||
/// Read the combined requirements and constraints from a set of sources.
|
||||
pub(crate) fn try_from_sources(
|
||||
pub(crate) fn from_sources(
|
||||
requirements: &[RequirementsSource],
|
||||
constraints: &[RequirementsSource],
|
||||
extras: &ExtrasSpecification,
|
||||
|
@ -149,7 +149,7 @@ impl RequirementsSpecification {
|
|||
// A `requirements.txt` can contain a `-c constraints.txt` directive within it, so reading
|
||||
// a requirements file can also add constraints.
|
||||
for source in requirements {
|
||||
let source = Self::try_from_source(source, extras)?;
|
||||
let source = Self::from_source(source, extras)?;
|
||||
spec.requirements.extend(source.requirements);
|
||||
spec.constraints.extend(source.constraints);
|
||||
spec.extras.extend(source.extras);
|
||||
|
@ -162,11 +162,16 @@ impl RequirementsSpecification {
|
|||
|
||||
// Read all constraints, treating both requirements _and_ constraints as constraints.
|
||||
for source in constraints {
|
||||
let source = Self::try_from_source(source, extras)?;
|
||||
let source = Self::from_source(source, extras)?;
|
||||
spec.constraints.extend(source.requirements);
|
||||
spec.constraints.extend(source.constraints);
|
||||
}
|
||||
|
||||
Ok(spec)
|
||||
}
|
||||
|
||||
/// Read the requirements from a set of sources.
|
||||
pub(crate) fn requirements(requirements: &[RequirementsSource]) -> Result<Vec<Requirement>> {
|
||||
Ok(Self::from_sources(requirements, &[], &ExtrasSpecification::None)?.requirements)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue