Skip to content

Commit

Permalink
Add --config-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 23, 2024
1 parent 8a12b2e commit 74b4969
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 35 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/uv-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ platform-host = { path = "../platform-host" }
uv-extract = { path = "../uv-extract" }
uv-fs = { path = "../uv-fs" }
uv-interpreter = { path = "../uv-interpreter" }
uv-traits = { path = "../uv-traits" }
uv-traits = { path = "../uv-traits", features = ["serde"] }
pypi-types = { path = "../pypi-types" }

anyhow = { workspace = true }
Expand Down
27 changes: 20 additions & 7 deletions crates/uv-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use distribution_types::Resolution;
use pep508_rs::Requirement;
use uv_fs::Normalized;
use uv_interpreter::{Interpreter, Virtualenv};
use uv_traits::{BuildContext, BuildKind, SetupPyStrategy, SourceBuildTrait};
use uv_traits::{BuildContext, BuildKind, ConfigSettings, SetupPyStrategy, SourceBuildTrait};

/// e.g. `pygraphviz/graphviz_wrap.c:3020:10: fatal error: graphviz/cgraph.h: No such file or directory`
static MISSING_HEADER_RE: Lazy<Regex> = Lazy::new(|| {
Expand Down Expand Up @@ -247,6 +247,7 @@ pub struct SourceBuildContext {
pub struct SourceBuild {
temp_dir: TempDir,
source_tree: PathBuf,
config_settings: ConfigSettings,
/// If performing a PEP 517 build, the backend to use.
pep517_backend: Option<Pep517Backend>,
/// The virtual environment in which to build the source distribution.
Expand Down Expand Up @@ -281,6 +282,7 @@ impl SourceBuild {
source_build_context: SourceBuildContext,
package_id: String,
setup_py: SetupPyStrategy,
config_settings: ConfigSettings,
build_kind: BuildKind,
) -> Result<SourceBuild, Error> {
let temp_dir = tempdir_in(build_context.cache().root())?;
Expand Down Expand Up @@ -354,6 +356,7 @@ impl SourceBuild {
build_context,
&package_id,
build_kind,
&config_settings,
)
.await?;
}
Expand All @@ -364,6 +367,7 @@ impl SourceBuild {
pep517_backend,
venv,
build_kind,
config_settings,
metadata_directory: None,
package_id,
})
Expand Down Expand Up @@ -492,10 +496,13 @@ impl SourceBuild {
prepare_metadata_for_build_wheel = getattr(backend, "prepare_metadata_for_build_wheel", None)
if prepare_metadata_for_build_wheel:
print(prepare_metadata_for_build_wheel("{}"))
print(prepare_metadata_for_build_wheel("{}", config_settings={}))
else:
print()
"#, pep517_backend.backend_import(), escape_path_for_python(&metadata_directory)
"#,
pep517_backend.backend_import(),
escape_path_for_python(&metadata_directory),
self.config_settings.escape_for_python(),
};
let span = info_span!(
"run_python_script",
Expand Down Expand Up @@ -619,8 +626,13 @@ impl SourceBuild {
let escaped_wheel_dir = escape_path_for_python(wheel_dir);
let script = formatdoc! {
r#"{}
print(backend.build_{}("{}", metadata_directory={}))
"#, pep517_backend.backend_import(), self.build_kind, escaped_wheel_dir, metadata_directory
print(backend.build_{}("{}", metadata_directory={}, config_settings={}))
"#,
pep517_backend.backend_import(),
self.build_kind,
escaped_wheel_dir,
metadata_directory,
self.config_settings.escape_for_python()
};
let span = info_span!(
"run_python_script",
Expand Down Expand Up @@ -682,6 +694,7 @@ async fn create_pep517_build_environment(
build_context: &impl BuildContext,
package_id: &str,
build_kind: BuildKind,
config_settings: &ConfigSettings,
) -> Result<(), Error> {
debug!(
"Calling `{}.get_requires_for_build_{}()`",
Expand All @@ -694,11 +707,11 @@ async fn create_pep517_build_environment(
get_requires_for_build = getattr(backend, "get_requires_for_build_{}", None)
if get_requires_for_build:
requires = get_requires_for_build()
requires = get_requires_for_build(config_settings={})
else:
requires = []
print(json.dumps(requires))
"#, pep517_backend.backend_import(), build_kind
"#, pep517_backend.backend_import(), build_kind, config_settings.escape_for_python()
};
let span = info_span!(
"run_python_script",
Expand Down
5 changes: 4 additions & 1 deletion crates/uv-dev/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use uv_dispatch::BuildDispatch;
use uv_installer::NoBinary;
use uv_interpreter::Virtualenv;
use uv_resolver::InMemoryIndex;
use uv_traits::{BuildContext, BuildKind, InFlight, NoBuild, SetupPyStrategy};
use uv_traits::{BuildContext, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(Parser)]
pub(crate) struct BuildArgs {
Expand Down Expand Up @@ -61,6 +61,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {
let index = InMemoryIndex::default();
let setup_py = SetupPyStrategy::default();
let in_flight = InFlight::default();
let config_settings = ConfigSettings::default();

let build_dispatch = BuildDispatch::new(
&client,
Expand All @@ -72,6 +73,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {
&in_flight,
venv.python_executable(),
setup_py,
&config_settings,
&NoBuild::None,
&NoBinary::None,
);
Expand All @@ -84,6 +86,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {
SourceBuildContext::default(),
args.sdist.display().to_string(),
setup_py,
config_settings.clone(),
build_kind,
)
.await?;
Expand Down
5 changes: 3 additions & 2 deletions crates/uv-dev/src/install_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use uv_installer::{Downloader, NoBinary};
use uv_interpreter::Virtualenv;
use uv_normalize::PackageName;
use uv_resolver::{DistFinder, InMemoryIndex};
use uv_traits::{BuildContext, InFlight, NoBuild, SetupPyStrategy};
use uv_traits::{BuildContext, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(Parser)]
pub(crate) struct InstallManyArgs {
Expand Down Expand Up @@ -65,12 +65,12 @@ pub(crate) async fn install_many(args: InstallManyArgs) -> Result<()> {
let setup_py = SetupPyStrategy::default();
let in_flight = InFlight::default();
let tags = venv.interpreter().tags()?;

let no_build = if args.no_build {
NoBuild::All
} else {
NoBuild::None
};
let config_settings = ConfigSettings::default();

let build_dispatch = BuildDispatch::new(
&client,
Expand All @@ -82,6 +82,7 @@ pub(crate) async fn install_many(args: InstallManyArgs) -> Result<()> {
&in_flight,
venv.python_executable(),
setup_py,
&config_settings,
&no_build,
&NoBinary::None,
);
Expand Down
5 changes: 3 additions & 2 deletions crates/uv-dev/src/resolve_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uv_dispatch::BuildDispatch;
use uv_installer::NoBinary;
use uv_interpreter::Virtualenv;
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
use uv_traits::{InFlight, NoBuild, SetupPyStrategy};
use uv_traits::{ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(ValueEnum, Default, Clone)]
pub(crate) enum ResolveCliFormat {
Expand Down Expand Up @@ -72,12 +72,12 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> Result<()> {
};
let index = InMemoryIndex::default();
let in_flight = InFlight::default();

let no_build = if args.no_build {
NoBuild::All
} else {
NoBuild::None
};
let config_settings = ConfigSettings::default();

let build_dispatch = BuildDispatch::new(
&client,
Expand All @@ -89,6 +89,7 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> Result<()> {
&in_flight,
venv.python_executable(),
SetupPyStrategy::default(),
&config_settings,
&no_build,
&NoBinary::None,
);
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-dev/src/resolve_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use uv_installer::NoBinary;
use uv_interpreter::Virtualenv;
use uv_normalize::PackageName;
use uv_resolver::InMemoryIndex;
use uv_traits::{BuildContext, InFlight, NoBuild, SetupPyStrategy};
use uv_traits::{BuildContext, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(Parser)]
pub(crate) struct ResolveManyArgs {
Expand Down Expand Up @@ -96,6 +96,7 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> {
let index_locations = IndexLocations::default();
let setup_py = SetupPyStrategy::default();
let flat_index = FlatIndex::default();
let config_settings = ConfigSettings::default();

// Create a `BuildDispatch` for each requirement.
let build_dispatch = BuildDispatch::new(
Expand All @@ -108,6 +109,7 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> {
&in_flight,
venv.python_executable(),
setup_py,
&config_settings,
&no_build,
&NoBinary::None,
);
Expand Down
6 changes: 5 additions & 1 deletion crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uv_client::{FlatIndex, RegistryClient};
use uv_installer::{Downloader, Installer, NoBinary, Plan, Planner, Reinstall, SitePackages};
use uv_interpreter::{Interpreter, Virtualenv};
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
use uv_traits::{BuildContext, BuildKind, InFlight, NoBuild, SetupPyStrategy};
use uv_traits::{BuildContext, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

/// The main implementation of [`BuildContext`], used by the CLI, see [`BuildContext`]
/// documentation.
Expand All @@ -34,6 +34,7 @@ pub struct BuildDispatch<'a> {
setup_py: SetupPyStrategy,
no_build: &'a NoBuild,
no_binary: &'a NoBinary,
config_settings: &'a ConfigSettings,
source_build_context: SourceBuildContext,
options: Options,
}
Expand All @@ -50,6 +51,7 @@ impl<'a> BuildDispatch<'a> {
in_flight: &'a InFlight,
base_python: PathBuf,
setup_py: SetupPyStrategy,
config_settings: &'a ConfigSettings,
no_build: &'a NoBuild,
no_binary: &'a NoBinary,
) -> Self {
Expand All @@ -63,6 +65,7 @@ impl<'a> BuildDispatch<'a> {
in_flight,
base_python,
setup_py,
config_settings,
no_build,
no_binary,
source_build_context: SourceBuildContext::default(),
Expand Down Expand Up @@ -279,6 +282,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.source_build_context.clone(),
package_id.to_string(),
self.setup_py,
self.config_settings.clone(),
build_kind,
)
.boxed()
Expand Down
7 changes: 7 additions & 0 deletions crates/uv-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license = { workspace = true }
workspace = true

[dependencies]
clap = { workspace = true, optional = true }
distribution-types = { path = "../distribution-types" }
once-map = { path = "../once-map" }
pep508_rs = { path = "../pep508-rs" }
Expand All @@ -21,4 +22,10 @@ uv-interpreter = { path = "../uv-interpreter" }
uv-normalize = { path = "../uv-normalize" }

anyhow = { workspace = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
tokio = { workspace = true, features = ["sync"] }

[features]
default = []
serde = ["dep:serde", "dep:serde_json"]
Loading

0 comments on commit 74b4969

Please sign in to comment.