Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Feb 13, 2025
1 parent b015bb7 commit 24be46c
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 99 deletions.
40 changes: 15 additions & 25 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,15 +1079,23 @@ pub struct PipCompileArgs {

/// The Python interpreter to use during resolution.
///
/// A Python interpreter is required for building source distributions to
/// determine package metadata when there are not wheels.
/// A Python interpreter is required for building source distributions to determine package
/// metadata when there are not wheels.
///
/// The interpreter is also used to determine the default minimum Python version, unless
/// `--python-version` is provided.
///
/// The interpreter is also used to determine the default minimum Python
/// version, unless `--python-version` is provided.
/// This option respects `UV_PYTHON`, but when set via environment variable, it is overridden
/// by `--python-version`.
///
/// See `uv help python` for details on Python discovery and supported
/// request formats.
#[arg(long, verbatim_doc_comment, help_heading = "Python options", value_parser = parse_maybe_string)]
/// See `uv help python` for details on Python discovery and supported request formats.
#[arg(
long,
short,
verbatim_doc_comment,
help_heading = "Python options",
value_parser = parse_maybe_string
)]
pub python: Option<Maybe<String>>,

/// Install packages into the system Python environment.
Expand Down Expand Up @@ -1173,24 +1181,6 @@ pub struct PipCompileArgs {
#[arg(long, help_heading = "Python options")]
pub python_version: Option<PythonVersion>,

/// The Python interpreter or version to use for resolution.
///
/// In previous versions of uv, `-p` was an alias for `--python-version` in `uv pip compile` but
/// an alias for `--python` in all other commands. This option is provided as a backwards
/// compatible shim, allowing `-p` to behave as `--python` without introducing a breaking
/// change.
///
/// `UV_PYTHON` is respected, but overridden by `--python-version` or `--python`.
#[arg(
short,
hide = true,
conflicts_with_all = ["python",
"python_version"],
value_name = "PYTHON",
help_heading = "Python options"
)]
pub python_legacy: Option<String>,

/// The platform for which requirements should be resolved.
///
/// Represented as a "target triple", a string that describes the target platform in terms of
Expand Down
35 changes: 17 additions & 18 deletions crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use uv_resolver::{
InMemoryIndex, OptionsBuilder, PrereleaseMode, PythonRequirement, RequiresPython,
ResolutionMode, ResolverEnvironment,
};
use uv_static::EnvVars;
use uv_types::{BuildIsolation, EmptyInstalledPackages, HashStrategy};
use uv_warnings::warn_user;

Expand Down Expand Up @@ -96,7 +95,6 @@ pub(crate) async fn pip_compile(
annotation_style: AnnotationStyle,
link_mode: LinkMode,
mut python: Option<String>,
mut python_legacy: Option<String>,
system: bool,
python_preference: PythonPreference,
concurrency: Concurrency,
Expand All @@ -106,26 +104,26 @@ pub(crate) async fn pip_compile(
printer: Printer,
preview: PreviewMode,
) -> Result<ExitStatus> {
// Respect `UV_PYTHON` with legacy behavior
if python_legacy.is_none() && python_version.is_none() && python.is_none() {
if let Ok(python) = std::env::var(EnvVars::UV_PYTHON) {
if !python.is_empty() {
python_legacy = Some(python);
// Respect `UV_PYTHON`
if python.is_none() && python_version.is_none() {
if let Ok(request) = std::env::var("UV_PYTHON") {
if !request.is_empty() {
python = Some(request);
}
}
}

// Resolve `-p` into `--python-version` or `--python`
if let Some(python_legacy) = python_legacy {
// `-p` is mutually exclusive with these options at the CLI level so it's safe to replace
// them
debug_assert!(python_version.is_none());
debug_assert!(python.is_none());

if let Ok(version) = PythonVersion::from_str(&python_legacy) {
python_version = Some(version);
} else {
python = Some(python_legacy);
// If `--python` / `-p` is a simple Python version request, we treat it as `--python-version`
// for backwards compatibility. `-p` was previously aliased to `--python-version` but changed to
// `--python` for consistency with the rest of the CLI in v0.6.0. Since we assume metadata is
// consistent across wheels, it's okay for us to build wheels (to determine metadata) with an
// alternative Python interpreter as long as we solve with the proper Python version tags.
if python_version.is_none() {
if let Some(request) = python.as_ref() {
if let Ok(version) = PythonVersion::from_str(request) {
python_version = Some(version);
python = None;
}
}
}

Expand Down Expand Up @@ -242,6 +240,7 @@ pub(crate) async fn pip_compile(
&& python_version.minor() == interpreter.python_minor()
};
if no_build.is_none()
&& python.is_none()
&& python_version.version() != interpreter.python_version()
&& (python_version.patch().is_some() || !matches_without_patch)
{
Expand Down
1 change: 0 additions & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.annotation_style,
args.settings.link_mode,
args.settings.python,
args.python_legacy,
args.settings.system,
globals.python_preference,
globals.concurrency,
Expand Down
3 changes: 0 additions & 3 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,6 @@ pub(crate) struct PipCompileSettings {
pub(crate) overrides_from_workspace: Vec<Requirement>,
pub(crate) environments: SupportedEnvironments,
pub(crate) refresh: Refresh,
pub(crate) python_legacy: Option<String>,
pub(crate) settings: PipSettings,
}

Expand Down Expand Up @@ -1582,7 +1581,6 @@ impl PipCompileSettings {
no_binary,
only_binary,
python_version,
python_legacy,
python_platform,
universal,
no_universal,
Expand Down Expand Up @@ -1652,7 +1650,6 @@ impl PipCompileSettings {
overrides_from_workspace,
environments,
refresh: Refresh::from(refresh),
python_legacy,
settings: PipSettings::combine(
PipOptions {
python: python.and_then(Maybe::into_option),
Expand Down
Loading

0 comments on commit 24be46c

Please sign in to comment.