Skip to content

Commit

Permalink
Add --no-binary and --no-binary-package <name>
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jan 17, 2024
1 parent fbe70f4 commit c806ec3
Show file tree
Hide file tree
Showing 23 changed files with 485 additions and 49 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/puffin-cli/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use platform_tags::Tags;
use puffin_cache::Cache;
use puffin_client::{FlatIndex, FlatIndexClient, RegistryClientBuilder};
use puffin_dispatch::BuildDispatch;
use puffin_installer::Downloader;
use puffin_installer::{Downloader, NoBinary};
use puffin_interpreter::{Interpreter, PythonVersion};
use puffin_normalize::{ExtraName, PackageName};
use puffin_resolver::{
Expand Down Expand Up @@ -196,6 +196,7 @@ pub(crate) async fn pip_compile(
interpreter.sys_executable().to_path_buf(),
setup_py,
no_build,
&NoBinary::None,
)
.with_options(options);

Expand Down
17 changes: 15 additions & 2 deletions crates/puffin-cli/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use puffin_cache::Cache;
use puffin_client::{FlatIndex, FlatIndexClient, RegistryClient, RegistryClientBuilder};
use puffin_dispatch::BuildDispatch;
use puffin_installer::{
BuiltEditable, Downloader, Plan, Planner, Reinstall, ResolvedEditable, SitePackages,
BuiltEditable, Downloader, NoBinary, Plan, Planner, Reinstall, ResolvedEditable, SitePackages,
};
use puffin_interpreter::{Interpreter, Virtualenv};
use puffin_normalize::PackageName;
Expand Down Expand Up @@ -51,6 +51,7 @@ pub(crate) async fn pip_install(
link_mode: LinkMode,
setup_py: SetupPyStrategy,
no_build: bool,
no_binary: &NoBinary,
strict: bool,
exclude_newer: Option<DateTime<Utc>>,
cache: Cache,
Expand Down Expand Up @@ -164,6 +165,7 @@ pub(crate) async fn pip_install(
venv.python_executable(),
setup_py,
no_build,
no_binary,
)
.with_options(options);

Expand Down Expand Up @@ -240,6 +242,7 @@ pub(crate) async fn pip_install(
venv.python_executable(),
setup_py,
no_build,
no_binary,
)
};

Expand All @@ -249,6 +252,7 @@ pub(crate) async fn pip_install(
editables,
site_packages,
reinstall,
no_binary,
link_mode,
&index_locations,
tags,
Expand Down Expand Up @@ -451,6 +455,7 @@ async fn install(
built_editables: Vec<BuiltEditable>,
site_packages: SitePackages<'_>,
reinstall: &Reinstall,
no_binary: &NoBinary,
link_mode: LinkMode,
index_urls: &IndexLocations,
tags: &Tags,
Expand Down Expand Up @@ -478,7 +483,15 @@ async fn install(
extraneous: _,
} = Planner::with_requirements(&requirements)
.with_editable_requirements(editables)
.build(site_packages, reinstall, index_urls, cache, venv, tags)
.build(
site_packages,
reinstall,
no_binary,
index_urls,
cache,
venv,
tags,
)
.context("Failed to determine installation plan")?;

// Nothing to do.
Expand Down
18 changes: 14 additions & 4 deletions crates/puffin-cli/src/commands/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use platform_tags::Tags;
use puffin_cache::Cache;
use puffin_client::{FlatIndex, FlatIndexClient, RegistryClient, RegistryClientBuilder};
use puffin_dispatch::BuildDispatch;
use puffin_installer::{Downloader, Plan, Planner, Reinstall, ResolvedEditable, SitePackages};
use puffin_installer::{
Downloader, NoBinary, Plan, Planner, Reinstall, ResolvedEditable, SitePackages,
};
use puffin_interpreter::Virtualenv;
use puffin_resolver::InMemoryIndex;
use puffin_traits::{InFlight, SetupPyStrategy};
Expand All @@ -33,6 +35,7 @@ pub(crate) async fn pip_sync(
index_locations: IndexLocations,
setup_py: SetupPyStrategy,
no_build: bool,
no_binary: &NoBinary,
strict: bool,
cache: Cache,
mut printer: Printer,
Expand Down Expand Up @@ -89,6 +92,7 @@ pub(crate) async fn pip_sync(
venv.python_executable(),
setup_py,
no_build,
no_binary,
);

// Determine the set of installed packages.
Expand Down Expand Up @@ -121,6 +125,7 @@ pub(crate) async fn pip_sync(
.build(
site_packages,
reinstall,
no_binary,
&index_locations,
&cache,
&venv,
Expand Down Expand Up @@ -163,9 +168,14 @@ pub(crate) async fn pip_sync(
FlatIndex::from_entries(entries, tags)
};

let wheel_finder =
puffin_resolver::DistFinder::new(tags, &client, venv.interpreter(), &flat_index)
.with_reporter(FinderReporter::from(printer).with_length(remote.len() as u64));
let wheel_finder = puffin_resolver::DistFinder::new(
tags,
&client,
venv.interpreter(),
&flat_index,
no_binary,
)
.with_reporter(FinderReporter::from(printer).with_length(remote.len() as u64));
let resolution = wheel_finder.resolve(&remote).await?;

let s = if resolution.len() == 1 { "" } else { "s" };
Expand Down
2 changes: 2 additions & 0 deletions crates/puffin-cli/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;
use fs_err as fs;
use miette::{Diagnostic, IntoDiagnostic};
use owo_colors::OwoColorize;
use puffin_installer::NoBinary;
use thiserror::Error;

use distribution_types::{DistributionMetadata, IndexLocations, Name};
Expand Down Expand Up @@ -158,6 +159,7 @@ async fn venv_impl(
venv.python_executable(),
SetupPyStrategy::default(),
true,
&NoBinary::None,
);

// Resolve the seed packages.
Expand Down
34 changes: 33 additions & 1 deletion crates/puffin-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use owo_colors::OwoColorize;

use distribution_types::{FlatIndexLocation, IndexLocations, IndexUrl};
use puffin_cache::{Cache, CacheArgs};
use puffin_installer::Reinstall;
use puffin_installer::{NoBinary, Reinstall};
use puffin_interpreter::PythonVersion;
use puffin_normalize::{ExtraName, PackageName};
use puffin_resolver::{PreReleaseMode, ResolutionMode};
Expand Down Expand Up @@ -287,6 +287,20 @@ struct PipSyncArgs {
#[clap(long)]
no_build: bool,

/// Don't install pre-built wheels.
///
/// When enabled, all installed packages will be installed from a source distribution. The resolver
/// will still use pre-built wheels for metadata.
#[clap(long)]
no_binary: bool,

/// Don't install pre-built wheels for a specific package.
///
/// When enabled, the specified packages will be installed from a source distribution. The resolver
/// will still use pre-built wheels for metadata.
#[clap(long)]
no_binary_package: Vec<PackageName>,

/// Validate the virtual environment after completing the installation, to detect packages with
/// missing dependencies or other issues.
#[clap(long)]
Expand Down Expand Up @@ -397,6 +411,20 @@ struct PipInstallArgs {
#[clap(long)]
no_build: bool,

/// Don't install pre-built wheels.
///
/// When enabled, all installed packages will be installed from a source distribution. The resolver
/// will still use pre-built wheels for metadata.
#[clap(long)]
no_binary: bool,

/// Don't install pre-built wheels for a specific package.
///
/// When enabled, the specified packages will be installed from a source distribution. The resolver
/// will still use pre-built wheels for metadata.
#[clap(long)]
no_binary_package: Vec<PackageName>,

/// Validate the virtual environment after completing the installation, to detect packages with
/// missing dependencies or other issues.
#[clap(long)]
Expand Down Expand Up @@ -597,6 +625,7 @@ async fn inner() -> Result<ExitStatus> {
.map(RequirementsSource::from)
.collect::<Vec<_>>();
let reinstall = Reinstall::from_args(args.reinstall, args.reinstall_package);
let no_binary = NoBinary::from_args(args.no_binary, args.no_binary_package);
commands::pip_sync(
&sources,
&reinstall,
Expand All @@ -608,6 +637,7 @@ async fn inner() -> Result<ExitStatus> {
SetupPyStrategy::Pep517
},
args.no_build,
&no_binary,
args.strict,
cache,
printer,
Expand Down Expand Up @@ -648,6 +678,7 @@ async fn inner() -> Result<ExitStatus> {
ExtrasSpecification::Some(&args.extra)
};
let reinstall = Reinstall::from_args(args.reinstall, args.reinstall_package);
let no_binary = NoBinary::from_args(args.no_binary, args.no_binary_package);
commands::pip_install(
&requirements,
&constraints,
Expand All @@ -664,6 +695,7 @@ async fn inner() -> Result<ExitStatus> {
SetupPyStrategy::Pep517
},
args.no_build,
&no_binary,
args.strict,
args.exclude_newer,
cache,
Expand Down
Loading

0 comments on commit c806ec3

Please sign in to comment.