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

Add missing-patch-comment check using rust and rnix #16

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

rmcgibbo
Copy link
Collaborator

Example:

$ nix run -c nixpkgs-hammer -f ~/projects/nixpkgs python38Packages.credstash
When evaluating attribute ‘python38Packages.credstash’:
warning: missing-patch-comment
Please add a comment on the line above explaining the purpose of this patch.
Near /home/mcgibbon/projects/nixpkgs/pkgs/development/python-modules/credstash/default.nix:13:4:
   |
13 |     (fetchpatch {
   |    ^
See: https://github.com/jtojnar/nixpkgs-hammering/blob/master/explanations/missing-patch-comment.md

Here's the relevant line of code: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/credstash/default.nix#L13

Notes:
(a) This is a big change because it requires rust and rnix. There might be better ways to do this with other tools.
(b) The check, as implemented, is probably too strict. It looks for each element in the patches = [...] list, and demands to find a comment immediately prior to the element. So, for example, a comment like this one in imageio-ffmpeg is not currently detected. But this could be changed.

@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch from e936d37 to 8df319b Compare January 24, 2021 18:07
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
tools/nixpkgs-hammer Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@rmcgibbo
Copy link
Collaborator Author

I've pushed a bunch of improvements + fixes in response to your review in 9313e78

tools/nixpkgs-hammer Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
ast-checks/Cargo.toml Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
ast-checks/Cargo.toml Show resolved Hide resolved
ast-checks/Cargo.toml Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@rmcgibbo
Copy link
Collaborator Author

In dea035c, I've switched to naersk for building the rust package, which required updating the flake lock file. I don't have much of an opinion one way or the other, so I'm happy to leave that in or revert it.

ast-checks/src/comment_finders.rs Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Outdated Show resolved Hide resolved
@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch from f408c1b to 2811feb Compare January 26, 2021 03:14
Copy link

@lovesegfault lovesegfault left a comment

Choose a reason for hiding this comment

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

The code looks good, I left one last idea for a small improvement :)

ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch 2 times, most recently from d2b27fc to b7ba8c6 Compare January 27, 2021 23:42

In each patch comment, please explain the purpose of the patch and link to the relevant upstream issue if possible. If the patch has been merged upstream but is not yet part of the released version, please note the version number or date in the comment such that a future maintainer updating the nix expression will know whether the patch has been incorporated upstream and can thus be removed from nixpkgs.

Furthermore, please use a _stable_ URL for the patch. Rather than, for example, linking to a github pull request of the form `https://github.com/owner/repo/pull/pr_number.patch` which would change every time a commit is addded or the PR is force-pushed, link to a specific commit-sha.patch of the form `https://github.com/owner/repo/commit/sha.patch`.
Copy link
Owner

@jtojnar jtojnar Jan 28, 2021

Choose a reason for hiding this comment

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

Agreed. But maybe this should be a separate check. But looks good enough and we can extract it later.

Copy link
Collaborator Author

@rmcgibbo rmcgibbo Jan 28, 2021

Choose a reason for hiding this comment

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

👍 Separating it out into another check at a later time sounds good to me.

flake.nix Outdated Show resolved Hide resolved
@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch from b7ba8c6 to eaf4b9e Compare January 31, 2021 21:24
flake.nix Outdated Show resolved Hide resolved
@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch from eaf4b9e to 8fb211a Compare January 31, 2021 21:29
@rmcgibbo
Copy link
Collaborator Author

(I've rebased on top of master and squashed this into 1 commit.)

@rmcgibbo rmcgibbo force-pushed the missing-patch-comment branch from 8fb211a to 1443f94 Compare January 31, 2021 21:32
Copy link
Owner

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

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

Looks very nice, just few last comments.

flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
ast-checks/src/tree_utils.rs Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
ast-checks/src/missing-patch-comment.rs Outdated Show resolved Hide resolved
@rmcgibbo
Copy link
Collaborator Author

Pushed a new commit based on your comments.

@jtojnar jtojnar self-assigned this Jan 31, 2021
@jtojnar jtojnar force-pushed the missing-patch-comment branch from 58a1d66 to 0864566 Compare February 1, 2021 00:22
Copy link
Owner

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

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

Tweaked style a bit, added a forgotten args.show_trace and now it is good to go.

Thanks for the excellent work.

@@ -15,4 +15,4 @@ jobs:
uses: cachix/install-nix-action@v12

- name: Run tests
run: nix-shell --run ./run-tests.py
run: nix run -c ./run-tests.py
Copy link
Owner

Choose a reason for hiding this comment

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

Just to save myself confusion in the future, Nix 2.4 will likely use nix shell command for this feature (this is how it is named at current nixUnstable).

@@ -37,7 +61,8 @@
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
python3
nix
Copy link
Owner

Choose a reason for hiding this comment

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

Removed Nix here since nixpkgs-hammer will already have it in PATH when ran from the package (as tests do), and for development one will have Nix anyway. And stable Nix here would make updating flake annoying.

@jtojnar jtojnar merged commit 0864566 into jtojnar:master Feb 1, 2021
@rmcgibbo rmcgibbo deleted the missing-patch-comment branch February 1, 2021 00:31
@rmcgibbo
Copy link
Collaborator Author

rmcgibbo commented Feb 1, 2021

Awesome!

@jtojnar jtojnar mentioned this pull request Feb 1, 2021
34 tasks
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.

3 participants