Skip to content

Commit

Permalink
new: Add Python tier 2 and 3 support. (#1694)
Browse files Browse the repository at this point in the history
* Save my work

* next iteration

* Latest version

* Run linter

* run pip with install args

* build: Prepare v1.30 release.

* new: Add new workspace builder. (#1697)

* Add workspace crate.

* Add projects loading.

* Add build.

* Clean up build data.

* Flesh out build.

* Add caching.

* Add to session.

* Use focused graphs.

* Add workspace mocker.

* Delete old graph builder.

* Polish.

* Fix tests.

* Fix tests.

* Add Tests and re-work based on discussions

* Add documentation

* Resolve conflict

* Save my work

* next iteration

* Latest version

* Run linter

* run pip with install args

* Add Tests and re-work based on discussions

* Add documentation

* new: Add new workspace builder. (#1697)

* Add workspace crate.

* Add projects loading.

* Add build.

* Clean up build data.

* Flesh out build.

* Add caching.

* Add to session.

* Use focused graphs.

* Add workspace mocker.

* Delete old graph builder.

* Polish.

* Fix tests.

* Fix tests.

* Add last commit

* Rebase completed

* Revert new language

* Final commit after format, lint and build

* Resolve Issues based on suggestions

- remove yarn version modification
- remove version configuration for pip, if user want's to update the pip dependency he can do this via the requirements.txt or installArgs method
- add root_requirements_only, to be able to create venv in project scope or in workspace scope
- pip_requirements fixed the occupied/vaccant
- clean up Cargo.toml
- reworked and rethinked the install_deps and setup_tool function; install_deps phase is absolute sufficient
- remove not needed comments
- remove all references to get_workspace_root
- Cleaned up CHANGELOG.md

* Execute lint and format

* Fix testing for python areas

* Fix project_config_test

* Resolve latest comments

* Update changelog.md

---------

Co-authored-by: Miles Johnson <[email protected]>
Co-authored-by: Miles Johnson <[email protected]>
  • Loading branch information
3 people committed Nov 25, 2024
1 parent d7223f8 commit 2cfc800
Show file tree
Hide file tree
Showing 43 changed files with 1,346 additions and 17 deletions.
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

0 comments on commit 2cfc800

Please sign in to comment.