Skip to content

Bmedx/docgen#29

Merged
bmedx merged 5 commits into
masterfrom
bmedx/docgen
Mar 5, 2019
Merged

Bmedx/docgen#29
bmedx merged 5 commits into
masterfrom
bmedx/docgen

Conversation

@bmedx
Copy link
Copy Markdown
Contributor

@bmedx bmedx commented Feb 25, 2019

Description: Adds the ability to generate human readable reports in RST from code-annotations generated YAML files.

JIRA: PLAT-2359

Author concerns: There is some basic functionality here for being able to use other templates to potentially create other types of output (HTML, MD, etc.) but it's pretty half baked. I'd like to come back to that and clean that up later, and add HTML generation as a proof-of-concept. Maybe next hackathon...

@bmedx bmedx requested review from doctoryes and pwnage101 February 25, 2019 23:47
Comment thread code_annotations/generate_docs.py Outdated

Args:
report_filename: Filename to write to.
report_data: Dict of reporting data to use, in the {'file name': [list, of, annotations,]} style.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW, I got stuck on understanding "report objects" (report_data here) for a while because I didn't realize the filename keys were names of source files (rather than report files). More verbage around this would be helpful.

Also, shouldn't report_filename/full_report_filename actually be doc_filename/full_doc_filename because it's an rst doc (rather than a yaml report)?

@@ -0,0 +1,5 @@
{% if annotation.extra and annotation.extra.object_id %}
`<{{ annotation.extra.object_id }}> line {{ annotation.line_number }} <{{ source_link_prefix }}{{ filename }}#L{{ annotation.line_number }}>`_: {{ annotation.annotation_token }} {% include "annotation_data.tpl" %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Links to the exact line on github!? 🆒 🥇

{% else %}
{% if loop.changed(annotation.report_group_id) %}

{% endif %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you clarify what the above if-block does exactly? Is the extra newline necessary to terminate the group because un-indenting isn't enough to cue the termination?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately handling rst whitespace in Jinja2 templates is super finicky and trying to comment them only makes it worse.

Comment thread .annotations_sample Outdated
@@ -1,7 +1,11 @@
source_path: ../
source_path: ../devstack-docker/edx-platform/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

was this change intentional, or temporary for testing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Temp, will fix.

"""
safelist_file.write(safelist_comment.lstrip())
yaml_ordered_dump(safelist_data, stream=safelist_file, default_flow_style=False)
yaml.safe_dump(safelist_data, stream=safelist_file, default_flow_style=False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm also just generally unclear as to why these don't need to be ordered anymore.

Copy link
Copy Markdown
Contributor Author

@bmedx bmedx Mar 1, 2019

Choose a reason for hiding this comment

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

Oddly sorted dicts seem to be the default behavior in pyyaml so this seems to have not been necessary in the first place: https://github.com/yaml/pyyaml/blob/4c2e993321ad29a02a61c4818f3cef9229219003/lib3/yaml/representer.py#L108-L114

I checked this in Python 3.6 and 2.7:

>>> a = {'z':1, 'g':2, 'a': 3, 'b': 4, 'w': 5}
>>> import yaml
>>> yaml.safe_dump(a)
'{a: 3, b: 4, g: 2, w: 5, z: 1}\n'

I found it because the new edx-lint enforces yaml.safe_load/dump, which fails on the old OrderedDict approach.

Comment thread .annotations_sample Outdated
@@ -1,7 +1,11 @@
source_path: ../
source_path: ../devstack-docker/edx-platform/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did this path sneak in? Or was it intended?

Comment thread code_annotations/generate_docs.py Outdated
for report_annotation in report[filename]:
if loaded_annotation['line_number'] == report_annotation['line_number'] and \
loaded_annotation['annotation_token'] == report_annotation['annotation_token'] and \
loaded_annotation['annotation_data'] == report_annotation['annotation_data']:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this any better?:

index_keys = ('line_number', 'annotation_token', 'annotation_data')
if all( [ loaded_annotation[k] == report_annotation[k] for k in index_keys ] ):

@@ -0,0 +1,8 @@
{% if annotation.annotation_data is sequence and annotation.annotation_data is not string %}
{% for a in annotation.annotation_data %}
choice_{{ slugify(a) }}_{% if not loop.last %}, {% endif %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is this loop magic? I'm intrigued...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread tests/helpers.py Outdated
file_extension: All files with this extension will be deleted
"""
try:
filelist = [f for f in os.listdir('test_reports') if f.endswith(file_extension)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Any reason for this line to be in the try...except block instead of outside it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, I'll move it.

Comment thread tests/test_generate_docs.py Outdated

def _do_find(source_path, new_report_path):
"""
Do a static annotation search with report, rename the report to a distinct name, return the new name.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't return the new name anymore?

- Adds ability to turn yaml reports into .rst
- Uses Jinja2 templates, so open to extension
- Can combine multiple report files
- Changes reporting format to use safe_read / safe_write
- Can create direct links to Github
@bmedx
Copy link
Copy Markdown
Contributor Author

bmedx commented Mar 1, 2019

@pwnage101 @doctoryes this is ready for re-review

@bmedx bmedx merged commit 9bd71a5 into master Mar 5, 2019
@bmedx bmedx deleted the bmedx/docgen branch March 5, 2019 17:02
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.

4 participants