Skip to content

Set up pre-commit #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 18, 2025
Merged

Set up pre-commit #289

merged 7 commits into from
Jun 18, 2025

Conversation

ondras12345
Copy link
Contributor

Proposal

pre-commit is a nice tool that can be used to run various linters before each commit is made.
This PR adds a .pre-commit-config.yaml with a basic set of checks and linters. It also fixes typos detected by the codespell check.

Currently, the mypy check fails:

$ pre-commit run --all-files
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for case conflicts.................................................Passed
check docstring is first.................................................Passed
check that executables have shebangs.................(no files to check)Skipped
check that scripts with shebangs are executable..........................Passed
mixed line ending........................................................Passed
debug statements (python)................................................Passed
detect destroyed symlinks................................................Passed
fix utf-8 byte order marker..............................................Passed
check for merge conflicts................................................Passed
python tests naming......................................................Passed
flake8...................................................................Passed
codespell................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

OMPython/OMParser.py:37: error: Need type annotation for "result" (hint: "result: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/OMTypedParser.py:112: error: Argument 1 has incompatible type "bool"; expected "str"  [arg-type]
OMPython/OMTypedParser.py:113: error: Argument 1 has incompatible type "bool"; expected "str"  [arg-type]
OMPython/OMTypedParser.py:114: error: Argument 1 has incompatible type "None"; expected "str"  [arg-type]
OMPython/OMCSession.py:92: error: Need type annotation for "_omc_cache" (hint: "_omc_cache: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/OMCSession.py:278: error: Incompatible default for argument "omhome" (default has type "None", argument has type "str")  [assignment]
OMPython/OMCSession.py:278: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
OMPython/OMCSession.py:278: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
OMPython/OMCSession.py:462: error: Incompatible default for argument "omhome" (default has type "None", argument has type "str")  [assignment]
OMPython/OMCSession.py:462: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
OMPython/OMCSession.py:462: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
OMPython/ModelicaSystem.py:44: error: Cannot find implementation or library stub for module named "numpy"  [import-not-found]
OMPython/ModelicaSystem.py:44: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
OMPython/ModelicaSystem.py:366: error: Need type annotation for "quantitiesList" (hint: "quantitiesList: list[<type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:367: error: Need type annotation for "paramlist" (hint: "paramlist: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:368: error: Need type annotation for "inputlist" (hint: "inputlist: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:369: error: Need type annotation for "outputlist" (hint: "outputlist: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:370: error: Need type annotation for "continuouslist" (hint: "continuouslist: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:371: error: Need type annotation for "simulateOptions" (hint: "simulateOptions: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:372: error: Need type annotation for "overridevariables" (hint: "overridevariables: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:373: error: Need type annotation for "simoptionsoverride" (hint: "simoptionsoverride: dict[<type>, <type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:377: error: Need type annotation for "linearinputs" (hint: "linearinputs: list[<type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:378: error: Need type annotation for "linearoutputs" (hint: "linearoutputs: list[<type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:379: error: Need type annotation for "linearstates" (hint: "linearstates: list[<type>] = ...")  [var-annotated]
OMPython/ModelicaSystem.py:386: error: Argument "omhome" to "OMCSessionZMQ" has incompatible type "str | None"; expected "str"  [arg-type]
OMPython/ModelicaSystem.py:389: error: Argument "commandLineOptions" to "setCommandLineOptions" of "ModelicaSystem" has incompatible type "str | None"; expected "str"  [arg-type]
OMPython/ModelicaSystem.py:826: error: Argument "modelname" to "ModelicaSystemCmd" has incompatible type "str | None"; expected "str"  [arg-type]
OMPython/ModelicaSystem.py:830: error: Incompatible types in assignment (expression has type "Path", variable has type "None")  [assignment]
OMPython/ModelicaSystem.py:832: error: Incompatible types in assignment (expression has type "Path", variable has type "None")  [assignment]
OMPython/ModelicaSystem.py:834: error: Incompatible types in assignment (expression has type "Path", variable has type "None")  [assignment]
OMPython/ModelicaSystem.py:836: error: "None" has no attribute "as_posix"  [attr-defined]
OMPython/ModelicaSystem.py:868: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
OMPython/ModelicaSystem.py:870: error: "str" has no attribute "as_posix"  [attr-defined]
OMPython/ModelicaSystem.py:873: error: "None" has no attribute "is_file"  [attr-defined]
OMPython/ModelicaSystem.py:874: error: "None" has no attribute "unlink"  [attr-defined]
OMPython/ModelicaSystem.py:878: error: "None" has no attribute "is_file"  [attr-defined]
Found 31 errors in 4 files (checked 5 source files)

I think @syntron has fixed at least some of these in his fork. I think we should wait for them to be merged before proceeding with this PR.

In the future, we could configure the github actions test workflow to also run linters via pre-commit.

@syntron
Copy link
Contributor

syntron commented May 28, 2025

See status in #279 (comment) - 14 errors left:

  • 3 in OMTypedParser - Argument 1 has incompatible type ...
  • 11 in ModelicaSystem - Need type annotation for ...

I will prepare the needed changes as PR(s)

@syntron
Copy link
Contributor

syntron commented May 28, 2025

I will prepare the needed changes as PR(s)

Please see PR #290, #291, #292 and #294 to reach this point

@ondras12345 ondras12345 mentioned this pull request Jun 10, 2025
@adeas31 adeas31 added this to the 3.8.0 milestone Jun 11, 2025
@ondras12345
Copy link
Contributor Author

Rebased and fixed remaining mypy warnings. All tests in pre-commit run --all-files pass in 1.7 seconds on my PC. Seems reasonable.

@ondras12345 ondras12345 marked this pull request as ready for review June 11, 2025 21:02
@ondras12345
Copy link
Contributor Author

Updated to run pre-commit run --all-files in Github actions CI.

@syntron
Copy link
Contributor

syntron commented Jun 14, 2025

@ondras12345 Would you consider to modify this PR such that it comes without the following parts (changes to OMCSession.py) - these clash with PR #295 such that there are big merge conflicts; both points (mypy warning and spelling fix) are included ...

@ondras12345
Copy link
Contributor Author

@syntron I could do that, but it would cause this PR to fail its CI test run. It might be better to get your PR merged first and let me handle the conflicts here.

@ondras12345
Copy link
Contributor Author

@syntron Btw, I tried to rebase #295 onto this PR, and it wasn't that bad. Only two of your commits had conflicts, and it was enough to just accept your version. Rebased branch: https://github.com/ondras12345/OMPython/tree/pr_295_rebased

@ondras12345
Copy link
Contributor Author

Rebased to fix merge conflict.

@syntron
Copy link
Contributor

syntron commented Jun 16, 2025

@syntron Btw, I tried to rebase #295 onto this PR, and it wasn't that bad. Only two of your commits had conflicts, and it was enough to just accept your version. Rebased branch: https://github.com/ondras12345/OMPython/tree/pr_295_rebased

@ondras12345 I think the renames would conflict with any changes in these classes; perhaps I should stop working on ModelicaSystem.py such that it could settle and you do not have so much work ...

@adeas31 Do you know that the numbers at the ModelicaSystem methods refer to, i.e. # 21 and similar?

@adeas31
Copy link
Member

adeas31 commented Jun 17, 2025

@adeas31 Do you know that the numbers at the ModelicaSystem methods refer to, i.e. # 21 and similar?

No idea. @arun3688 might know.

@arun3688
Copy link
Collaborator

@adeas31 Do you know that the numbers at the ModelicaSystem methods refer to, i.e. # 21 and similar?

That does not have any meaning just to count the number of API i guess which was done by a student as part of this thesis, so you can ignore that or you can even remove those numbers

@adeas31 adeas31 modified the milestones: 3.8.0, 4.0.0 Jun 17, 2025
@ondras12345
Copy link
Contributor Author

Rebased, should be ready for review & merge.

@adeas31 adeas31 merged commit d87e46e into OpenModelica:master Jun 18, 2025
5 checks passed
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.

4 participants