Skip to content

Commit

Permalink
Macro declarations after comments (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer authored Oct 29, 2023
1 parent 0ce09c6 commit 7582ce7
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 47 deletions.
20 changes: 20 additions & 0 deletions crates/huak-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ 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,
},
/// Install a toolchain.
Install {
/// The version of Python to install.
#[arg(required = true)]
version: RequestedVersion,
/// The path to install a toolchain to.
target: PathBuf,
},
}

// Command gating for Huak.
impl Cli {
pub fn run(self) -> CliResult<i32> {
Expand Down
2 changes: 1 addition & 1 deletion crates/huak-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::process::{exit, ExitCode};

mod error;

#[must_use]
/// Launch Huak's cli process.
#[must_use]
pub fn main() -> ExitCode {
setup_panic!();

Expand Down
2 changes: 1 addition & 1 deletion crates/huak-home/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::PathBuf;

#[must_use]
/// Huak's home directory is located at ~/.huak.
///
/// # Unix
Expand All @@ -10,6 +9,7 @@ use std::path::PathBuf;
/// # Windows
///
/// On windows the `USERPROFILE` environment variable is used if it exists.
#[must_use]
pub fn huak_home_dir() -> Option<PathBuf> {
home_dir().map(|p| p.join(".huak"))
}
Expand Down
8 changes: 4 additions & 4 deletions crates/huak-package-manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::path::PathBuf;

use crate::{sys::Terminal, workspace::Workspace, TerminalOptions};

#[derive(Clone, Default)]
/// The main `Config` for Huak.
///
/// The `Config` contains data telling Huak what to do at times.
Expand All @@ -22,6 +21,7 @@ use crate::{sys::Terminal, workspace::Workspace, TerminalOptions};
///
/// let workspace = config.workspace();
/// ```
#[derive(Clone, Default)]
pub struct Config {
/// The configured `Workspace` root path.
pub workspace_root: PathBuf,
Expand All @@ -32,20 +32,20 @@ pub struct Config {
}

impl Config {
#[must_use]
/// Resolve the current `Workspace` based on the `Config` data.
#[must_use]
pub fn workspace(&self) -> Workspace {
Workspace::new(&self.workspace_root, self)
}

#[must_use]
/// Get a `Terminal` based on the `Config` data.
#[must_use]
pub fn terminal(&self) -> Terminal {
Terminal::from_options(self.terminal_options.clone())
}

#[must_use]
/// Get a `Config` with a new `Terminal`.
#[must_use]
pub fn with_terminal(self, terminal_options: TerminalOptions) -> Self {
Config {
workspace_root: self.workspace_root,
Expand Down
6 changes: 3 additions & 3 deletions crates/huak-package-manager/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use pep508_rs::{Requirement, VersionOrUrl};

use crate::Error;

#[derive(Clone, Debug)]
/// The `Dependency` is an abstraction for `Package` data used as a cheap alternative
/// for operations on lots of `Package` data.
///
Expand All @@ -17,11 +16,12 @@ use crate::Error;
///
/// let dependency = Dependency::from_str("my-dependency >= 0.1.0, < 0.2.0").unwrap();
/// ```
#[derive(Clone, Debug)]
pub struct Dependency(Requirement);

impl Dependency {
#[must_use]
/// Get a reference to the wrapped `Requirement`.
#[must_use]
pub fn requirement(&self) -> &Requirement {
&self.0
}
Expand All @@ -31,8 +31,8 @@ impl Dependency {
&mut self.0
}

#[must_use]
/// Get the `Dependency` name.
#[must_use]
pub fn name(&self) -> &str {
&self.requirement().name
}
Expand Down
10 changes: 5 additions & 5 deletions crates/huak-package-manager/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct Environment {
}

impl Environment {
#[must_use]
/// Initialize an `Environment`.
#[must_use]
pub fn new() -> Environment {
let interpreters = Environment::resolve_python_interpreters();

Expand All @@ -38,8 +38,8 @@ impl Environment {
.map(Interpreter::path)
}

#[must_use]
/// Resolve `Interpreters` for the `Environment`.
#[must_use]
pub fn resolve_python_interpreters() -> Interpreters {
// Note that we filter out any interpreters we can't establish a `Version` for.
let interpreters = python_paths().filter_map(|(version, path)| {
Expand All @@ -57,8 +57,8 @@ impl Environment {
Interpreters::new(interpreters)
}

#[must_use]
/// Get a reference to the environment's resolved Python interpreters.
#[must_use]
pub fn interpreters(&self) -> &Interpreters {
&self.interpreters
}
Expand All @@ -70,8 +70,8 @@ impl Default for Environment {
}
}

#[must_use]
/// Get a vector of paths from the system `PATH` environment variable.
#[must_use]
pub fn env_path_values() -> Option<Vec<PathBuf>> {
if let Some(val) = env_path_string() {
return Some(std::env::split_paths(&val).collect());
Expand All @@ -80,8 +80,8 @@ pub fn env_path_values() -> Option<Vec<PathBuf>> {
None
}

#[must_use]
/// Get the `OsString` value of the enrionment variable `PATH`.
#[must_use]
pub fn env_path_string() -> Option<OsString> {
std::env::var_os("PATH")
}
8 changes: 4 additions & 4 deletions crates/huak-package-manager/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::{dependency::Dependency, Error, HuakResult};

const DEFAULT_METADATA_FILE_NAME: &str = "pyproject.toml";

#[derive(Debug)]
/// A `LocalMetadata` struct used to manage local `Metadata` files such as
/// the pyproject.toml (<https://peps.python.org/pep-0621/>).
#[derive(Debug)]
pub struct LocalMetadata {
/// The core `Metadata`.
/// See https://packaging.python.org/en/latest/specifications/core-metadata/.
Expand Down Expand Up @@ -55,8 +55,8 @@ impl LocalMetadata {
}
}

#[must_use]
/// Get a reference to the core `Metadata`.
#[must_use]
pub fn metadata(&self) -> &Metadata {
&self.metadata
}
Expand Down Expand Up @@ -111,11 +111,11 @@ fn pyproject_toml_metadata<T: Into<PathBuf>>(path: T) -> HuakResult<LocalMetadat
Ok(local_metadata)
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
/// The `Metadata` of a `Package`.
///
/// See <https://peps.python.org/pep-0621/> for more about core metadata.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Metadata {
/// The build system used for the `Package`.
build_system: BuildSystem,
Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/ops/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub fn use_python(version: &str, config: &Config) -> HuakResult<()> {
let interpreters = Environment::resolve_python_interpreters();

// TODO(cnpryer): Re-export `Interpreter` as public
#[allow(clippy::redundant_closure_for_method_calls)]
// Get a path to an interpreter based on the version provided, excluding any activated Python environment.
#[allow(clippy::redundant_closure_for_method_calls)]
let Some(path) = interpreters
.interpreters()
.iter()
Expand Down
12 changes: 6 additions & 6 deletions crates/huak-package-manager/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{fmt::Display, str::FromStr};

const VERSION_OPERATOR_CHARACTERS: [char; 5] = ['=', '~', '!', '>', '<'];

#[derive(Clone)]
/// The `Package` contains data about a Python `Package`.
///
/// A `Package` contains information like the project's name, its version, authors,
Expand All @@ -19,6 +18,7 @@ const VERSION_OPERATOR_CHARACTERS: [char; 5] = ['=', '~', '!', '>', '<'];
///
/// assert_eq!(package.version, Version::from_str("0.0.1").unwrap()));
/// ```
#[derive(Clone)]
pub struct Package {
/// Information used to identify the `Package`.
id: PackageId,
Expand All @@ -27,33 +27,33 @@ pub struct Package {
}

impl Package {
#[must_use]
/// Get a reference to the `Package`'s name.
#[must_use]
pub fn name(&self) -> &str {
&self.id.name
}

#[must_use]
/// Get a reference to the PEP 440 `Version` of the `Package`.
#[must_use]
pub fn version(&self) -> &Version {
&self.id.version
}

#[must_use]
/// Get a reference to the `Package`'s core `Metadata`.
#[must_use]
pub fn metadata(&self) -> &Metadata {
&self.metadata
}

// TODO: I want this implemented with `FromStr`.
#[allow(clippy::should_implement_trait)]
/// Initialize a `Package` from a `&str`.
///
/// ```
/// use huak_package_manager::Package;
///
/// let package = Package::from_str("my-package == 0.0.1").unwrap();
/// ```
#[allow(clippy::should_implement_trait)]
pub fn from_str<T: AsRef<str>>(s: T) -> HuakResult<Package> {
// A naive approach to parsing the name and `VersionSpecifiers` from the `&str`.
// Find the first character of the `VersionSpecifiers`. Everything prior is considered
Expand Down Expand Up @@ -137,8 +137,8 @@ impl PartialEq for Package {

impl Eq for Package {}

#[derive(Clone)]
/// The `PackageId` struct is used to contain `Package`-identifying data.
#[derive(Clone)]
struct PackageId {
/// The `Package` name.
name: String,
Expand Down
Loading

0 comments on commit 7582ce7

Please sign in to comment.