Implemented a config file for beman-tidy#228
Implemented a config file for beman-tidy#228AndreiDurlea wants to merge 30 commits intobemanproject:mainfrom
Conversation
8d1a86c to
42a5aa6
Compare
|
@neatudarius when you're free, can you take a look at this PR? Besides the commited changes, I'm also thinking about a slight design improvement. Instead of forbidding, at config level, the ignoring of files/dirs such as I can easily implement something like this for any check that requires files to be present - that means modifying those checks to
This would allow users to check for other issues while keeping something temporarily ignored for their own reasons. And then I'd simply remove |
and reversal of unnecessary logging changes
and reversal of unnecessary logging changes
…reiDurlea/beman-tidy into origin/andreidurlea-issue227
…reiDurlea/beman-tidy into origin/andreidurlea-issue227
cff2eb3 to
c89a623
Compare
docs/dev-guide.md
Outdated
| * `tests/`: Unit tests for the tool. | ||
| * Structure is similar to the `beman_tidy/` directory. | ||
| * `pytest` is used for testing. | ||
| * `.beman-tidy.yml`: Configuration file for `beman-tidy` (optional). |
There was a problem hiding this comment.
Move it where ls -l says!
Should we first load default deployed beman_tidy/.beman-tidy.yml, and apply user file repo/path/.beman-tidy.yml over it? Aka should we provide a default .beman-tidy.yml near .beman-standard.yml? Right now it will be an empty config, but maybe we can add something in the future.
What do you think?
There was a problem hiding this comment.
That sounds like better design. Will work on implementing it 👍🏻
| """ | ||
|
|
||
| def __init__(self, repo_info, beman_standard_check_config, relative_path, name=None): | ||
| self.repo_info = repo_info |
There was a problem hiding this comment.
Check super().__init__(repo_info, beman_standard_check_config, name=name). It is doing what you need, right?
There was a problem hiding this comment.
Okay so, after some investigative work:
repo_infois (was) not available at init- when I implemented
should_skip()which callsget_ignroes(self.repo_info)which requires, of course,repo_info, a crash would happen - I half-fixed that problem by just setting
repo_infomyself
I'm now working on a bugfix regarding this issue, by changing when some params are intialized in base_check's constructor. Should I open a separate issue and do this in a separate pull request @neatudarius? Or is it fine to do this here.
There was a problem hiding this comment.
I still don't understand why current status from main is not enough?
-
repo info is set in super here : https://github.com/bemanproject/beman-tidy/blob/main/beman_tidy/lib/checks/base/base_check.py#L79
-
path is et at this line https://github.com/bemanproject/beman-tidy/pull/228/changes#diff-f79f15f4db56c998457771c1b845d1d6c2c41ab811a221e46a86a7db7a2c1faaR24. if you still need
relative_path, sure, addself.relative_path = Path(relative_path)at line 23.
TLDR: first line in any class that is derived needs to be called to super!
There was a problem hiding this comment.
I managed to implement it so the first line is the super's constructor. See the changes here.
I initially didn't keep the constructor first because it needed should_skip() to set log_level. and my should_skip() needed properties that were not yet initialized (repo_info, relative_path) to find out if the check if for ignored paths. So I initialized them before the construcgtor and called it a day=)
Basically,
constructor -> log_level -> should_skip() -> stuff in the constructor.
So i made log_level be lazily initialized.
repo_info was easy to fix, as I just made sure it was initialized before log_level in the constructor. But relative_path was not intiliazed in the constructor at all, and, as you said, the constructor should be the first thing called, hence the lazy initialization required for anything that uses should_skip() (in this case log_level
This issue had me use more brainpower than I expected I'd need for it =)))
Co-Authored-By: Darius Neațu <neatudarius@gmail.com>
This reverts commit 2a9b530.
Co-Authored-By: Darius Neațu <neatudarius@gmail.com>
|
@neatudarius I applied your changes, ready for another round of review. |
| """ | ||
|
|
||
| def __init__(self, repo_info, beman_standard_check_config, relative_path, name=None): | ||
| self.repo_info = repo_info |
There was a problem hiding this comment.
I still don't understand why current status from main is not enough?
-
repo info is set in super here : https://github.com/bemanproject/beman-tidy/blob/main/beman_tidy/lib/checks/base/base_check.py#L79
-
path is et at this line https://github.com/bemanproject/beman-tidy/pull/228/changes#diff-f79f15f4db56c998457771c1b845d1d6c2c41ab811a221e46a86a7db7a2c1faaR24. if you still need
relative_path, sure, addself.relative_path = Path(relative_path)at line 23.
TLDR: first line in any class that is derived needs to be called to super!
Laziliy initialized it because it calls should_skip() which needs stuff that is not init'd before / in the constructor. And the constructor should be the first thing called Rabbit hole development =)
22d8e39 to
96abdb0
Compare
to match clang-tidy docs style
|
@neatudarius ready for a re-review |
| """ | ||
| if super().should_skip(): | ||
| return True | ||
| return is_ignored(self.repo_info, self.relative_path) |
beman_tidy/lib/utils/config.py
Outdated
| Load the configuration file. | ||
| """ | ||
| # Load default configuration | ||
| default_config_path = files('beman_tidy').joinpath('.beman-tidy.yml') |
There was a problem hiding this comment.
This is not good practice. Do you want something like https://github.com/bemanproject/beman-tidy/blob/main/beman_tidy/lib/utils/git.py#L125?
There was a problem hiding this comment.
Alright I get why, I'll implement that. I initially thought having that .parent.parent.parent structure would be prone to errors (for example if the file gets moved), but I suppose that's an okay compromise
There was a problem hiding this comment.
Please test the installed tool. Does it work in your approach?
There was a problem hiding this comment.
It did run on exemplar, but, for the sake of consistency, I'll refactor to what is also used for beman-standard.yml. I dont see my file moving in the near future but, to be sure, I wrapped getting the path in a different function that will be sure to pop in someones eyes, should they want to move that file. Mental gymnastics here trying to prevent future bugs :)
Done! @neatudarius is ok?
To be consistent with `beman-standard.yml`
5e973e4 to
b8cb760
Compare
|
@neatudarius yet again ready for a re-review |
#227
Initial implementation:
.beman-tidy.yml, orconfig_pathparam.ignored_paths:is used specify paths of dirs or files. Dirs exclude all files and dirs in them. (behaves like gitignore)ignoresparam found onget_*_files()functions.is_ignored()function inlib/utils/file.pyto check if a given path is ignored