Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add uv support for Python. #1810

Merged
merged 8 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prototools
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ deno = "2.1.7"
node = "20.8.0"
npm = "10.1.0"
pkl = "0.27.2"
python = "3.11.10"
uv = "0.5.26"

[plugins]
pkl = "https://raw.githubusercontent.com/milesj/proto-plugins/refs/heads/master/pkl.toml"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
- Added support for v3 and v4 lockfiles (we now use the `deno_lockfile` crate).
- Added basic support for workspaces.
- Added `deno.installArgs` setting.
- Improved the Python toolchain.
- Added unstable uv support. Can be enabled with the new `python.packageManager` setting.
- Right now, has basic toolchain support, including dependency install and virtual environments.
- Renamed `python.rootRequirementsOnly` to `python.rootVenvOnly`.
- Will now inherit versions from the root `.prototools`.
- Improved the Rust toolchain.
- The root-level project is now properly taken into account when detecting the package workspaces.
- Project dependencies (`dependsOn`) are now automatically inferred from `Cargo.toml`
Expand Down
125 changes: 77 additions & 48 deletions Cargo.lock

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

123 changes: 77 additions & 46 deletions crates/cli/tests/run_python_test.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
use moon_config::{PartialPipConfig, PartialPythonConfig};
use moon_config::{PartialPipConfig, PartialPythonConfig, PartialUvConfig, PythonPackageManager};
use moon_test_utils::{
assert_snapshot, create_sandbox_with_config, get_python_fixture_configs, Sandbox,
assert_snapshot, create_sandbox_with_config, get_python_fixture_configs,
predicates::prelude::*, Sandbox,
};
use proto_core::UnresolvedVersionSpec;

fn python_sandbox(config: PartialPythonConfig) -> Sandbox {
python_sandbox_with_config(|_| {}, config)
python_sandbox_with_config("python", config)
}

fn python_sandbox_with_config<C>(callback: C, config: PartialPythonConfig) -> Sandbox
where
C: FnOnce(&mut PartialPythonConfig),
{
fn python_sandbox_with_config(fixture: &str, config: PartialPythonConfig) -> Sandbox {
let (workspace_config, mut toolchain_config, tasks_config) = get_python_fixture_configs();

toolchain_config.python = Some(config);

if let Some(python_config) = &mut toolchain_config.python {
callback(python_config);
}

let sandbox = create_sandbox_with_config(
"python",
fixture,
Some(workspace_config),
Some(toolchain_config),
Some(tasks_config),
Expand All @@ -31,39 +25,76 @@ where
sandbox
}

#[test]
fn runs_standard_script() {
let sandbox = python_sandbox(PartialPythonConfig {
version: Some(UnresolvedVersionSpec::parse("3.11.10").unwrap()),
..PartialPythonConfig::default()
});
let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:standard");
});

assert_snapshot!(assert.output());
}
mod python {
use super::*;

#[test]
fn runs_standard_script() {
let sandbox = python_sandbox(PartialPythonConfig {
version: Some(UnresolvedVersionSpec::parse("3.11.10").unwrap()),
..PartialPythonConfig::default()
});
let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:standard");
});

assert_snapshot!(assert.output());
}

mod pip {
use super::*;

#[test]
fn runs_install_deps_via_args() {
let sandbox = python_sandbox(PartialPythonConfig {
version: Some(UnresolvedVersionSpec::parse("3.11.10").unwrap()),
pip: Some(PartialPipConfig {
install_args: Some(vec![
"--quiet".to_string(),
"--disable-pip-version-check".to_string(),
"poetry==1.8.4".to_string(),
]),
}),
..PartialPythonConfig::default()
});

// Needed for venv
sandbox.create_file("base/requirements.txt", "");

#[test]
fn runs_install_deps_via_args() {
let sandbox = python_sandbox(PartialPythonConfig {
version: Some(UnresolvedVersionSpec::parse("3.11.10").unwrap()),
pip: Some(PartialPipConfig {
install_args: Some(vec![
"--quiet".to_string(),
"--disable-pip-version-check".to_string(),
"poetry==1.8.4".to_string(),
]),
}),
..PartialPythonConfig::default()
});

// Needed for venv
sandbox.create_file("base/requirements.txt", "");

let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:poetry");
});

assert_snapshot!(assert.output());
let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:poetry");
});

assert_snapshot!(assert.output());
}
}

mod uv {
use super::*;

#[test]
fn runs_install_deps_via_args() {
let sandbox = python_sandbox_with_config(
"python-uv",
PartialPythonConfig {
version: Some(UnresolvedVersionSpec::parse("3.11.10").unwrap()),
package_manager: Some(PythonPackageManager::Uv),
uv: Some(PartialUvConfig {
version: Some(UnresolvedVersionSpec::parse("0.5.26").unwrap()),
..PartialUvConfig::default()
}),
..PartialPythonConfig::default()
},
);

let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:uv");
});

let output = assert.output();

assert!(predicate::str::contains("uv 0.5.26").eval(&output));
assert!(predicate::str::contains("Creating virtual environment").eval(&output));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/cli/tests/run_python_test.rs
expression: assert.output()
---
▪▪▪▪ python -m venv
▪▪▪▪ pip install
▪▪▪▪ python:poetry
Poetry (version 1.8.4)
▪▪▪▪ python:poetry (100ms)

Tasks: 1 completed
Time: 100ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/cli/tests/run_python_test.rs
expression: assert.output()
---
▪▪▪▪ pip install
▪▪▪▪ python:standard
Python 3.11.10
▪▪▪▪ python:standard (100ms)

Tasks: 1 completed
Time: 100ms
Loading
Loading