Skip to content

Implemented a config file for beman-tidy#228

Draft
AndreiDurlea wants to merge 30 commits intobemanproject:mainfrom
AndreiDurlea:origin/andreidurlea-issue227
Draft

Implemented a config file for beman-tidy#228
AndreiDurlea wants to merge 30 commits intobemanproject:mainfrom
AndreiDurlea:origin/andreidurlea-issue227

Conversation

@AndreiDurlea
Copy link
Member

@AndreiDurlea AndreiDurlea commented Feb 15, 2026

#227
Initial implementation:

  • Load config with default name, .beman-tidy.yml, or config_path param.
  • In the config yaml content, the entry ignored_paths: is used specify paths of dirs or files. Dirs exclude all files and dirs in them. (behaves like gitignore)
  • Previously excluded dirs (.idea etc.) are now merged with this functionality in the ignores param found on get_*_files() functions.
  • introduced is_ignored() function in lib/utils/file.py to check if a given path is ignored

@AndreiDurlea AndreiDurlea force-pushed the origin/andreidurlea-issue227 branch from 8d1a86c to 42a5aa6 Compare February 15, 2026 14:58
@AndreiDurlea
Copy link
Member Author

AndreiDurlea commented Feb 15, 2026

@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 README.md, LICENSE etc., I propose that their individual checks simply throw errors if those files seem nonexistent and print out a log message if they actually exist but are ignored in the config. For example
README.md was found, but was explicitly ignored in the config file (.beman-tidy.yml). Make sure it is visible to beman-tidy to pass this check and other related checks.

I can easily implement something like this for any check that requires files to be present - that means modifying those checks to

  1. Check in non-ignored files first
  2. If some required file is not found, check the ignored stuff, just in case, and print out something useful (example above) if the mandatory file was ignored.

This would allow users to check for other issues while keeping something temporarily ignored for their own reasons.

And then I'd simply remove mandatory_files from config.py. Let me know if this design sounds ok

@AndreiDurlea AndreiDurlea changed the title Config file for beman-tidy Implemented a config file for beman-tidy Feb 15, 2026
@AndreiDurlea AndreiDurlea force-pushed the origin/andreidurlea-issue227 branch from cff2eb3 to c89a623 Compare February 15, 2026 23:47
Copy link
Member

@neatudarius neatudarius left a comment

Choose a reason for hiding this comment

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

Initial round of review

* `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).
Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds like better design. Will work on implementing it 👍🏻

Copy link
Member Author

@AndreiDurlea AndreiDurlea Feb 16, 2026

Choose a reason for hiding this comment

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

Done! Is it ok?

"""

def __init__(self, repo_info, beman_standard_check_config, relative_path, name=None):
self.repo_info = repo_info
Copy link
Member

Choose a reason for hiding this comment

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

Check super().__init__(repo_info, beman_standard_check_config, name=name). It is doing what you need, right?

Copy link
Member Author

@AndreiDurlea AndreiDurlea Feb 16, 2026

Choose a reason for hiding this comment

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

Okay so, after some investigative work:

  • repo_info is (was) not available at init
  • when I implemented should_skip() which calls get_ignroes(self.repo_info)which requires, of course, repo_info, a crash would happen
  • I half-fixed that problem by just setting repo_info myself

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.

Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand why current status from main is not enough?

TLDR: first line in any class that is derived needs to be called to super!

Copy link
Member Author

@AndreiDurlea AndreiDurlea Feb 19, 2026

Choose a reason for hiding this comment

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

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 =)))

@AndreiDurlea
Copy link
Member Author

@neatudarius I applied your changes, ready for another round of review.
Mention: I'm working on the deeper bugfix to remove the temporary fix provided by L19 in file_base_check.py. Awaiting your response in the comment thread on that line.

"""

def __init__(self, repo_info, beman_standard_check_config, relative_path, name=None):
self.repo_info = repo_info
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand why current status from main is not enough?

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 =)
@AndreiDurlea AndreiDurlea force-pushed the origin/andreidurlea-issue227 branch from 22d8e39 to 96abdb0 Compare February 19, 2026 21:59
@AndreiDurlea
Copy link
Member Author

@neatudarius ready for a re-review

"""
if super().should_skip():
return True
return is_ignored(self.repo_info, self.relative_path)
Copy link
Member

Choose a reason for hiding this comment

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

Excellent!

Load the configuration file.
"""
# Load default configuration
default_config_path = files('beman_tidy').joinpath('.beman-tidy.yml')
Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

Please test the installed tool. Does it work in your approach?

Copy link
Member Author

@AndreiDurlea AndreiDurlea Feb 23, 2026

Choose a reason for hiding this comment

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

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`
@AndreiDurlea AndreiDurlea force-pushed the origin/andreidurlea-issue227 branch from 5e973e4 to b8cb760 Compare February 23, 2026 23:26
@AndreiDurlea
Copy link
Member Author

@neatudarius yet again ready for a re-review

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.

2 participants