Skip to content

Commit

Permalink
Add uv build
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 31, 2024
1 parent f5d2f7c commit 6933f30
Show file tree
Hide file tree
Showing 15 changed files with 958 additions and 167 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

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

118 changes: 104 additions & 14 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ pub enum Commands {
after_long_help = ""
)]
Venv(VenvArgs),
/// Build Python packages into source distributions and wheels.
///
/// By default, `uv build` will build a source distribution ("sdist")
/// from the source directory, and a binary distribution ("wheel") from
/// the source distribution.
///
/// `uv build --sdist` can be used to build only the source distribution,
/// `uv build --wheel` can be used to build only the binary distribution,
/// and `uv build --sdist --wheel` can be used to build both distributions
/// from source.
#[command(
after_help = "Use `uv help build` for more details.",
after_long_help = ""
)]
Build(BuildArgs),
/// Manage uv's cache.
#[command(
after_help = "Use `uv help cache` for more details.",
Expand Down Expand Up @@ -1125,7 +1140,7 @@ pub struct PipSyncArgs {

/// The Python interpreter into which packages should be installed.
///
/// By default, syncing requires a virtual environment. An path to an
/// By default, syncing requires a virtual environment. A path to an
/// alternative Python can be provided, but it is only recommended in
/// continuous integration (CI) environments and should be used with
/// caution, as it can modify the system Python installation.
Expand Down Expand Up @@ -1407,7 +1422,7 @@ pub struct PipInstallArgs {

/// The Python interpreter into which packages should be installed.
///
/// By default, installation requires a virtual environment. An path to an
/// By default, installation requires a virtual environment. A path to an
/// alternative Python can be provided, but it is only recommended in
/// continuous integration (CI) environments and should be used with
/// caution, as it can modify the system Python installation.
Expand Down Expand Up @@ -1572,7 +1587,7 @@ pub struct PipUninstallArgs {

/// The Python interpreter from which packages should be uninstalled.
///
/// By default, uninstallation requires a virtual environment. An path to an
/// By default, uninstallation requires a virtual environment. A path to an
/// alternative Python can be provided, but it is only recommended in
/// continuous integration (CI) environments and should be used with
/// caution, as it can modify the system Python installation.
Expand Down Expand Up @@ -1923,6 +1938,49 @@ pub struct PipTreeArgs {
pub compat_args: compat::PipGlobalCompatArgs,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct BuildArgs {
/// The directory from which source distributions and/or wheels should be built.
///
/// Defaults to the current working directory.
#[arg(value_parser = parse_file_path)]
pub src_dir: Option<PathBuf>,

/// Build a source distribution ("sdist") from the given directory.
#[arg(long)]
pub sdist: bool,

/// Build a built distribution ("wheel") from the given directory.
#[arg(long)]
pub wheel: bool,

/// The Python interpreter to use for the build environment.
///
/// By default, builds are executed in isolated virtual environments. The
/// discovered interpreter will be used to create those environments, and
/// will be symlinked or copied in depending on the platform.
///
/// See `uv help python` to view supported request formats.
#[arg(
long,
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
)]
pub python: Option<String>,

#[command(flatten)]
pub resolver: ResolverArgs,

#[command(flatten)]
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct VenvArgs {
Expand Down Expand Up @@ -2298,7 +2356,7 @@ pub struct RunArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -2426,7 +2484,7 @@ pub struct SyncArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -2479,7 +2537,7 @@ pub struct LockArgs {
pub resolver: ResolverArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -2593,7 +2651,7 @@ pub struct AddArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -2662,7 +2720,7 @@ pub struct RemoveArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -2722,7 +2780,7 @@ pub struct TreeArgs {
pub frozen: bool,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub resolver: ResolverArgs,
Expand Down Expand Up @@ -2819,7 +2877,7 @@ pub struct ExportArgs {
pub resolver: ResolverArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand All @@ -2844,6 +2902,38 @@ pub struct ExportArgs {
pub python: Option<String>,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct BuildNamespace {
#[command(subcommand)]
pub command: BuildCommand,
}

#[derive(Subcommand)]
pub enum BuildCommand {
/// Run a command provided by a Python package.
///
/// By default, the package to install is assumed to match the command name.
///
/// The name of the command can include an exact version in the format
/// `<package>@<version>`, e.g., `uv tool run ruff@0.3.0`. If more complex
/// version specification is desired or if the command is provided by a
/// different package, use `--from`.
///
/// If the tool was previously installed, i.e., via `uv tool install`, the
/// installed version will be used unless a version is requested or the
/// `--isolated` flag is used.
///
/// `uvx` is provided as a convenient alias for `uv tool run`, their
/// behavior is identical.
///
/// If no command is provided, the installed tools are displayed.
///
/// Packages are installed into an ephemeral virtual environment in the uv
/// cache directory.
Run(BuildOptionsArgs),
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct ToolNamespace {
Expand Down Expand Up @@ -2966,7 +3056,7 @@ pub struct ToolRunArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -3018,7 +3108,7 @@ pub struct ToolInstallArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,

#[command(flatten)]
pub refresh: RefreshArgs,
Expand Down Expand Up @@ -3103,7 +3193,7 @@ pub struct ToolUpgradeArgs {
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,
pub build: BuildOptionsArgs,
}

#[derive(Args)]
Expand Down Expand Up @@ -3407,7 +3497,7 @@ pub struct RefreshArgs {

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct BuildArgs {
pub struct BuildOptionsArgs {
/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary Python code. The cached wheels of
Expand Down
18 changes: 11 additions & 7 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use uv_resolver::PrereleaseMode;
use uv_settings::{PipOptions, ResolverInstallerOptions, ResolverOptions};

use crate::{
BuildArgs, IndexArgs, InstallerArgs, Maybe, RefreshArgs, ResolverArgs, ResolverInstallerArgs,
BuildOptionsArgs, IndexArgs, InstallerArgs, Maybe, RefreshArgs, ResolverArgs,
ResolverInstallerArgs,
};

/// Given a boolean flag pair (like `--upgrade` and `--no-upgrade`), resolve the value of the flag.
Expand Down Expand Up @@ -206,8 +207,11 @@ impl From<IndexArgs> for PipOptions {
}
}

/// Construct the [`ResolverOptions`] from the [`ResolverArgs`] and [`BuildArgs`].
pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> ResolverOptions {
/// Construct the [`ResolverOptions`] from the [`ResolverArgs`] and [`BuildOptionsArgs`].
pub fn resolver_options(
resolver_args: ResolverArgs,
build_args: BuildOptionsArgs,
) -> ResolverOptions {
let ResolverArgs {
index_args,
upgrade,
Expand All @@ -228,7 +232,7 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
no_sources,
} = resolver_args;

let BuildArgs {
let BuildOptionsArgs {
no_build,
build,
no_build_package,
Expand Down Expand Up @@ -281,10 +285,10 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
}
}

/// Construct the [`ResolverInstallerOptions`] from the [`ResolverInstallerArgs`] and [`BuildArgs`].
/// Construct the [`ResolverInstallerOptions`] from the [`ResolverInstallerArgs`] and [`BuildOptionsArgs`].
pub fn resolver_installer_options(
resolver_installer_args: ResolverInstallerArgs,
build_args: BuildArgs,
build_args: BuildOptionsArgs,
) -> ResolverInstallerOptions {
let ResolverInstallerArgs {
index_args,
Expand All @@ -311,7 +315,7 @@ pub fn resolver_installer_options(
no_sources,
} = resolver_installer_args;

let BuildArgs {
let BuildOptionsArgs {
no_build,
build,
no_build_package,
Expand Down
1 change: 1 addition & 0 deletions crates/uv-client/src/base_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl<'a> BaseClientBuilder<'a> {
) -> Client {
// Configure the builder.
let client_builder = ClientBuilder::new()
.http1_title_case_headers()
.user_agent(user_agent)
.pool_max_idle_per_host(20)
.read_timeout(std::time::Duration::from_secs(timeout))
Expand Down
10 changes: 1 addition & 9 deletions crates/uv-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ workspace = true
[dependencies]
distribution-filename = { workspace = true }
distribution-types = { workspace = true }
install-wheel-rs = { workspace = true }
pep508_rs = { workspace = true }
pypi-types = { workspace = true }
uv-build = { workspace = true }
uv-cache = { workspace = true, features = ["clap"] }
uv-cli = { workspace = true }
uv-client = { workspace = true }
uv-configuration = { workspace = true }
uv-dispatch = { workspace = true }
uv-git = { workspace = true }
uv-installer = { workspace = true }
uv-macros = { workspace = true }
uv-options-metadata = { workspace = true }
uv-python = { workspace = true }
uv-resolver = { workspace = true }
uv-settings = { workspace = true, features = ["schemars"] }
uv-types = { workspace = true }
uv-workspace = { workspace = true, features = ["schemars"] }

# Any dependencies that are exclusively used in `uv-dev` should be listed as non-workspace
Expand All @@ -44,12 +37,11 @@ anyhow = { workspace = true }
clap = { workspace = true, features = ["derive", "wrap_help"] }
fs-err = { workspace = true, features = ["tokio"] }
itertools = { workspace = true }
markdown = "0.3.0"
markdown = { version = "0.3.0" }
owo-colors = { workspace = true }
poloto = { version = "19.1.2", optional = true }
pretty_assertions = { version = "1.4.0" }
resvg = { version = "0.29.0", optional = true }
rustc-hash = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
Loading

0 comments on commit 6933f30

Please sign in to comment.