Skip to content

Commit

Permalink
Add huak-toolchain crate
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Oct 29, 2023
1 parent 25d737a commit 6137810
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/huak-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ colored = { workspace = true }
huak-home = { path = "../huak-home" }
huak-package-manager = { path = "../huak-package-manager"}
huak-python-manager = { path = "../huak-python-manager" }
huak-toolchain = { path = "../huak-toolchain" }
human-panic = { workspace = true }
# included to build PyPi Wheels (see .github/workflow/README.md)
openssl = { version = "0.10.57", features = ["vendored"], optional = true }
Expand Down
88 changes: 77 additions & 11 deletions crates/huak-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ enum Commands {
#[arg(last = true)]
trailing: Option<Vec<String>>,
},
/// Manage toolchains.
#[clap(alias = "tc")]
Toolchain {
#[command(subcommand)]
command: Toolchain,
},
/// Update the project's dependencies.
Update {
#[arg(num_args = 0..)]
Expand Down Expand Up @@ -188,21 +194,66 @@ enum Python {

#[derive(Subcommand)]
enum Toolchain {
/// List available toolchains.
List,
/// Use an available toolchain.
Use {
/// The version of Python to use.
#[arg(required = true)]
version: RequestedVersion,
/// Add a tool to a toolchain.
Add {
/// A tool to add.
tool: String,
/// Add a tool to a specific channel.
#[arg(long, required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
},
/// Display information about a toolchain.
Info {
/// The toolchain channel to display information for.
#[arg(required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
},
/// Install a toolchain.
Install {
/// The version of Python to install.
#[arg(required = true)]
version: RequestedVersion,
/// The toolchain channel to install.
#[arg(required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
/// The path to install a toolchain to.
target: PathBuf,
#[arg(required = false)]
target: Option<PathBuf>, // TODO(cnpryer): Could default to home dir toolchains dir.
},
/// List available toolchains.
List,
/// Remove a tool from a toolchain.
Remove {
/// A tool to add.
tool: String,
/// Remove a tool from a specific channel.
#[arg(long, required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
},
/// Run a tool installed to a toolchain.
Run {
/// The tool to run.
tool: String,
/// The toolchain channel to run a tool from.
#[arg(long, required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
},
/// Uninstall a toolchain.
Uninstall {
/// The toolchain channel to uninstall.
#[arg(required = false)]
channel: Option<String>, // TODO(cnpryer): Parse `Channel`
},
/// Update the current toolchain.
Update {
/// A tool to update.
#[arg(required = false)]
tool: Option<String>, // TODO(cnpryer): Either include @version or add version arg.
/// The toolchain channel to update.
#[arg(long, required = false)]
channel: Option<String>,
},
/// Use an available toolchain.
Use {
/// The toolchain channel to use.
channel: String, // TODO(cnpryer): Parse `Channel`
},
}

Expand Down Expand Up @@ -345,6 +396,7 @@ fn exec_command(cmd: Commands, config: &mut Config) -> HuakResult<()> {
};
test(config, &options)
}
Commands::Toolchain { command } => toolchain(command, config),
Commands::Update {
dependencies,
trailing,
Expand Down Expand Up @@ -474,6 +526,20 @@ fn test(config: &Config, options: &TestOptions) -> HuakResult<()> {
ops::test_project(config, options)
}

fn toolchain(command: Toolchain, config: &Config) -> HuakResult<()> {
match command {
Toolchain::Add { tool, channel } => ops::add_to_toolchain(tool, channel, config),
Toolchain::Info { channel } => ops::display_toolchain_info(channel, config),
Toolchain::Install { channel, target } => ops::install_toolchain(channel, target, config),
Toolchain::List => ops::list_toolchains(config),
Toolchain::Remove { tool, channel } => ops::remove_from_toolchain(tool, channel, config),
Toolchain::Run { tool, channel } => ops::run_from_toolchain(tool, channel, config),
Toolchain::Uninstall { channel } => ops::uninstall_toolchain(channel, config),
Toolchain::Update { tool, channel } => ops::update_toolchain(tool, channel, config),
Toolchain::Use { channel } => ops::use_toolchain(channel, config),
}
}

fn update(
dependencies: Option<Vec<String>>,
config: &Config,
Expand Down
6 changes: 6 additions & 0 deletions crates/huak-package-manager/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod python;
mod remove;
mod run;
mod test;
mod toolchain;
mod update;
mod version;

Expand All @@ -33,6 +34,11 @@ pub use remove::{remove_project_dependencies, RemoveOptions};
pub use run::run_command_str;
use std::{path::PathBuf, process::Command};
pub use test::{test_project, TestOptions};
pub use toolchain::{
add_to_toolchain, display_toolchain_info, install_toolchain, list_toolchains,
remove_from_toolchain, run_from_toolchain, uninstall_toolchain, update_toolchain,
use_toolchain,
};
pub use update::{update_project_dependencies, UpdateOptions};
pub use version::display_project_version;

Expand Down
55 changes: 55 additions & 0 deletions crates/huak-package-manager/src/ops/toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::path::PathBuf;

use crate::{Config, HuakResult};

pub fn add_to_toolchain(tool: String, channel: Option<String>, config: &Config) -> HuakResult<()> {
todo!()
}

pub fn display_toolchain_info(channel: Option<String>, config: &Config) -> HuakResult<()> {
todo!()
}

pub fn install_toolchain(
channel: Option<String>,
target: Option<PathBuf>,
config: &Config,
) -> HuakResult<()> {
todo!()
}

pub fn list_toolchains(config: &Config) -> HuakResult<()> {
todo!()
}

pub fn remove_from_toolchain(
tool: String,
channel: Option<String>,
config: &Config,
) -> HuakResult<()> {
todo!()
}

pub fn run_from_toolchain(
tool: String,
channel: Option<String>,
config: &Config,
) -> HuakResult<()> {
todo!()
}

pub fn uninstall_toolchain(channel: Option<String>, config: &Config) -> HuakResult<()> {
todo!()
}

pub fn update_toolchain(
tool: Option<String>,
channel: Option<String>,
config: &Config,
) -> HuakResult<()> {
todo!()
}

pub fn use_toolchain(channel: String, config: &Config) -> HuakResult<()> {
todo!()
}
13 changes: 13 additions & 0 deletions crates/huak-toolchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "huak-toolchain"
version = "0.0.0"
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
huak-python-manager = { path = "../huak-python-manager" }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/huak-toolchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Toolchain

The toolchain implementation for Huak.
116 changes: 116 additions & 0 deletions crates/huak-toolchain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//! # The toolchain implementation for Huak.
//!
//! ## Toolchain
//!
//! - Channel
//! - Path
//! - Tools
//!
//! ## Channels
//!
//! Channels are used to identify toolchains.
//!
//! - major.minor of a Python interpreter
//! - major.minor.patch of a Python interpreter
//! - Complete Python interpreter identifying chains (for example, 'cpython-3.12.0-apple-aarch64-pgo+lto')
//! - Etc.
//!
//! ## Path
//!
//! A unique toolchain is identifiable by the path it's installed to. A directory contains the entire toolchain.
//!
//! ## Tools
//!
//! Toolchains are composed of installed tools. The default tools installed are:
//!
//! - python (and Python installation management system)
//! - ruff
//! - mypy (TODO(cnpryer): May be replaced)
//! - pytest (TODO(cnpryer): May be replaced)
//!
//! ## Other
//!
//! Tools are centralized around a common Python inerpreter installed to the toolchain. The toolchain utilizes
//! a virtual environment shared by the tools in the toolchain. A bin directory contains the symlinked tools.
//! If a platform doesn't support symlinks hardlinks are used.
//!
//! ## `huak-toolchain`
//!
//! This crate implements Huak's toolchain via `Channel`, `Toolchain`, and `Tool`.
use std::path::PathBuf;

const DEFAULT_TOOLS: [&str; 4] = ["python", "ruff", "mypy", "pytest"];

pub struct Toolchain {
inner: ToolchainInner,
}

impl Toolchain {
pub fn new(channel: Channel, path: PathBuf) -> Self {
Toolchain {
inner: ToolchainInner {
channel,
path,
tools: Tools::new(),
},
}
}

pub fn channel(&self) -> &Channel {
&self.inner.channel
}

pub fn path(&self) -> &PathBuf {
&self.inner.path
}
}

impl From<PathBuf> for Toolchain {
fn from(value: PathBuf) -> Self {
todo!()
}
}

struct ToolchainInner {
channel: Channel,
path: PathBuf,
tools: Tools,
}

pub enum Channel {
Latest, // TODO(cnpryer)
Version(Version),
IdentifierChain(String), // TODO(cnpryer): `Parts` or similar
}

struct Tools {
tools: Vec<Tool>,
}

impl Tools {
fn new() -> Self {
Tools {
tools: Vec::with_capacity(DEFAULT_TOOLS.len()),
}
}

fn add(&mut self, tool: Tool) {
todo!()
}

fn remove(&mut self, tool: Tool) {
todo!()
}
}

pub struct Tool {
name: String,
version: Version, // TODO(cnpryer): Use PEP440-compatible struct.
}

pub struct Version {
major: Option<u8>,
minor: Option<u8>,
patch: Option<u8>,
}

0 comments on commit 6137810

Please sign in to comment.