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

More intelligently perform operations based on the pyproject.toml #517

Merged
merged 1 commit into from
Mar 28, 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
20 changes: 10 additions & 10 deletions src/bin/huak/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ fn add(
group: Option<String>,
operation_config: OperationConfig,
) -> HuakResult<()> {
let deps: Vec<&str> =
dependencies.iter().map(|item| item.as_str()).collect();
match group.as_ref() {
Some(it) => {
ops::add_project_optional_dependencies(&deps, it, &operation_config)
}
None => ops::add_project_dependencies(&deps, &operation_config),
Some(it) => ops::add_project_optional_dependencies(
&dependencies,
it,
&operation_config,
),
None => ops::add_project_dependencies(&dependencies, &operation_config),
}
}

Expand Down Expand Up @@ -384,15 +384,15 @@ fn remove(
group: Option<String>,
operation_config: OperationConfig,
) -> HuakResult<()> {
let deps: Vec<&str> =
dependencies.iter().map(|item| item.as_str()).collect();
match group.as_ref() {
Some(it) => ops::remove_project_optional_dependencies(
&deps,
&dependencies,
it,
&operation_config,
),
None => ops::remove_project_dependencies(&deps, &operation_config),
None => {
ops::remove_project_dependencies(&dependencies, &operation_config)
}
}
}

Expand Down
20 changes: 15 additions & 5 deletions src/huak/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,28 @@ impl Project {
}

/// Add a Python package as a dependency to the project's manifest file.
pub fn add_dependency(&mut self, package_str: &str) {
self.pyproject_toml.add_dependency(package_str);
pub fn add_dependency(&mut self, package_str: &str) -> HuakResult<()> {
if !self.contains_dependency(package_str)?
&& !self.contains_optional_dependency(package_str)?
{
self.pyproject_toml.add_dependency(package_str);
}
Ok(())
}

/// Add a Python package as a dependency to the project' project file.
pub fn add_optional_dependency(
&mut self,
package_str: &str,
group_name: &str,
) {
self.pyproject_toml
.add_optional_dependency(package_str, group_name)
) -> HuakResult<()> {
if !self.contains_dependency(package_str)?
&& !self.contains_optional_dependency(package_str)?
{
self.pyproject_toml
.add_optional_dependency(package_str, group_name)
}
Ok(())
}

/// Remove a dependency from the project's manifest file.
Expand Down
Loading