Conversation
…anywhere in the module body Also adds fundamental testing of the `bin.addheader.main` function, and some support functions for working with io
jonasbardino
left a comment
There was a problem hiding this comment.
The fix looks right and good idea to add unit tests while at it.
A number of GH actions failed so I'd be nice if you could either look into fixing or commenting on them before I proceed with the review. We have seen false positives e.g. from unrelated lint warnings in the past but it doesn't look like just that here.
…m bin.addheader import`
I'm investigating this. I ran the jobs locally with |
I found the reason. The issue is that |
…y in rocky9/rocky10 CI This is done because the CI `checkout` action falls back to using the GitHub REST API when run under Rocky9/Rocky10, and the REST API respects `.gitattributes`, thus excluding `bin/addheader.py`.
| def add_header(modulename: str, modulebody: str) -> str: | ||
| """Naive function to add a header, used for generting test data.""" | ||
| return ( | ||
| HEADER_FORMAT.format(modulename=modulename, description=DEFAULT_DESC) |
There was a problem hiding this comment.
We have opted for percent-expansion over other string construction methods so far. I think we need to discuss in the dev team whether or when to stray from that.
There was a problem hiding this comment.
Alright. Should I change this printf-style formatting for now then?
There was a problem hiding this comment.
The path of least resistance for merging is going with percent expansion. You can still use the dict form to preserve named values.
Feel free to branch the current version with the other review issues addressed and save it for a possible follow up PR only to switch to .format after we have discussed it in the team next week(?)
| TreeDict = Union[dict[str, "TreeDict"], dict[str, str]] | ||
|
|
||
|
|
||
| def write_file(directory: str, name: str, content: str) -> None: |
There was a problem hiding this comment.
I think we want to discuss strict typing in the dev team before we venture too far down the path of using it.
There was a problem hiding this comment.
Okay. So far I have opted to add it when adding or modifying code, since it can co-exist with untyped code.
There was a problem hiding this comment.
Yes, I noticed it in other PRs too and while I'm not against the idea and it doesn't hurt as such it still potentially introduces inconsistency. So I still think it's something we want to briefly discuss with pros and cons weighed in the dev team before we decide the path ahead.
| import os | ||
| import shutil | ||
| import tempfile | ||
| import unittest |
There was a problem hiding this comment.
minor: unittest import appears unused now
| self.target_dir = tempfile.mkdtemp(prefix=self.id()) | ||
|
|
||
| def after_each(self) -> None: | ||
| shutil.rmtree(self.target_dir) |
There was a problem hiding this comment.
Hmm, I think I recall that we wipe test locations automatically in other cases to avoid this kind of explicit post-test cleanup, but I might be wrong or perhaps it's specific to the new iosupp module. In any case it would be nice to avoid because it's easy to forget.
| import unittest | ||
|
|
||
| from bin.addheader import __file__ as addheader_module_file | ||
| from bin.addheader import main |
There was a problem hiding this comment.
nit-pick: should we keep all imports from one module in a single import ?
| def write_tree(root: str, tree: TreeDict) -> None: | ||
| """ | ||
| Write the given given tree to the given root directory. | ||
| """ |
There was a problem hiding this comment.
nit-pick: is this black formatting or on purpose? I'd expect shorter than 80 char doc-strings to remain on a single line as PEP8 recommends.
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software Foundation, | ||
| # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # |
There was a problem hiding this comment.
nit-pick: this header looks oddly under-filled (significantly shorter than 80 chars). Did you use addheader to generate it or do we have those same overly short lines in another module you reused from?
Same applies to similar occurrences in other files below.
|
|
||
|
|
||
| def add_header(modulename: str, modulebody: str) -> str: | ||
| """Naive function to add a header, used for generting test data.""" |
There was a problem hiding this comment.
nit-pick: typo in generating
|
|
||
| def write_tree(root: str, tree: TreeDict) -> None: | ||
| """ | ||
| Write the given given tree to the given root directory. |
There was a problem hiding this comment.
nit-pick: duplicate 'given'
jonasbardino
left a comment
There was a problem hiding this comment.
Looks good overall, but I think we need to sort out a few things as mentioned in the comments. Also has minor bits and pieces to polish while at it.
Fix
bin.addheaderbug causing it to crash on modules with%sanywherein the module body.
Also adds fundamental testing of the
bin.addheader.mainfunction, and somesupport functions in
tests.support.iosuppfor working reading and writing filesand filetrees in tests.