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
Verify doc examples #48497
Verify doc examples #48497
Conversation
doc/functions/library/test.py
Outdated
yield { "id": xml_id, "code": code.text, "expect": expect.text } | ||
|
||
|
||
parser = argparse.ArgumentParser(description='Execute doc tests for the Nixpkgs manual..') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put the following code in a function, e.g. main()
and add `if __name __ = "main": main()
doc/functions/library/test.py
Outdated
doc_root = os.path.dirname(os.path.realpath(__file__)) | ||
all_doc_files = glob.glob("{}/*.xml".format(doc_root)) | ||
|
||
all_docs = [ET.parse(filename) for filename in all_doc_files] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generator expression
doc/functions/library/test.py
Outdated
all_docs = [ET.parse(filename) for filename in all_doc_files] | ||
all_examples = itertools.chain(*[find_examples(doc) for doc in all_docs]) | ||
|
||
if len(args.ids) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if args.ids:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, this is >1 not >0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... But should it be? seems like we drop a singleton list here? OK agreed with @FRidh then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 this is a relic of when I didn't have proper argument parsing 😁 good catch.
doc/default.nix
Outdated
@@ -6,7 +6,8 @@ in | |||
pkgs.stdenv.mkDerivation { | |||
name = "nixpkgs-manual"; | |||
|
|||
buildInputs = with pkgs; [ pandoc libxml2 libxslt zip jing xmlformat ]; | |||
buildInputs = with pkgs; [ pandoc libxml2 libxslt zip jing xmlformat | |||
python36 nix ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python3 is sufficient. Note that soon I intend to make python37 the default, and this code will still work fine then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
doc/functions/library/test.py
Outdated
all_docs = [ET.parse(filename) for filename in all_doc_files] | ||
all_examples = itertools.chain(*[find_examples(doc) for doc in all_docs]) | ||
|
||
if len(args.ids) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, this is >1 not >0
doc/functions/library/test.py
Outdated
all_docs = [ET.parse(filename) for filename in all_doc_files] | ||
all_examples = itertools.chain(*[find_examples(doc) for doc in all_docs]) | ||
|
||
if len(args.ids) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... But should it be? seems like we drop a singleton list here? OK agreed with @FRidh then
doc/functions/library/test.py
Outdated
failed = [] | ||
|
||
for example in filtered_examples: | ||
full_expression = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe want f strings?
Using a single configuration file reduces the need to think about how quoting works from Nix -> Bash -> Make -> xsltproc -> XSL Additionally, it allows us to make additional interesting customisations as needed.
91869a6
to
b216f74
Compare
Also, hide <programlisting role="context"> which are for doc-tests.
b216f74
to
37ceae1
Compare
Are there any updates on this pull request, please? |
@grahamc has this been abandoned? |
Motivation for this change
Test the function examples actually work.
Testing steps:
It outputs something like:
For each example without a testable program, it prints:
If a test fails, it outputs instructions on how to test only the failing examples:
These tests will block the Nixpkgs manual from building as well.
The XML isn't super nice to write, but I think isn't too onerous?
Anyway, rendered it looks like this:
I also verified that python3 was already in the build closure.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)