Skip to content

Commit 778d37f

Browse files
Merge pull request science-computing#450 from primeos-work/rework-and-improve-package-version-constraints
Rework and improve the code around package version and package version constraints
2 parents f7c68cb + 4fb877a commit 778d37f

File tree

20 files changed

+285
-124
lines changed

20 files changed

+285
-124
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ reqwest = { version = "0.12", features = [ "stream" ] }
6060
resiter = "0.5"
6161
rlimit = "0.10"
6262
rustversion = "1"
63+
semver = "1"
6364
serde = "1"
6465
serde_json = "1"
6566
sha1 = "0.10"

src/cli.rs

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn cli() -> Command {
4747
.long("package")
4848
.short('p')
4949
.value_name("PKG")
50-
.help("Only list releases for package PKG"),
50+
.help("List only releases for package PKG"),
5151
)
5252
.arg(
5353
Arg::new("limit")
@@ -412,7 +412,7 @@ pub fn cli() -> Command {
412412
.required(true)
413413
.index(1)
414414
.value_name("UUID")
415-
.help("The id of the Job")
415+
.help("The job to print the log of")
416416
.value_parser(uuid::Uuid::parse_str)
417417
)
418418
)
@@ -579,11 +579,11 @@ pub fn cli() -> Command {
579579
.value_name("PACKAGE_NAME")
580580
.help("The name of the package")
581581
)
582-
.arg(Arg::new("package_version_constraint")
582+
.arg(Arg::new("package_version")
583583
.required(true)
584584
.index(2)
585-
.value_name("VERSION_CONSTRAINT")
586-
.help("A version constraint to search for (optional), e.g., '=1.0.0'")
585+
.value_name("PACKAGE_VERSION")
586+
.help("The version of the package")
587587
)
588588
)
589589

