Skip to content

Commit

Permalink
Infer default pname when using '-u'
Browse files Browse the repository at this point in the history
closes: #49
  • Loading branch information
jonringer committed Sep 10, 2022
1 parent 702fe8f commit 8f4f231
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixes:
- Fix failure with pypi responses not containing a platform
- `-u` with pypi will now filter out pre-releases when determining latest release
- Default to repo name when using `-u`

## v0.3.0

Expand Down
19 changes: 11 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,15 @@ pub fn validate_and_serialize_matches(
assert(matches.occurrences_of("pname") != 0, "Must provide value for -p,--pname when using flake template.");
}

let (path_to_write, top_level_path) =
nix_file_paths(&matches, &template, &path, &pname, &nixpkgs_root);

assert(matches.is_present("stdout") || (!path_to_write.exists()),
&format!("Cannot write to file '{}', already exists", path_to_write.display()));

let mut info = ExpressionInfo {
pname,
version,
license,
maintainer,
template,
fetcher,
path_to_write,
top_level_path,
path_to_write: std::path::PathBuf::new(),
top_level_path: std::path::PathBuf::new(),
include_documentation_links,
include_meta,
tag_prefix: "".to_owned(),
Expand All @@ -205,6 +199,15 @@ pub fn validate_and_serialize_matches(
read_meta_from_url(url, &mut info);
}

let (path_to_write, top_level_path) =
nix_file_paths(&matches, &info.template, &path, &info.pname, &nixpkgs_root);

info.path_to_write = path_to_write.clone();
info.top_level_path = top_level_path.clone();

assert(matches.is_present("stdout") || (!path_to_write.exists()),
&format!("Cannot write to file '{}', already exists", path_to_write.display()));

info
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Info {
pub license: String,

#[serde(rename = "name")]
name: String,
pub name: String,

#[serde(rename = "package_url")]
package_url: String,
Expand Down
10 changes: 9 additions & 1 deletion src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ pub fn fetch_github_release_info(repo: &types::GithubRepo) -> types::GhReleaseRe
}

pub fn fill_github_info(repo: &types::GithubRepo, info: &mut types::ExpressionInfo) {
if info.pname == "CHANGE" {
info.pname = repo.repo.to_string();
}

eprintln!("Determining latest release for {}", &repo.repo);
let mut releases = fetch_github_release_info(&repo);
if !releases.is_empty() {
Expand Down Expand Up @@ -247,8 +251,13 @@ pub fn fill_github_info(repo: &types::GithubRepo, info: &mut types::ExpressionIn
}

pub fn fill_pypi_info(pypi_repo: &types::PypiRepo, info: &mut types::ExpressionInfo) {

eprintln!("Determining latest release for {}", &pypi_repo.project);
let pypi_response = fetch_pypi_project_info(pypi_repo);
if info.pname == "CHANGE" {
info.pname = pypi_repo.project.clone();
}

let mut releases: Vec<String> = pypi_response
.releases
.keys()
Expand All @@ -269,7 +278,6 @@ pub fn fill_pypi_info(pypi_repo: &types::PypiRepo, info: &mut types::ExpressionI
.filter(|a| a.packagetype == "sdist")
.next();

info.pname = pypi_repo.project.clone();
info.version = latest_version.clone();
info.homepage = pypi_response.info.home_page.clone();
info.description = pypi_response.info.summary.trim_end_matches(".").to_string();
Expand Down

0 comments on commit 8f4f231

Please sign in to comment.