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

feat(nim): add support for nimble project package version #2569

Merged
merged 8 commits into from
May 9, 2021

Conversation

aeruhxi
Copy link
Contributor

@aeruhxi aeruhxi commented Apr 9, 2021

This PR adds support for the package module for a nimble project to show version number in the project directory.

Description

I have added a new function find_file that takes a directory and a predicate. It iterates over all files in a given directory and returns a filename if it satisfies the given predicate. This function is used to detect if a given directory is a nimble project by checking file_name.ends_with(".nimble").

If a directory is found to be a nimble project, extract_nimble_version then calls nimble dump --json to get the package version. I used json instead of the default ini format for dump because I could not find an existing ini parser used in the project but json parser was already there used predominantly for most packages.

Update

It now uses context to check for the existence of .nimble file.

Alternative implementation?

After already writing find_file, I later found out that Instead of using find_file, I could directly call nimble dump and checks its exit code, because it fails if it's not a nimble project, to determine a nimble project. I want to have others' opinion on this if that would be a better implementation idea.

Motivation and Context

The motivation and context is in the linked issue.

Closes #2454.

Screenshots (if appropriate):

image

How Has This Been Tested?

  • I have tested using MacOS (I don't have an access to it)
  • I have tested using Linux
  • I have tested using Windows (I don't have an access to it)

Checklist:

This PR is a WIP. Docs and tests are yet to be done.

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

@@ -175,6 +186,8 @@ fn extract_meson_version(file_contents: &str) -> Option<String> {
fn get_package_version(base_dir: &Path, config: &PackageConfig) -> Option<String> {
if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) {
extract_cargo_version(&cargo_toml)
} else if utils::find_file(base_dir, |file_name| file_name.ends_with(".nimble")).is_some() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you have this at least make the initial check for nimble files via context, like the language modules do? It keeps a list of files and file extensions.

context
  .try_begin_scan()?
  .set_extensions(&["nimble"])
  .is_match();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. It's done.

Copy link
Member

@davidkna davidkna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current approach and not always calling nimble dump is better for general performance.

src/modules/package.rs Outdated Show resolved Hide resolved
@aeruhxi aeruhxi changed the title feat(nim): add support for nimble project package version (WIP) feat(nim): add support for nimble project package version Apr 12, 2021
@aeruhxi
Copy link
Contributor Author

aeruhxi commented Apr 12, 2021

It has been complete from my side now. I don't own a dev macos or windows machine.

docs/config/README.md Outdated Show resolved Hide resolved
project_dir.close()
}

#[test]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another test with a nimble file but no nimble command available would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I've just added it.

@davidkna
Copy link
Member

I don't own a dev macos or windows machine.

That's fine.

@vladimyr
Copy link
Member

Let me try something before we merge this, looks good otherwise 👍

@andytom andytom requested a review from a team April 25, 2021 20:15
@vladimyr
Copy link
Member

Let me try something before we merge this, looks good otherwise

Ignore me, my attempts failed so let's continue reviewing it as is.

@aeruhxi
Copy link
Contributor Author

aeruhxi commented May 1, 2021

Should I rebase and resolve conflicts?

@vladimyr
Copy link
Member

vladimyr commented May 1, 2021

Should I rebase and resolve conflicts?

Please do 🚀

@aeruhxi aeruhxi force-pushed the feat-nimble-project-support branch from 885b5e3 to f189d6c Compare May 5, 2021 13:09
@aeruhxi
Copy link
Contributor Author

aeruhxi commented May 5, 2021

Should I rebase and resolve conflicts?

Please do

Done.

Copy link
Member

@davidkna davidkna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andytom
Copy link
Member

andytom commented May 8, 2021

Sorry @aeruhxi can you fix the merge conflicts again and then we can get this merged.

@aeruhxi
Copy link
Contributor Author

aeruhxi commented May 9, 2021

Sorry @aeruhxi can you fix the merge conflicts again and then we can get this merged.

Sure, no problem.

@aeruhxi aeruhxi force-pushed the feat-nimble-project-support branch from f189d6c to 65286ce Compare May 9, 2021 03:00
@andytom andytom merged commit f3984ea into starship:master May 9, 2021
@andytom
Copy link
Member

andytom commented May 9, 2021

Thank you for your contribution @aeruhxi and thank you for the reviews @davidkna and @vladimyr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package version: Nimble project support
4 participants