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 Python tier 2 and 3 support. #1694

Merged
merged 34 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a584eee
Save my work
harlequin Oct 12, 2024
6e9ca3a
next iteration
harlequin Oct 14, 2024
431e197
Latest version
harlequin Oct 14, 2024
3650ed5
Merge branch 'master' of https://github.com/harlequin/moon into pytho…
harlequin Oct 14, 2024
b0b9a81
Run linter
harlequin Oct 14, 2024
3ce7527
run pip with install args
harlequin Oct 16, 2024
287fb77
build: Prepare v1.30 release.
milesj Oct 18, 2024
542ded8
new: Add new workspace builder. (#1697)
milesj Oct 24, 2024
b50cae4
Add Tests and re-work based on discussions
harlequin Oct 30, 2024
07cda58
Add documentation
harlequin Oct 30, 2024
290a42a
Resolve conflict
harlequin Oct 30, 2024
f1a7c07
Merge branch 'develop-1.30' into python-plattform-support
harlequin Oct 30, 2024
d5b59d2
Save my work
harlequin Oct 12, 2024
e8b1ae5
next iteration
harlequin Oct 14, 2024
59c55df
Latest version
harlequin Oct 14, 2024
ac83571
Run linter
harlequin Oct 14, 2024
16d5038
run pip with install args
harlequin Oct 16, 2024
4fe41c3
Add Tests and re-work based on discussions
harlequin Oct 30, 2024
0e984d4
Add documentation
harlequin Oct 30, 2024
89d1557
new: Add new workspace builder. (#1697)
milesj Oct 24, 2024
c29a7dc
Add last commit
harlequin Nov 4, 2024
0a9757b
Rebase completed
harlequin Nov 4, 2024
2cdd563
Merge branch 'python-plattform-support' of https://github.com/harlequ…
harlequin Nov 4, 2024
fb18177
Revert new language
harlequin Nov 4, 2024
d192b37
Final commit after format, lint and build
harlequin Nov 4, 2024
116cb27
Resolve Issues based on suggestions
harlequin Nov 8, 2024
00d4426
Merge with current develop-1.30
harlequin Nov 11, 2024
c99a369
Execute lint and format
harlequin Nov 11, 2024
7e21f57
Fix testing for python areas
harlequin Nov 12, 2024
069d361
Fix project_config_test
harlequin Nov 12, 2024
c655e88
Resolve latest comments
harlequin Nov 14, 2024
63dc2c7
Merge branch 'develop-1.30' of https://github.com/moonrepo/moon into …
harlequin Nov 14, 2024
d8a12b1
Update changelog.md
harlequin Nov 14, 2024
de63df4
Merge branch 'develop-1.30' into python-plattform-support
harlequin Nov 15, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
- Added 7 new token variables: `$arch`, `$os`, `$osFamily`, `$vcsBranch`, `$vcsRepository`,
`$vcsRevision`, `$workingDir`
- Added a `rust.binstallVersion` setting to `.moon/toolchain.yml`.
- Added Python tier 3 support.
- Will download and install Python into the toolchain when a `version` is configured.
- Will parse the `requirements.txt` to resolve and install dependencies.
- Added a `python.version` setting to `.moon/toolchain.yml`.
- Added a `toolchain.python` setting to `moon.yml`.
- Updated `moon bin` commands to support Python.

#### 🐞 Fixes

Expand Down
118 changes: 118 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ moon_deno_platform = { path = "../../legacy/deno/platform" }
moon_node_lang = { path = "../../legacy/node/lang" }
moon_node_tool = { path = "../../legacy/node/tool" }
moon_node_platform = { path = "../../legacy/node/platform" }
moon_python_lang = { path = "../../legacy/python/lang" }
moon_python_tool = { path = "../../legacy/python/tool" }
moon_python_platform = { path = "../../legacy/python/platform" }
moon_rust_lang = { path = "../../legacy/rust/lang" }
moon_rust_tool = { path = "../../legacy/rust/tool" }
moon_rust_platform = { path = "../../legacy/rust/platform" }
Expand Down
13 changes: 13 additions & 0 deletions crates/app/src/systems/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use moon_console::{Checkpoint, Console};
use moon_deno_platform::DenoPlatform;
use moon_node_platform::NodePlatform;
use moon_platform::PlatformManager;
use moon_python_platform::PythonPlatform;
use moon_rust_platform::RustPlatform;
use moon_system_platform::SystemPlatform;
use moon_toolchain_plugin::ToolchainRegistry;
Expand Down Expand Up @@ -172,6 +173,18 @@ pub async fn register_platforms(
);
}

if let Some(python_config) = &toolchain_config.python {
registry.register(
PlatformType::Python,
Box::new(PythonPlatform::new(
python_config,
workspace_root,
Arc::clone(proto_env),
Arc::clone(&console),
)),
);
}

if let Some(rust_config) = &toolchain_config.rust {
registry.register(
PlatformType::Rust,
Expand Down
65 changes: 65 additions & 0 deletions crates/cli/tests/run_python_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use moon_config::{PartialPipConfig, PartialPythonConfig};
use moon_test_utils::{
assert_snapshot, create_sandbox_with_config, get_python_fixture_configs, Sandbox,
};
use proto_core::UnresolvedVersionSpec;

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

fn python_sandbox_with_config<C>(callback: C, config: PartialPythonConfig) -> Sandbox
where
C: FnOnce(&mut PartialPythonConfig),
{
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",
Some(workspace_config),
Some(toolchain_config),
Some(tasks_config),
);

sandbox.enable_git();
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());
}

#[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()
});
let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("python:poetry");
});

