Skip to content

Commit

Permalink
Add huak-toolchain (789)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Nov 6, 2023
1 parent dce3350 commit 3b8a59e
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 200 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/huak-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "huak"
version = "0.0.19"
version = "0.0.19-alpha1"
description = "A Python package manager written in Rust and inspired by Cargo."
repository = "https://github.com/cnpryer/huak.git"
homepage = "https://github.com/cnpryer/huak.git"
Expand Down
3 changes: 2 additions & 1 deletion crates/huak-cli/tests/snapshots/r#mod__tests__help-2.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/huak_cli/tests/mod.rs
source: crates/huak-cli/tests/mod.rs
info:
program: huak
args:
Expand Down Expand Up @@ -29,6 +29,7 @@ Commands:
remove Remove dependencies from the project
run Run a command within the project's environment context
test Test the project's Python code
toolchain Manage toolchains
update Update the project's dependencies
version Display the version of the project
help Print this message or the help of the given subcommand(s)
Expand Down
3 changes: 2 additions & 1 deletion crates/huak-cli/tests/snapshots/r#mod__tests__help.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/huak_cli/tests/mod.rs
source: crates/huak-cli/tests/mod.rs
info:
program: huak
args:
Expand Down Expand Up @@ -29,6 +29,7 @@ Commands:
remove Remove dependencies from the project
run Run a command within the project's environment context
test Test the project's Python code
toolchain Manage toolchains
update Update the project's dependencies
version Display the version of the project
help Print this message or the help of the given subcommand(s)
Expand Down
4 changes: 2 additions & 2 deletions crates/huak-package-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub enum Error {
#[error("a problem occurred resolving huak's home directory")]
HuakHomeNotFound,
#[error("a toolchain cannot be found")]
HuakToolchainNotFound,
ToolchainNotFound,
#[error("{0}")] // See TODO note above.
HuakToolchainError(#[from] huak_toolchain::Error),
ToolchainError(#[from] huak_toolchain::Error),
#[error("a toolchain already exists: {0}")]
LocalToolchainExists(PathBuf),
#[error("a problem with huak's internals occurred: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/ops/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn install(path: PathBuf, channel: Channel, config: &Config) -> HuakResult<()> {
.is_err()
{
if let Err(e) = toolchain.register_tool_from_path(&path, "python", true) {
return Err(Error::HuakToolchainError(e));
return Err(Error::ToolchainError(e));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Workspace {
/// 3. ~/.huak/settings.toml configuration
pub fn resolve_local_toolchain(&self, channel: Option<&Channel>) -> HuakResult<LocalToolchain> {
let Some(it) = resolve_local_toolchain(self, channel) else {
return Err(Error::HuakToolchainNotFound);
return Err(Error::ToolchainNotFound);
};

Ok(it)
Expand Down
10 changes: 3 additions & 7 deletions crates/huak-python-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,28 @@
//!
//! ```no_run
//! use std::{str::FromStr, path::PathBuf};
//! use huak_python_manager::{Options, RequestedVersion, Strategy, install_with_target, resolve_release};
//!
//!
//! // The version of the Python to install.
//! let version = RequestedVersion::from_str("3.12").unwrap();
//! use huak_python_manager::{ReleaseOptions, Strategy, install_with_target, resolve_release};
//!
//! // Target directory to install Python to.
//! let target = PathBuf::from("...");
//!
//! // Use selection strategy to resolve for the best matching release available.
//! let strategy = Strategy::Selection(Options { version: Some(version), kind: "cpython", os: "apple", architecture: "aarch64", build_configuration: "pgo+lto"});
//! let strategy = Strategy::Selection(ReleaseOptions::default());
//!
//! let release = resolve_release(&strategy).unwrap();
//!
//! install_with_target(&release, target).unwrap();
//! ```
pub use crate::error::Error;
pub use crate::install::install_with_target;
pub use crate::resolve::{
release_options_from_requested_version, resolve_release, ReleaseArchitecture,
ReleaseBuildConfiguration, ReleaseKind, ReleaseOption, ReleaseOptions, ReleaseOs,
RequestedVersion, Strategy,
};
pub use crate::version::Version;
use install::download_release;
pub use install::install_with_target;
pub use releases::Release;
use std::path::Path;
use tar::Archive;
Expand Down
12 changes: 11 additions & 1 deletion crates/huak-toolchain/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Toolchain

The toolchain implementation for Huak.
The toolchain implementation for Huak.

This crate is a work-in-progress.

## Usage

**This crate is designed to be used by Huak.** Install a toolchain to ~/.huak/toolchains.

```
huak toolchain install <channel>
```
170 changes: 0 additions & 170 deletions crates/huak-toolchain/src/install.rs

This file was deleted.

39 changes: 30 additions & 9 deletions crates/huak-toolchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@
//! Local tools can be executable programs.
//!
//! ```rust
//! use huak_toolchain::prelude::*;
//! use huak_toolchain::LocalToolchain;
//! use std::path::PathBuf;
//!
//! let path = PathBuff::new("path/to/toolchain/");
//! let toolchain = LocalToolchain::new(path)?;
//! let path = PathBuf::from("path/to/toolchain/");
//! let toolchain = LocalToolchain::new(&path);
//! let py = toolchain.tool("python");
//! let bin = path.join("bin");
//! let py_bin = bin.join("python");
//!
//! assert_eq!(py.name, "python");
//! assert_eq!(py.path, path.join("bin").join("python"))
//! assert_eq!(&py.name, "python");
//! assert_eq!(py.path, py_bin);
//! ```
//!
//! Use `toolchain.try_with_proxy_tool(tool)` to attempt to create a proxy file installed to the toolchain.
Expand All @@ -66,14 +69,15 @@
//! may contain full copies of executable programs or proxies to them.
//!
//! ```
//!
//! ```
//! export PATH="/path/to/toolchain/bin/:$PATH"
//! ```
pub use channel::{Channel, DescriptorParts};
pub use error::Error;
pub use install::install_toolchain_with_target;
use path::name_from_path;
pub use resolve::{Entry, LocalToolchainResolver};
pub use resolve::LocalToolchainResolver;
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
Expand All @@ -86,7 +90,6 @@ pub use tools::LocalTool;

mod channel;
mod error;
mod install;
mod path;
mod resolve;
mod tools;
Expand All @@ -96,7 +99,25 @@ pub struct LocalToolchain {
inner: LocalToolchainInner,
}

// TODO(cnpryer): Teardown
/// The local toolchain for Huak.
///
/// A local toolchain is created for different channels. The channel determines its
/// release installs and its path.
///
/// A `LocalToolchain` is meant to be used as an API for toolchain management on some
/// filesystem.
///
/// ```rust
/// use std::path::PathBuf;
/// use huak_toolchain::LocalToolchain;
///
///
/// let root = PathBuf::new();
/// let toolchain = LocalToolchain::new(&root);
///
/// assert_eq!(toolchain.root(), &root);
/// assert_eq!(toolchain.bin(), root.join("bin"));
/// ```
impl LocalToolchain {
pub fn new<T: Into<PathBuf>>(path: T) -> Self {
let path = path.into();
Expand Down
Loading

0 comments on commit 3b8a59e

Please sign in to comment.