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 bound-options #81

Merged
merged 9 commits into from
Nov 11, 2024
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ repos:

- Description: Validate if packages conform to a specified validation target.
- Options
- `--bound, -b <FILE>`: Path to the file containing bound requirements.
- `--bound, -b <FILE>`: Path or URL to the file containing bound requirements.
- `--bound-options <OPTIONS>`: Names of additional optional dependency groups.
- `--subset`: Allow the observed packages to be a subset of the bound requirements.
- `--superset`: Allow the observed packages to be a superset of the bound requirements.
- Subcommands
Expand Down Expand Up @@ -317,7 +318,8 @@ repos:

- Description: Purge packages that are invalid based on dependency specification.
- Options
- `--bound, -b <FILE>`: Path to the file containing bound requirements.
- `--bound, -b <FILE>`: Path or URL to the file containing bound requirements.
- `--bound-options <OPTIONS>`: Names of additional optional dependency groups.
- `--subset`: Allow the observed packages to be a subset of the bound requirements.
- `--superset`: Allow the observed packages to be a superset of the bound requirements.

Expand Down
29 changes: 21 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ enum Commands {
},
/// Validate if packages conform to a validation target.
Validate {
/// File path from which to read bound requirements.
/// File path or URL from which to read bound requirements.
#[arg(short, long, value_name = "FILE")]
bound: PathBuf,

/// Names of additional optional dependency groups.
#[arg(long, value_name = "OPTIONS")]
bound_options: Option<Vec<String>>,

/// If the subset flag is set, the observed packages can be a subset of the bound requirements.
#[arg(long)]
subset: bool,
Expand Down Expand Up @@ -190,10 +194,14 @@ enum Commands {
},
/// Purge packages that are invalid based on dependency specification.
PurgeInvalid {
/// File path from which to read bound requirements.
/// File path or URL from which to read bound requirements.
#[arg(short, long, value_name = "FILE")]
bound: PathBuf,

/// Names of additional optional dependency groups.
#[arg(long, value_name = "OPTIONS")]
bound_options: Option<Vec<String>>,

/// If the subset flag is set, the observed packages can be a subset of the bound requirements.
#[arg(long)]
subset: bool,
Expand Down Expand Up @@ -339,17 +347,20 @@ fn get_scan(
}

// Given a Path, load a DepManifest. This might branch by extension to handle pyproject.toml and other formats.
fn get_dep_manifest(bound: &PathBuf) -> Result<DepManifest, Box<dyn std::error::Error>> {
fn get_dep_manifest(
bound: &PathBuf,
bound_options: Option<&Vec<String>>,
) -> Result<DepManifest, Box<dyn std::error::Error>> {
if bound.to_str().map_or(false, |s| s.ends_with(".git")) {
DepManifest::from_git_repo(bound)
DepManifest::from_git_repo(bound, bound_options)
} else if bound
.to_str()
.map_or(false, |s| s.ends_with("pyproject.toml"))
{
DepManifest::from_pyproject_file(bound)
DepManifest::from_pyproject_file(bound, bound_options)
} else if bound.to_str().map_or(false, |s| s.starts_with("http")) {
// might have URL based requirements or pyproject
DepManifest::from_url(&UreqClientLive, bound)
DepManifest::from_url(&UreqClientLive, bound, bound_options)
} else {
// assume all text files are requirements-style
let fp = path_normalize(bound).unwrap_or_else(|_| bound.clone());
Expand Down Expand Up @@ -431,11 +442,12 @@ where
},
Some(Commands::Validate {
bound,
bound_options,
subset,
superset,
subcommands,
}) => {
let dm = get_dep_manifest(bound)?;
let dm = get_dep_manifest(bound, bound_options.as_ref())?;
let permit_superset = *superset;
let permit_subset = *subset;
let vr = sfs.to_validation_report(
Expand Down Expand Up @@ -527,10 +539,11 @@ where
}
Some(Commands::PurgeInvalid {
bound,
bound_options,
subset,
superset,
}) => {
let dm = get_dep_manifest(bound)?;
let dm = get_dep_manifest(bound, bound_options.as_ref())?;
let permit_superset = *superset;
let permit_subset = *subset;
let _ = sfs.to_purge_invalid(
Expand Down
Loading