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

Upstream features from r-rmcgibbo bot #187

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

rmcgibbo
Copy link

I've re-based my fork onto the current top-of-tree, and tried to split my (otherwise disorganized) commits into a logical set of features. Each commit should be separate enough to review independently.

The commits are:

  1. Add --post-logs feature to post the build logs of failed packages to gist.github.com and to provide a link to the log in the github commit. In order to stay within usage restrictions of gist.github.com, this truncates the logs to 1MB if they're extremely long, and also strips out ANSI color codes. It also takes some care to try to capture stderr from the nix build process that might be relevant. For example, hash mismatches are not reported in the log accessible via nix log, and so you need to take other measures to capture them and associate them with the log.
  2. Add --prefer-edit feature. If running nixpkgs-review from multiple systems with the same github account (e.g. aarch64-linux and x86_64-linux), this feature causes the second upload of the github comment to edit the first comment, to avoid an extra ping to each github user subscribed on the thread.
  3. pre-build-filter: this feature adds a hook point where nixpkgs-review will call and external binary to filter the package set. this hook is used by the r-rmcgibbo bot to implement a dynamic form the the skip-packages feature that tries to skip packages such that the estimated build time falls within a cutoff. This is sufficiently complicated (it involves approximately solving a combinatorial optimization problem called the precedence constrained knapsack problem) that it makes sense as a hook to an external program.
  4. A minor commit to reduce the amount of output from git that is sent to stderr, which is useful for keeping the logs clear.

cc #171 @SuperSandro2000

I will ping this PR once my implementation of the pre-build-filter is available. I'm cleaning that up next.

@rmcgibbo rmcgibbo force-pushed the r-rmcgibbo-1 branch 3 times, most recently from d75a270 to e5e01e6 Compare March 28, 2021 23:22
propagatedBuildInputs = [
python3.pkgs.humanize
# humanize fails to declare its dependency on septools correctly
# https://github.com/NixOS/nixpkgs/pull/113060
Copy link
Collaborator

Choose a reason for hiding this comment

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

That PR is merged.

Copy link
Author

Choose a reason for hiding this comment

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

Is that sufficient? I personally call this default.nix with nixpkgs from 20.09.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can backport this is required.

Copy link
Author

Choose a reason for hiding this comment

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

Would you be able to do that? I've never done a backport.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nixpkgs_review/github.py Outdated Show resolved Hide resolved
nixpkgs_review/github.py Show resolved Hide resolved
nixpkgs_review/github.py Show resolved Hide resolved
nixpkgs_review/github.py Show resolved Hide resolved
nixpkgs_review/github.py Show resolved Hide resolved
nixpkgs_review/nix.py Outdated Show resolved Hide resolved
def pre_build_filter(attrs: List[Attr]) -> List[Attr]:
for cmd in (
cmd
for cmd in os.environ.get("NIXPKGS_REVIEW_PRE_BUILD_FILTER", "").split(":")
Copy link
Collaborator

Choose a reason for hiding this comment

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

That ENV needs documentation.

Copy link
Author

@rmcgibbo rmcgibbo Mar 30, 2021

Choose a reason for hiding this comment

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

This is a potential area of discussion, @Mic92:

Despite being a small amount of code, for me this is the most important feature. The idea is that I want to run some code to manipulate the set of attrs that the rest of the code deals with, to set some as skipped=True based on a dynamic calculation that I can control. Basically a "plugin".

I can think of two possible ways to achieve this feature. One is as written, where nixpkgs-review connects with these external plugins by environment variable and subprocesses them. A different way to do it that you might prefer would be to use import.metadata entry_points, which is kind of a python plugin feature. We could agree on the name of the entry point, and then this pre_build_filter function would find the plugins by iterating over the matching entry points rather than looking through an environment variable. The big difference here would be that the plugin would execute inside the same process as the main python interpreter.

I am open to either mechanism.

Copy link
Owner

Choose a reason for hiding this comment

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

I will have a look this evening into this PR. Thanks for leading the review so far @SuperSandro2000 . Due to diverse requirements and languages used in the community a language-independent solution might be preferred.

Copy link
Owner

Choose a reason for hiding this comment

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

@ryantm is this something that nixpkgs-update could benefit from as well? If not what is missing?

Copy link
Author

Choose a reason for hiding this comment

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

I added some documentation to the README.md

nixpkgs_review/report.py Show resolved Hide resolved
nixpkgs_review/report.py Outdated Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
@SuperSandro2000
Copy link
Collaborator

Thanks for doing this! ❤️

return None

def upload_gist(self, name: str, content: str, description: str) -> Dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add an option to use a different token for posting gists? I have them on my bot account but would like to post as me.

Copy link
Author

Choose a reason for hiding this comment

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

Would you want to control this by providing an environment variable like GITHUB_GIST_TOKEN that would have a higher precedence than the other mechanisms for setting the token?

Copy link
Collaborator

@SuperSandro2000 SuperSandro2000 Apr 1, 2021

Choose a reason for hiding this comment

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

Thats how I do it right now. Would be great if you could add this here, too :)

Copy link
Owner

@Mic92 Mic92 Jun 1, 2021

Choose a reason for hiding this comment

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

How about adding build logs within the comment instead of a gist? NixOS/nixpkgs#125133 (comment)

Than we don't have this issue at all.

Copy link
Author

Choose a reason for hiding this comment

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

That seems strictly worse to me. At least in my browser (firefox), there's no dedicated HTML page for files embedded within the comment, so glancing at each log requires downloading the file and navigating to the downloads folder and opening it up.

Copy link
Owner

Choose a reason for hiding this comment

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

Fair enough.

@@ -5,6 +5,14 @@ python3.pkgs.buildPythonApplication rec {
name = "nixpkgs-review";
src = ./.;
buildInputs = [ makeWrapper ];

propagatedBuildInputs = [
python3.pkgs.humanize
Copy link
Owner

Choose a reason for hiding this comment

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

Eventually I want get rid of humanize/backport again, but I can also do this later on master.
Right now we are unsetting PYTHONPATH to avoid injecting dependencies into nix-shell.

Copy link
Author

Choose a reason for hiding this comment

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

Do you prefer if I vendor the naturaldelta function from humanize into this PR, or we could also do something based on wrappers so that we get python3.pkgs.humanize on sys.path even though external settings of PYTHONPATH are ignored?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Vendoring the code is probably less hacky. Maybe we can also rewrite the function if it is less complex.

rmcgibbo added 8 commits June 6, 2021 14:45
… from which to fetch the ofborg evalation.

This is not required for normal users, but can be useful when nixpkgs-review is run as part of a distributed
system like r-rmcgibbo, and you want to use an ofborg evaluation that has since been invalidated by a force-push
to the PR and you do not want to fall back to local evaluation.
@happysalada
Copy link

@rmcgibbo thank you for this! ❤️

@SuperSandro2000
Copy link
Collaborator

@rmcgibbo Can you take a look at the tests failures? I think it is unable to parse remotes that are local files.

@Artturin
Copy link
Collaborator

@Mic92 the test log has expired, please rerun it

@SuperSandro2000
Copy link
Collaborator

@Mic92 why can't I rerun the tests?
The author of the PR can always trigger a test run by force pushing.

@rmcgibbo
Copy link
Author

I made a half-heared attempt to resolve the conflicts.

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.

5 participants