assert_snapshot!(assert.output());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/cli/tests/run_python_test.rs
assertion_line: 60
expression: assert.output()
snapshot_kind: text
---
▪▪▪▪ activate virtual environment
▪▪▪▪ 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
assertion_line: 38
expression: assert.output()
---
▪▪▪▪ python:standard
Python 3.11.10
▪▪▪▪ python:standard (100ms)

Tasks: 1 completed
Time: 100ms
2 changes: 2 additions & 0 deletions crates/config/src/language_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ derive_enum!(
Bun,
Deno,
Node,
Python,
Rust,
System,
#[default]
Expand Down Expand Up @@ -103,6 +104,7 @@ mod tests {
assert_eq!(LanguageType::Go.to_string(), "go");
assert_eq!(LanguageType::JavaScript.to_string(), "javascript");
assert_eq!(LanguageType::Ruby.to_string(), "ruby");
assert_eq!(LanguageType::Python.to_string(), "python");
assert_eq!(LanguageType::Unknown.to_string(), "unknown");
assert_eq!(LanguageType::Other(Id::raw("dotnet")).to_string(), "dotnet");
}
Expand Down
4 changes: 4 additions & 0 deletions crates/config/src/project/overrides_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ cacheable!(
#[setting(nested)]
pub deno: Option<ProjectToolchainCommonToolConfig>,

/// Overrides `python` settings.
#[setting(nested)]
pub python: Option<ProjectToolchainCommonToolConfig>,

/// Overrides `node` settings.
#[setting(nested)]
pub node: Option<ProjectToolchainCommonToolConfig>,
Expand Down
2 changes: 2 additions & 0 deletions crates/config/src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod bun_config;
mod deno_config;
mod moon_config;
mod node_config;
mod python_config;
mod rust_config;
mod typescript_config;

Expand All @@ -11,6 +12,7 @@ pub use bun_config::*;
pub use deno_config::*;
pub use moon_config::*;
pub use node_config::*;
pub use python_config::*;
pub use rust_config::*;
pub use typescript_config::*;

Expand Down
35 changes: 35 additions & 0 deletions crates/config/src/toolchain/python_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// use super::bin_config::BinEntry;
use schematic::Config;
use serde::Serialize;
use version_spec::UnresolvedVersionSpec;
use warpgate_api::PluginLocator;

#[derive(Clone, Config, Debug, PartialEq, Serialize)]
pub struct PipConfig {
/// List of arguments to append to `pip install` commands.
pub install_args: Option<Vec<String>>,
}

#[derive(Clone, Config, Debug, PartialEq)]
pub struct PythonConfig {
/// Location of the WASM plugin to use for Python support.
pub plugin: Option<PluginLocator>,

/// Options for pip, when used as a package manager.
#[setting(nested)]
pub pip: Option<PipConfig>,

/// Defines the virtual environment name which will be created on workspace root.
/// Project dependencies will be installed into this. Defaults to `.venv`
#[setting(default = ".venv")]
pub venv_name: String,

/// Assumes only the root `requirements.txt` is used for dependencies.
/// Can be used to support the "one version policy" pattern.
#[setting(default = true)]
pub root_requirements_only: bool,

/// The version of Python to download, install, and run `python` tasks with.
#[setting(env = "MOON_PYTHON_VERSION")]
pub version: Option<UnresolvedVersionSpec>,
}
Loading
Loading