@@ -599,7 +599,7 @@ pub fn cli() -> Command {
599599
.required(false)
600600
.index(2)
601601
.value_name("VERSION_CONSTRAINT")
602-
.help("A version constraint to search for (optional), e.g., '=1.0.0'")
602+
.help("A version constraint to match the package version against (optional), e.g., '=1.0.0'")
603603
)
604604
.arg(Arg::new("no_script_filter")
605605
.action(ArgAction::SetTrue)
@@ -645,7 +645,7 @@ pub fn cli() -> Command {
645645
.required(false)
646646
.index(2)
647647
.value_name("VERSION_CONSTRAINT")
648-
.help("A version constraint to search for (optional), e.g., '=1.0.0'")
648+
.help("A version constraint to match the package version against (optional), e.g., '=1.0.0'")
649649
)
650650

651651
.arg(Arg::new("terse")
@@ -766,11 +766,11 @@ pub fn cli() -> Command {
766766
.value_name("PKG")
767767
.help("Verify the sources of this package (optional, if left out, all packages are checked)")
768768
)
769-
.arg(Arg::new("package_version")
769+
.arg(Arg::new("package_version_constraint")
770770
.required(false)
771771
.index(2)
772-
.value_name("VERSION")
773-
.help("Verify the sources of this package version (optional, if left out, all packages are checked)")
772+
.value_name("VERSION_CONSTRAINT")
773+
.help("Verify the sources of matching package versions (optional, if left out, all versions are checked)")
774774
)
775775

776776
.arg(Arg::new("matching")
@@ -794,13 +794,13 @@ pub fn cli() -> Command {
794794
.required(false)
795795
.index(1)
796796
.value_name("PKG")
797-
.help("Verify the sources of this package (optional, if left out, all packages are checked)")
797+
.help("Show the URL of this package (or all packages, if omitted)")
798798
)
799-
.arg(Arg::new("package_version")
799+
.arg(Arg::new("package_version_constraint")
800800
.required(false)
801801
.index(2)
802-
.value_name("VERSION")
803-
.help("Verify the sources of this package version (optional, if left out, all packages are checked)")
802+
.value_name("VERSION_CONSTRAINT")
803+
.help("Show the URLs of matching package versions (or all versions, if omitted)")
804804
)
805805
)
806806
.subcommand(Command::new("download")
@@ -811,24 +811,24 @@ pub fn cli() -> Command {
811811
.value_name("PKG")
812812
.help("Download the sources of this package")
813813
)
814-
.arg(Arg::new("package_version")
814+
.arg(Arg::new("package_version_constraint")
815815
.required(false)
816816
.index(2)
817817
.value_name("VERSION_CONSTRAINT")
818-
.help("Download the sources of this package version (optional, if left out, all packages are downloaded)")
818+
.help("Download the sources of matching package versions (optional, if left out, all versions are downloaded)")
819819
)
820820
.arg(Arg::new("force")
821821
.action(ArgAction::SetTrue)
822822
.required(false)
823823
.long("force")
824-
.help("Overwrite existing cache entry")
824+
.help("Overwrite existing cache entry (the downloaded source file(s) will be deleted before the re-download starts)")
825825
)
826826

827827
.arg(Arg::new("matching")
828828
.required(false)
829829
.long("matching")
830830
.value_name("REGEX")
831-
.help("Download all packages matching a regex with their name")
831+
.help("Download all packages where the package name matches REGEX")
832832
)
833833

834834
.group(ArgGroup::new("download-one-or-many")
@@ -850,13 +850,13 @@ pub fn cli() -> Command {
850850
.required(false)
851851
.index(1)
852852
.value_name("PKG")
853-
.help("Get the source file paths for this package")
853+
.help("Get the source file paths for this package (or all packages, if omitted)")
854854
)
855-
.arg(Arg::new("package_version")
855+
.arg(Arg::new("package_version_constraint")
856856
.required(false)
857857
.index(2)
858-
.value_name("VERSION")
859-
.help("Get the source file paths for the package in this version")
858+
.value_name("VERSION_CONSTRAINT")
859+
.help("Get the source file paths for the package in matching versions (or all versions, if omitted)")
860860
)
861861
)
862862
)
@@ -880,15 +880,15 @@ pub fn cli() -> Command {
880880
)
881881

882882
.arg(Arg::new("package_name")
883-
.required(false)
883+
.required(true)
884884
.index(1)
885885
.value_name("PKG")
886886
.help("The name of the package")
887887
.requires("package_version")
888888
)
889889

890890
.arg(Arg::new("package_version")
891-
.required(false)
891+
.required(true)
892892
.index(2)
893893
.value_name("VERSION")
894894
.help("The exact version of the package (string match)")
@@ -902,7 +902,7 @@ pub fn cli() -> Command {
902902
.required(true)
903903
.index(1)
904904
.value_name("SUBMIT")
905-
.help("The submit uuid from which to release a package")
905+
.help("The submit UUID from which to release a package")
906906
.value_parser(uuid::Uuid::parse_str)
907907
)
908908
.arg(Arg::new("release_store_name")
@@ -919,18 +919,7 @@ pub fn cli() -> Command {
919919
.required(false)
920920
.index(2)
921921
.value_name("PKG")
922-
.help("The name of the package")
923-
.conflicts_with("all-packages")
924-
)
925-
.arg(Arg::new("all-packages")
926-
.required(false)
927-
.long("all")
928-
.help("Release all packages")
929-
.conflicts_with("package_name")
930-
)
931-
.group(ArgGroup::new("package")
932-
.args(["package_name", "all-packages"])
933-
.required(true) // one of these is required
922+
.help("The name of the package (or, if omitted, release all packages of the submit)")
934923
)
935924
.arg(Arg::new("package_version")
936925
.required(false)
@@ -968,13 +957,13 @@ pub fn cli() -> Command {
968957
.required(false)
969958
.index(1)
970959
.value_name("NAME")
971-
.help("Package name to lint (if not present, every package will be linted")
960+
.help("Package name to lint (if not present, every package will be linted)")
972961
)
973-
.arg(Arg::new("package_version")
962+
.arg(Arg::new("package_version_constraint")
974963
.required(false)
975964
.index(2)
976965
.value_name("VERSION_CONSTRAINT")
977-
.help("A version constraint to search for (optional), e.g., '=1.0.0'")
966+
.help("A version constraint to match the package version against (optional), e.g., '=1.0.0'")
978967
)
979968
)
980969

@@ -984,9 +973,9 @@ pub fn cli() -> Command {
984973
.required(true)
985974
.index(1)
986975
.value_name("NAME")
987-
.help("Package name to lint (if not present, every package will be linted")
976+
.help("Package name to print the dependency tree of")
988977
)
989-
.arg(Arg::new("package_version")
978+
.arg(Arg::new("package_version_constraint")
990979
.required(false)
991980
.index(2)
992981
.value_name("VERSION_CONSTRAINT")

src/commands/dependencies_of.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
use std::io::Write;
1414

15+
use anyhow::Context;
1516
use anyhow::Result;
1617
use clap::ArgMatches;
1718
use futures::stream::StreamExt;
@@ -21,6 +22,7 @@ use tracing::trace;
2122
use crate::commands::util::getbool;
2223
use crate::config::*;
2324
use crate::package::PackageName;
25+
use crate::package::PackageVersionConstraint;
2426
use crate::repository::Repository;
2527
use crate::ui::*;
2628

@@ -39,8 +41,20 @@ pub async fn dependencies_of(
3941
.map(PackageName::from)
4042
.unwrap();
4143
trace!("Checking for package with name = {}", name);
44+
let version_constraint = matches
45+
.get_one::<String>("package_version_constraint")
46+
.map(|s| s.to_owned())
47+
.map(PackageVersionConstraint::try_from)
48+
.transpose()
49+
.context("Parsing package version constraint")?;
50+
trace!(
51+
"Checking for package with version constraint = {:?}",
52+
version_constraint
53+
);
4254

43-
crate::util::filters::build_package_filter_by_name(name)
55+
crate::util::filters::build_package_filter_by_name(name).and(
56+
crate::util::filters::build_package_filter_by_version_constraint(version_constraint),
57+
)
4458
};
4559

4660
let format = config.package_print_format();

src/commands/env_of.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use clap::ArgMatches;
1515
use tracing::trace;
1616

1717
use crate::package::PackageName;
18-
use crate::package::PackageVersionConstraint;
18+
use crate::package::PackageVersion;
1919
use crate::repository::Repository;
2020

2121
/// Implementation of the "env_of" subcommand
@@ -29,19 +29,20 @@ pub async fn env_of(matches: &ArgMatches, repo: Repository) -> Result<()> {
2929
.map(|s| s.to_owned())
3030
.map(PackageName::from)
3131
.unwrap();
32-
let constraint = matches
33-
.get_one::<String>("package_version_constraint")
32+
let version = matches
33+
.get_one::<String>("package_version")
3434
.map(|s| s.to_owned())
35-
.map(PackageVersionConstraint::try_from)
35+
.map(PackageVersion::try_from)
3636
.unwrap()?;
3737
trace!(
3838
"Checking for package with name = {} and version = {:?}",
3939
name,
40-
constraint
40+
version
4141
);
4242

43-
crate::util::filters::build_package_filter_by_name(name)
44-
.and(crate::util::filters::build_package_filter_by_version_constraint(constraint))
43+
crate::util::filters::build_package_filter_by_name(name).and(
44+
crate::util::filters::build_package_filter_by_version(version),
45+
)
4546
};
4647

4748
let mut stdout = std::io::stdout();

src/commands/find_artifact.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ pub async fn find_artifact(
5050
.map(|s| s.to_owned())
5151
.map(PackageVersionConstraint::try_from)
5252
.transpose()
53-
.context("Parsing package version constraint")
54-
.context("A valid package version constraint looks like this: '=1.0.0'")?;
53+
.context("Parsing package version constraint")?;
5554

5655
let env_filter = matches
5756
.get_many::<String>("env_filter")

src/commands/find_pkg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ pub async fn find_pkg(
3939
.map(|s| s.to_owned())
4040
.map(PackageVersionConstraint::try_from)
4141
.transpose()
42-
.context("Parsing package version constraint")
43-
.context("A valid package version constraint looks like this: '=1.0.0'")?;
42+
.context("Parsing package version constraint")?;
4443

4544
let iter = repo
4645
.packages()

src/commands/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn lint(
3737
.map(|s| s.to_owned())
3838
.map(PackageName::from);
3939
let pvers = matches
40-
.get_one::<String>("package_version")
40+
.get_one::<String>("package_version_constraint")
4141
.map(|s| s.to_owned())
4242
.map(PackageVersionConstraint::try_from)
4343
.transpose()?;

src/commands/metrics.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,27 @@ pub async fn metrics(
128128
r#"
129129
Butido release {release}
130130
131-
{configured_endpoints} Configured endpoints
132-
{configured_images} Configured images
133-
{configured_release_stores} Configured release stores
134-
{configured_phases} Configures phases
131+
Configuration:
132+
- {configured_endpoints} endpoints
133+
- {configured_images} images
134+
- {configured_release_stores} release stores
135+
- {configured_phases} phases
135136
136-
{nfiles} files in repository
137-
{repo_packages} packages in repository
137+
Repository:
138+
- {nfiles} files
139+
- {repo_packages} packages
138140
139-
{n_artifacts} artifacts in database
140-
{n_endpoints} endpoints in database
141-
{n_envvars} envvars in database
142-
{n_githashes} githashes in database
143-
{n_images} images in database
144-
{n_jobs} jobs in database
145-
{n_packages} packages in database
146-
{n_releasestores} releasestores in database
147-
{n_releases} releases in database
148-
{n_submits} submits in database
141+
Database:
142+
- {n_artifacts} artifacts
143+
- {n_endpoints} endpoints
144+
- {n_envvars} envvars
145+
- {n_githashes} githashes
146+
- {n_images} images
147+
- {n_jobs} jobs
148+
- {n_packages} packages
149+
- {n_releasestores} releasestores
150+
- {n_releases} releases
151+
- {n_submits} submits
149152
"#,
150153
release = clap::crate_version!(),
151154
configured_endpoints = config.docker().endpoints().len(),

src/commands/release.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ async fn new_release(
119119
};
120120
debug!("Artifacts = {:?}", arts);
121121

122+
if arts.is_empty() {
123+
return Err(anyhow!("No matching artifacts found to release"));
124+
}
125+
122126
arts.iter()
123127
.filter_map(|art| {
124128
art.path_buf()

0 commit comments

Comments
 (0)