Skip to content

Modularised and extend critique.py - #22

Merged
benajamin merged 4 commits into
masterfrom
improve_critique
Nov 10, 2020
Merged

benajamin merged 4 commits into
masterfrom
improve_critique

Conversation

@benajamin

@benajamin benajamin commented Oct 22, 2020 •

Copy link
Copy Markdown
Contributor

Fixes #20
Performing tests on the example files is now modular and each test reports with its own column. Tests are implemented to:

  • identify the container files (HDF5, HDF4 and XML),
  • count the NXentry groups (only implemented for HDF5 so far), and
  • show the names of any application definitions included (only implemented for HDF5 so far)

Implementing the tests for XML should be straightforward, but I don't think the HDF4 dependencies are worth working with.

@prjemian

Copy link
Copy Markdown
Contributor

@benajamin suggested by email:

... the output table could be automatically generated by a github "action" (on every commit to the exampledata repo) and could go directly into the README.md file so that it is more prominently displayed.

Seems possible but re-writing the README file could make it less intuitive how to edit the static content there. Maybe there is another way to have the content appear in the README even though it comes from another file. Some kind of include directive, if it exists.

@prjemian

Copy link
Copy Markdown
Contributor

@prjemian

Copy link
Copy Markdown
Contributor

Also need to avoid the obvious race condition posed by a new commit from the Github Action.

Comment thread critique.md Resolved
Comment thread critique.md Resolved
@benajamin

Copy link
Copy Markdown
Contributor Author

@prjemian, is it correct now?

Comment thread critique.py Outdated
fullname = os.path.join(path, fname)
if not os.path.exists(fullname):
return
## can the file be found?

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.

remove these commented-out lines

Comment thread critique.py Resolved
Comment thread critique.py Resolved
Comment thread critique.py Outdated
ad_list.add(str(entry['definition'][0], encoding='utf-8'))
else:
for sub in subentry_list:
ad_list.add(str(sub['definition'][0], encoding='utf-8'))

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.

add comment saying this counts application definitions as NXsubentry

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.

at line 204

Comment thread critique.py Outdated

def __init__(self):
self.db = {}
self.test_bank = [func for func in dir(Critic) if callable(getattr(Critic, func)) and func.startswith("test_")]

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.

While efficient for execution, list comprehensions such as this can be tricky to review and edit. Also, the line length becomes a bit long. I often break a list comprehension such as this into several lines to improve readability without compromising efficiency:

self.test_bank = [
    func
    for func in dir(Critic)
    if callable(getattr(Critic, func)) and func.startswith("test_")
]

Comment thread critique.py Outdated
:param str fname: (absolute or relative path and) name of file
'''

def __init__(self, path, fname):

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.

consider changing to path=None, fname=None with consequence to the caller as shown below

Comment thread critique.py Outdated
def __init__(self):
self.db = {}
self.test_bank = [func for func in dir(Critic) if callable(getattr(Critic, func)) and func.startswith("test_")]
self.table_labels = ["path", "file"] + Critic( None, None).test_results

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.

per previous suggestion, then Critic().test_results

Comment thread critique.py Outdated
table.labels = ["file", "critique"]
for fname, critique in sorted(flist.items()):
table.addRow(("``"+fname+"``", critique))
table.addRow(["`"+path+"`","`"+fname+"`"]+ critique.test_results)

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.

space after the ,

Comment thread critique.py Resolved
Comment thread critique.py Outdated
return
for nm in files:
registrar.add(path, Critic(path, nm))
if os.path.splitext(nm)[1] not in ['.txt','.py','.rst','.md','.in'] and nm[0] != '.': # skip other types of file

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.

        if os.path.splitext(nm)[1] not in extensions and nm[0] != '.': # skip other types of file

Comment thread critique.py Resolved

@prjemian prjemian left a comment

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.

changes as noted

@prjemian

Copy link
Copy Markdown
Contributor

For code style matters, pylint, flake8, and black are the usual tools. Of these, black actually modifies the file per the style (the others point out items inconsistent with the style). While brutal, I usually use black -l 75 some_module.py to apply black's choices and limit line length to no more than 75 characters.

ALWAYS, I run black after committing the some_module.py file to version control.

@prjemian prjemian left a comment

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.

LGTM

@prjemian

Copy link
Copy Markdown
Contributor

Good job!

@benajamin

Copy link
Copy Markdown
Contributor Author

Black looks interesting and I'll check it out. I am pretty progressive in my personal opinions about code style though:

  • Most arguments for line length limits are outdated. Readability is always paramount.
  • Tabs are better than spaces because modern editors can adjust tab width.

But style arguments are like wars, the only way to win is to not get involved.

@benajamin
benajamin merged commit 2aedd34 into master Nov 10, 2020
@benajamin
benajamin deleted the improve_critique branch November 10, 2020 17:45
@prjemian

Copy link
Copy Markdown
Contributor

But style arguments are like wars, the only way to win is to not get involved.

Why I have succumbed to black. The Borg have won.

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.

Sort files by application definition

2 participants