Skip to content

Commit

Permalink
Add home to Config (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer authored Nov 3, 2023
1 parent 6ab6e36 commit 2557377
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/huak-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ fn get_config(cwd: PathBuf, cli: &Cli) -> Config {
workspace_root,
cwd,
terminal_options,
home: huak_home_dir(),
};
if cli.no_color {
config.terminal_options = TerminalOptions {
Expand Down
18 changes: 17 additions & 1 deletion crates/huak-package-manager/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::PathBuf;

use huak_home::huak_home_dir;

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

/// The main `Config` for Huak.
Expand All @@ -21,14 +23,16 @@ use crate::{sys::Terminal, workspace::Workspace, TerminalOptions};
///
/// let workspace = config.workspace();
/// ```
#[derive(Clone, Default)]
#[derive(Clone)]
pub struct Config {
/// The configured `Workspace` root path.
pub workspace_root: PathBuf,
/// The current working directory.
pub cwd: PathBuf,
/// `Terminal` options to use.
pub terminal_options: TerminalOptions,
/// Huak's home directory.
pub home: Option<PathBuf>,
}

impl Config {
Expand All @@ -51,6 +55,18 @@ impl Config {
workspace_root: self.workspace_root,
cwd: self.cwd,
terminal_options,
..Default::default()
}
}
}

impl Default for Config {
fn default() -> Self {
Self {
workspace_root: PathBuf::default(),
cwd: PathBuf::default(),
terminal_options: TerminalOptions::default(),
home: huak_home_dir(),
}
}
}
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
let venv = ws.resolve_python_environment().unwrap();
Expand Down Expand Up @@ -162,6 +163,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = CleanOptions {
include_pycache: true,
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = WorkspaceOptions { uses_git: false };
init_lib_project(&config, &options).unwrap();
Expand Down Expand Up @@ -84,6 +85,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = WorkspaceOptions { uses_git: false };

Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down Expand Up @@ -118,6 +119,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = LintOptions {
values: None,
Expand Down Expand Up @@ -134,6 +135,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = WorkspaceOptions { uses_git: false };

Expand Down Expand Up @@ -125,6 +126,7 @@ def test_version():
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = WorkspaceOptions { uses_git: false };

Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};

use_python(&version, &config).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = RemoveOptions {
install_options: InstallOptions { values: None },
Expand Down Expand Up @@ -124,6 +125,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let options = RemoveOptions {
install_options: InstallOptions { values: None },
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
// For some reason this test fails with multiple threads used. Workspace.resolve_python_environment()
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/ops/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/huak-package-manager/src/ops/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down Expand Up @@ -133,6 +134,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/huak-package-manager/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ mod tests {
workspace_root,
cwd,
terminal_options,
..Default::default()
};
let ws = config.workspace();
let venv = ws.resolve_python_environment().unwrap();
Expand Down

0 comments on commit 2557377

Please sign in to comment.