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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: mixed-line-ending
- id: debug-statements
- id: destroyed-symlinks
- id: fix-byte-order-marker
- id: check-merge-conflict
- id: name-tests-test
args: [--pytest-test-first]

- repo: https://github.com/pycqa/flake8
rev: '7.2.0'
hooks:
- id: flake8

- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: "v1.15.0"
hooks:
- id: mypy
args: []
exclude: tests/
additional_dependencies:
- pyparsing
- types-psutil
- pyzmq
2 changes: 1 addition & 1 deletion OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def sendExpression(self, command, parsed=True):
logger.warning("Result of 'getMessagesStringInternal()' cannot be parsed - set parsed to False!")
parsed = False
else:
# allways check for error
# always check for error
self._omc.send_string('getMessagesStringInternal()', flags=zmq.NOBLOCK)
error_raw = self._omc.recv_string()
# run error handling only if there is something to check
Expand Down
36 changes: 16 additions & 20 deletions OMPython/OMParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,13 @@ def make_elements(strings):
skip_start = index + 1
if strings[skip_start] == "{":
skip_brace += 1
indx = skip_start
while indx < len(strings):
char = strings[indx]
for i in range(skip_start, len(strings)):
char = strings[i]
if char == "}":
skip_brace -= 1
if skip_brace == 0:
index = indx + 1
index = i + 1
break
indx += 1

index += 1

Expand Down Expand Up @@ -522,21 +520,21 @@ def make_elements(strings):


def check_for_next_string(next_string):
anchorr = 0
positionn = 0
stopp = 0
anchor = 0
position = 0
stop = 0

# remove braces & keep only the SET's values
while positionn < len(next_string):
check_str = next_string[positionn]
while position < len(next_string):
check_str = next_string[position]
if check_str == "{":
anchorr = positionn
anchor = position
elif check_str == "}":
stopp = positionn
delStr = next_string[anchorr:stopp + 1]
stop = position
delStr = next_string[anchor:stop + 1]
next_string = next_string.replace(delStr, '')
positionn = -1
positionn += 1
position = -1
position += 1

if isinstance(next_string, str):
if len(next_string) == 0:
Expand Down Expand Up @@ -615,16 +613,14 @@ def skip_all_inner_sets(position):
if brace_count == 0:
break
elif s == "=" and string[position + 1] == "{":
indx = position + 2
skip_brace = 1
while indx < end_of_main_set:
char = string[indx]
for i in range(position + 2, end_of_main_set):
char = string[i]
if char == "}":
skip_brace -= 1
if skip_brace == 0:
position = indx + 1
position = i + 1
break
indx += 1
position += 1
position += 1
elif char == "{" and string[position + 1] == "{":
Expand Down
1 change: 0 additions & 1 deletion OMPython/OMTypedParser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Anand Kalaiarasi Ganeson, ganan642@student.liu.se, 2012-03-19, and Martin Sjölund"
__license__ = """
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ online.
- Submit bugs through the [OpenModelica GitHub issues](https://github.com/OpenModelica/OMPython/issues/new).
- [Pull requests](https://github.com/OpenModelica/OMPython/pulls) are welcome.


## Development
It is recommended to set up [`pre-commit`](https://pre-commit.com/) to
automatically run linters:
```sh
# cd to the root of the repository
pre-commit install
```

## Contact

- Adeel Asghar, <adeel.asghar@liu.se>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ArrayDimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# do not change the prefix class name, the class name should have prefix "Test"
# according to the documenation of pytest
# according to the documentation of pytest
class Test_ArrayDimension:
def test_ArrayDimension(self):
omc = OMPython.OMCSessionZMQ()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_FMIRegression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# do not change the prefix class name, the class name should have prefix "Test"
# according to the documenation of pytest
# according to the documentation of pytest
class Test_FMIRegression:

def buildModelFMU(self, modelName):
Expand Down
Loading