Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Huak's Task Table #860

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Commands:
publish Builds and uploads current project to a registry
python Manage Python installations
remove Remove dependencies from the project
run Run a command within the project's environment context
run Run a command with Huak
test Test the project's Python code
update Update the project's dependencies
version Display the version of the project
Expand Down
6 changes: 3 additions & 3 deletions crates/huak-package-manager/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub struct Environment {
impl Environment {
/// Initialize an `Environment`.
#[must_use]
pub fn new() -> Environment {
let interpreters = Environment::resolve_python_interpreters();
pub fn new() -> Self {
let interpreters = Self::resolve_python_interpreters();

Environment { interpreters }
Self { interpreters }
}

/// Get an `Iterator` over the Python `Interpreter` `PathBuf`s found.
Expand Down
4 changes: 4 additions & 0 deletions crates/huak-package-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub enum Error {
InternalError(String),
#[error("a checksum is invalid: {0}")]
InvalidChecksum(String),
#[error("a program is invalid: {0}")]
InvalidProgram(String),
#[error("a run command is invalid: {0}")]
InvalidRunCommand(String),
#[error("a version number could not be parsed: {0}")]
InvalidVersionString(String),
#[error("a problem occurred with json deserialization: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! lish Builds and uploads current project to a registry
//! python Manage Python installations
//! remove Remove dependencies from the project
//! run Run a command within the project's environment context
//! run Run a command with Huak
//! test Test the project's Python code
//! update Update the project's dependencies
//! version Display the version of the project
Expand Down
35 changes: 35 additions & 0 deletions crates/huak-package-manager/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ dev = [
"black ==22.8.0",
"isort ==5.12.0",
]

[tool.huak.task]
string = "python -c 'print(\"string\")'"
array = ["python", "-c", "print('array')"]
inline-cmd = { cmd = "python -c 'print(\"cmd\")'" }
inline-args = { args = ["python", "-c", "print('args')"] }
inline-program = { program = "python", args = ["-c", "print('program')"], env = { TESTING_HUAK = "test"} }
"#
);
}
Expand Down Expand Up @@ -238,6 +245,13 @@ dev = [
"pytest == 7.4.3",
"ruff",
]

[tool.huak.task]
string = "python -c 'print(\"string\")'"
array = ["python", "-c", "print('array')"]
inline-cmd = { cmd = "python -c 'print(\"cmd\")'" }
inline-args = { args = ["python", "-c", "print('args')"] }
inline-program = { program = "python", args = ["-c", "print('program')"], env = { TESTING_HUAK = "test"} }
"#
);
}
Expand Down Expand Up @@ -282,6 +296,13 @@ dev = [
new-group = [
"test2",
]

[tool.huak.task]
string = "python -c 'print(\"string\")'"
array = ["python", "-c", "print('array')"]
inline-cmd = { cmd = "python -c 'print(\"cmd\")'" }
inline-args = { args = ["python", "-c", "print('args')"] }
inline-program = { program = "python", args = ["-c", "print('program')"], env = { TESTING_HUAK = "test"} }
"#
);
}
Expand Down Expand Up @@ -317,6 +338,13 @@ dev = [
"pytest == 7.4.3",
"ruff",
]

[tool.huak.task]
string = "python -c 'print(\"string\")'"
array = ["python", "-c", "print('array')"]
inline-cmd = { cmd = "python -c 'print(\"cmd\")'" }
inline-args = { args = ["python", "-c", "print('args')"] }
inline-program = { program = "python", args = ["-c", "print('program')"], env = { TESTING_HUAK = "test"} }
"#
);
}
Expand Down Expand Up @@ -353,6 +381,13 @@ email = "[email protected]"
dev = [
"pytest == 7.4.3",
]

