bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
896 stars 250 forks source link

Make better use of pre-commit #2288

Closed LDprg closed 1 week ago

LDprg commented 3 weeks ago

This PR adds some useful pre-commit stuff since powercalc is already using it for ruff. I added some handy checks for broken stuff (symlinks, line endings, etc.) and some formatting. The official pre-commit-hooks are added and the formatter of ruff and auto fix for the linter are enabled.

Important file is .pre-commit-config.yaml All other files are autofixed by the pre-commit or some few manual fixes for the checks (f.e. broken symlinks, shebangs, permissions). Sadly fixes are really blown up by the auto fixes (especially by the trailing-whitespace hook).

You could also consider adding the pre-commit CI/CD (lite or full both are free for open source). This allows automatic pr checks/autofixes and stats about pre-commit.

This PR should really cleanup the whole project code base. I haven't tested the code after all the auto fixes. In theory there shouldn't be any stuff that changed from a code wise perspective. The pre-commit CI/CD would also help keep code clean, because PRs that do not install pre-commit would mix code and auto fixes (pre-commit CI/CD prevents this).

LDprg commented 3 weeks ago

Seems like I broke the "LUT file validation / Add plot to PR" action. I am not exactly sure what did broke and why (only a strange log message). But I am also not sure what it actually does.

If anyone has an idea whats going please ping me!

LDprg commented 3 weeks ago

Ok I worked the problem out! The script doesn't handles filenames with spaces correctly. Will make a patch for this.

LDprg commented 3 weeks ago

Patch is included in the PR (just a small script change that replaces spaces with a proper escape sequence). Github actions is however not using the new action.

bramstroker commented 2 weeks ago

Could you please rebase with master? should hopefully fix the broken actions.

bramstroker commented 1 week ago

Could you rebase / resolve conflicts final time? When no CI/CD issues I will merge today.

LDprg commented 1 week ago

The "Generate support model list / Generate list (pull_request)" is now failing too seems related to some github secret?

LDprg commented 1 week ago

I missed to add escape sequence for brackets in the filenames. Created a second pr fixing the LUT action.

bramstroker commented 1 week ago

Let's merge. We'll see how the actions on master branch runs.

bramstroker commented 1 week ago

Precommit was working correctly for me. Very nice!

Screenshot 2024-06-23 at 09 17 45
LDprg commented 1 week ago

@bramstroker you might want to add the precommit.ci bot for automatic PR checks.

https://pre-commit.ci/

bramstroker commented 1 week ago

@bramstroker you might want to add the precommit.ci bot for automatic PR checks.

https://pre-commit.ci/

Will have a look into that. Also mypy checks must still be added to precommit.

bramstroker commented 1 week ago

precommit ci has been activated btw