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 5c21339 commit 8a6eaad
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 11 deletions.
11 changes: 11 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
89 changes: 78 additions & 11 deletions crates/huak-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use huak_package_manager::{
Verbosity, WorkspaceOptions,
};
use huak_python_manager::RequestedVersion;
use huak_toolchain::{Channel, Tool};
use std::{env::current_dir, path::PathBuf, process::ExitCode, str::FromStr};
use termcolor::ColorChoice;

Expand Down Expand Up @@ -156,6 +157,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 +195,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: Tool,
/// Add a tool to a specific channel.
#[arg(long, required = false)]
channel: Option<Channel>,
},
/// Display information about a toolchain.
Info {
/// The toolchain channel to display information for.
#[arg(required = false)]
channel: Option<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<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: Tool,
/// Remove a tool from a specific channel.
#[arg(long, required = false)]
channel: Option<Channel>,
},
/// Run a tool installed to a toolchain.
Run {
/// The tool to run.
tool: Tool,
/// The toolchain channel to run a tool from.
#[arg(long, required = false)]
channel: Option<Channel>,
},
/// Uninstall a toolchain.
Uninstall {
/// The toolchain channel to uninstall.
#[arg(required = false)]
channel: Option<Channel>,
},
/// Update the current toolchain.
Update {
/// A tool to update.
#[arg(required = false)]
tool: Option<Tool>, // TODO(cnpryer): Either include @version or add version arg.
/// The toolchain channel to update.
#[arg(long, required = false)]
channel: Option<Channel>,
},
/// Use an available toolchain.
Use {
/// The toolchain channel to use.
channel: Channel,
},
}

Expand Down Expand Up @@ -345,6 +397,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 +527,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
1 change: 1 addition & 0 deletions crates/huak-package-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ toml_edit = "0.19.4"
regex = "1.9.5"
huak-python-manager = { path = "../huak-python-manager" }
huak-home = { path = "../huak-home" }
huak-toolchain = { path = "../huak-toolchain" }

[dev-dependencies]
huak-dev = { path = "../huak-dev" }
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
51 changes: 51 additions & 0 deletions crates/huak-package-manager/src/ops/toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::{Config, HuakResult};
use huak_toolchain::{Channel, Tool};
use std::path::PathBuf;

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

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

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

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

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

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

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

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

pub fn use_toolchain(channel: Channel, config: &Config) -> HuakResult<()> {
todo!()
}
15 changes: 15 additions & 0 deletions crates/huak-toolchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[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" }
pep440_rs.workspace = true
thiserror.workspace = true

[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.
81 changes: 81 additions & 0 deletions crates/huak-toolchain/src/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::{fmt::Display, str::FromStr};

#[derive(Default, Clone, Debug)]
pub enum Channel {
#[default]
Default,
Version(Version),
Descriptor(DescriptorParts),
}

/// Parse `Channel` from strings. This is useful for parsing channel inputs for applications implementing CLI.
impl FromStr for Channel {
type Err = crate::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
todo!()
}
}

// Right now this is just a dynamic struct of `Release` data.
#[derive(Clone, Debug)]
pub struct DescriptorParts {
huak: Option<String>,
kind: Option<String>,
version: Option<Version>,
os: Option<String>,
architecture: Option<String>,
build_configuration: Option<String>,
}

impl Display for DescriptorParts {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Only allocate enough for `DiscriptorParts` data.

Check warning on line 33 in crates/huak-toolchain/src/channel.rs

View workflow job for this annotation

GitHub Actions / Spell check

"Discriptor" should be "Descriptor".
let mut parts = Vec::with_capacity(6);

if let Some(huak) = &self.huak {
parts.push(huak.to_string());
}

if let Some(kind) = &self.kind {
parts.push(kind.to_string());
}

if let Some(version) = &self.version {
parts.push(format!("{}", version));
}

if let Some(os) = &self.os {
parts.push(os.to_string());
}

if let Some(architecture) = &self.architecture {
parts.push(architecture.to_string());
}

if let Some(build_config) = &self.build_configuration {
parts.push(build_config.to_string());
}

write!(f, "{}", parts.join("-"))
}
}

#[derive(Clone, Debug)]
pub struct Version {
major: u8,
minor: u8,
patch: Option<u8>,
}

impl Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}", self.major, self.minor)?;

if let Some(patch) = self.patch {
write!(f, ".{patch}")?;
}

Ok(())
}
}
7 changes: 7 additions & 0 deletions crates/huak-toolchain/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use thiserror::Error as ThisError;

#[derive(ThisError, Debug)]
pub enum Error {
#[error("a problem occurred attempting to parse a channel: {0}")]
ParseChannelError(String),
}
Loading

0 comments on commit 8a6eaad

Please sign in to comment.