[tool.huak.task]
string = "python -c 'print(\"string\")'"
array = ["python", "-c", "print('array')"]
inline-cmd = { cmd = "python -c 'print(\"cmd\")'" }
inline-args = { args = ["python", "-c", "print('args')"] }
inline-program = { program = "python", args = ["-c", "print('program')"], env = { TESTING_HUAK = "test"} }
"#
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/huak-package-manager/src/ops/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::make_venv_command;
use super::add_venv_to_command;
use crate::{Config, Dependency, HuakResult, InstallOptions};
use std::{process::Command, str::FromStr};

Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn build_project(config: &Config, options: &BuildOptions) -> HuakResult<()>
if let Some(it) = options.values.as_ref() {
args.extend(it.iter().map(std::string::String::as_str));
}
make_venv_command(&mut cmd, &python_env)?;
add_venv_to_command(&mut cmd, &python_env)?;
cmd.args(args).current_dir(workspace.root());

config.terminal().run_command(&mut cmd)
Expand Down
7 changes: 4 additions & 3 deletions crates/huak-package-manager/src/ops/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::make_venv_command;
use crate::{Config, Dependency, HuakResult, InstallOptions};
use std::{process::Command, str::FromStr};

use super::add_venv_to_command;

pub struct FormatOptions {
/// A values vector of format options typically used for passing on arguments.
pub values: Option<Vec<String>>,
Expand Down Expand Up @@ -56,8 +57,8 @@ pub fn format_project(config: &Config, options: &FormatOptions) -> HuakResult<()
let mut cmd = Command::new(python_env.python_path());
let mut ruff_cmd = Command::new(python_env.python_path());
let mut ruff_args = vec!["-m", "ruff", "check", ".", "--select", "I", "--fix"];
make_venv_command(&mut cmd, &python_env)?;
make_venv_command(&mut ruff_cmd, &python_env)?;
add_venv_to_command(&mut cmd, &python_env)?;
add_venv_to_command(&mut ruff_cmd, &python_env)?;
let mut args = vec!["-m", "ruff", "format", "."];
if let Some(v) = options.values.as_ref() {
args.extend(v.iter().map(String::as_str));
Expand Down
6 changes: 3 additions & 3 deletions crates/huak-package-manager/src/ops/lint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::make_venv_command;
use super::add_venv_to_command;
use crate::{Config, Dependency, HuakResult, InstallOptions};
use std::{process::Command, str::FromStr};

Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn lint_project(config: &Config, options: &LintOptions) -> HuakResult<()> {

// Run `mypy` excluding the workspace's Python environment directory.
let mut mypy_cmd = Command::new(python_env.python_path());
make_venv_command(&mut mypy_cmd, &python_env)?;
add_venv_to_command(&mut mypy_cmd, &python_env)?;
mypy_cmd
.args(vec!["-m", "mypy", ".", "--exclude", &python_env.name()?])
.current_dir(workspace.root());
Expand All @@ -48,7 +48,7 @@ pub fn lint_project(config: &Config, options: &LintOptions) -> HuakResult<()> {
if let Some(v) = options.values.as_ref() {
args.extend(v.iter().map(String::as_str));
}
make_venv_command(&mut cmd, &python_env)?;
add_venv_to_command(&mut cmd, &python_env)?;
cmd.args(args).current_dir(workspace.root());
terminal.run_command(&mut cmd)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if __name__ == "__main__":
/// `PATH` environment variable.
/// - Adds `VIRTUAL_ENV` environment variable to the command pointing at the virtual environment's
/// root.
fn make_venv_command(cmd: &mut Command, venv: &PythonEnvironment) -> HuakResult<()> {
fn add_venv_to_command(cmd: &mut Command, venv: &PythonEnvironment) -> HuakResult<()> {
let mut paths = env_path_values().unwrap_or_default();

paths.insert(0, venv.executables_dir_path().clone());
Expand Down
4 changes: 2 additions & 2 deletions crates/huak-package-manager/src/ops/publish.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::make_venv_command;
use super::add_venv_to_command;
use crate::{Config, Dependency, HuakResult, InstallOptions};
use std::{process::Command, str::FromStr};

Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn publish_project(config: &Config, options: &PublishOptions) -> HuakResult<
if let Some(v) = options.values.as_ref() {
args.extend(v.iter().map(String::as_str));
}
make_venv_command(&mut cmd, &python_env)?;
add_venv_to_command(&mut cmd, &python_env)?;
cmd.args(args).current_dir(workspace.root());
config.terminal().run_command(&mut cmd)
}
Loading
Loading