Skip to content

Commit 18f3b2f

Browse files
committed
Format with ruff
1 parent 1d9d6cb commit 18f3b2f

File tree

10 files changed

+428
-265
lines changed

10 files changed

+428
-265
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- run: ruff check
1515
- run: ruff format --check --diff
1616
build-win32-binaries:
17+
needs: [lint]
1718
runs-on: windows-2022
1819
steps:
1920
- uses: actions/checkout@v4
@@ -25,6 +26,7 @@ jobs:
2526
path: ./FMI/Resources/Library/win32/ModelicaFMI.dll
2627
if-no-files-found: error
2728
build-win64-binaries:
29+
needs: [lint]
2830
runs-on: windows-2022
2931
steps:
3032
- uses: actions/checkout@v4
@@ -36,6 +38,7 @@ jobs:
3638
path: ./FMI/Resources/Library/win64/ModelicaFMI.dll
3739
if-no-files-found: error
3840
build-linux64-binaries:
41+
needs: [lint]
3942
runs-on: ubuntu-22.04
4043
steps:
4144
- uses: actions/checkout@v4
@@ -47,6 +50,7 @@ jobs:
4750
path: ./FMI/Resources/Library/linux64/libModelicaFMI.so
4851
if-no-files-found: error
4952
build-darwin64-binaries:
53+
needs: [lint]
5054
runs-on: macos-13
5155
steps:
5256
- uses: actions/checkout@v4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.6'
1+
__version__ = "0.0.6"
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
""" Entry point for the command line interface """
2-
3-
4-
if __name__ == '__main__':
1+
"""Entry point for the command line interface"""
52

3+
if __name__ == "__main__":
64
from modelica_fmi import cli
75

86
cli.main()
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
"""The Command Line Interface (CLI)"""
22

3-
def main():
43

4+
def main():
55
import argparse
66
from . import __version__ as version
77
from .import_fmu_to_modelica import import_fmu_to_modelica
88

99
parser = argparse.ArgumentParser(
10-
prog='modelica-fmi',
10+
prog="modelica-fmi",
1111
description="Import an FMU into a Modelica library",
12-
formatter_class=argparse.RawDescriptionHelpFormatter
12+
formatter_class=argparse.RawDescriptionHelpFormatter,
1313
)
1414

15-
parser.add_argument('-v', '--version', action='version', version=f'%(prog)s version {version}', help="print the program version")
15+
parser.add_argument(
16+
"-v",
17+
"--version",
18+
action="version",
19+
version=f"%(prog)s version {version}",
20+
help="print the program version",
21+
)
1622

17-
parser.add_argument('fmu_path', help="Path of the FMU to import")
18-
parser.add_argument('model_path', help="Path of the Modelica file to generate")
23+
parser.add_argument("fmu_path", help="Path of the FMU to import")
24+
parser.add_argument("model_path", help="Path of the Modelica file to generate")
1925

2026
args = parser.parse_args()
2127

22-
import_fmu_to_modelica(fmu_path=args.fmu_path, model_path=args.model_path, interface_type='CoSimulation')
28+
import_fmu_to_modelica(
29+
fmu_path=args.fmu_path,
30+
model_path=args.model_path,
31+
interface_type="CoSimulation",
32+
)

modelica_fmi/src/modelica_fmi/cross_check.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,41 @@
66

77
models = [
88
[
9-
'Dymola',
9+
"Dymola",
1010
[
11-
('https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi2_Dassl.fmu', '3f2dfb10c7ee6b7a1c16a51e6f2c34796bf47b0e7d62342922170dbee79461eb'),
12-
('https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi3_Dassl.fmu', 'b45f7f2d71ad2f29f1af24de82b518c98feb53e57a0ad9680e079dcfbc758923'),
11+
(
12+
"https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi2_Dassl.fmu",
13+
"3f2dfb10c7ee6b7a1c16a51e6f2c34796bf47b0e7d62342922170dbee79461eb",
14+
),
15+
(
16+
"https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi3_Dassl.fmu",
17+
"b45f7f2d71ad2f29f1af24de82b518c98feb53e57a0ad9680e079dcfbc758923",
18+
),
1319
],
1420
],
1521
[
16-
'Dymola',
22+
"Dymola",
1723
[
18-
('https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi2_Dassl.fmu', '3f2dfb10c7ee6b7a1c16a51e6f2c34796bf47b0e7d62342922170dbee79461eb'),
19-
('https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi3_Dassl.fmu', 'b45f7f2d71ad2f29f1af24de82b518c98feb53e57a0ad9680e079dcfbc758923'),
24+
(
25+
"https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi2_Dassl.fmu",
26+
"3f2dfb10c7ee6b7a1c16a51e6f2c34796bf47b0e7d62342922170dbee79461eb",
27+
),
28+
(
29+
"https://github.com/CATIA-Systems/dymola-fmi-compatibility/raw/refs/heads/main/2025x%20Refresh%201,%202025-04-11/CoupledClutches_fmi3_Dassl.fmu",
30+
"b45f7f2d71ad2f29f1af24de82b518c98feb53e57a0ad9680e079dcfbc758923",
31+
),
2032
],
2133
],
2234
]
2335

2436

2537
def import_dymola_fmus():
26-
2738
for url, checksum in models:
2839
filename = download_file(url, checksum)
2940
model_name, _ = os.path.splitext(filename)
30-
model_path = rf'E:\WS\Modelica-FMI\FMI\Tests\Dymola\{model_name}.mo'
41+
model_path = rf"E:\WS\Modelica-FMI\FMI\Tests\Dymola\{model_name}.mo"
3142
import_fmu_to_modelica(filename, model_path)
3243

33-
if __name__ == '__main__':
44+
45+
if __name__ == "__main__":
3446
import_dymola_fmus()

modelica_fmi/src/modelica_fmi/generate_examples.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,69 @@
33

44

55
def generate_examples():
6-
76
from fmpy import extract
87
from fmpy.util import download_file
98
from pathlib import Path
109
from .import_fmu_to_modelica import import_fmu_to_modelica
1110

12-
url = 'https://github.com/modelica/Reference-FMUs/releases/download/v0.0.38/Reference-FMUs-0.0.38.zip'
13-
checksum = 'dc3d1467ddea24cf6d171f7eb4d790d7d6f3f7b8856cf76c0cd832c78e8e629a'
11+
url = "https://github.com/modelica/Reference-FMUs/releases/download/v0.0.38/Reference-FMUs-0.0.38.zip"
12+
checksum = "dc3d1467ddea24cf6d171f7eb4d790d7d6f3f7b8856cf76c0cd832c78e8e629a"
1413
archive = download_file(url=url, checksum=checksum)
1514

1615
dist = Path(extract(archive))
1716

18-
examples_dir = Path(__file__).parent.parent.parent.parent / 'FMI' / 'Examples'
17+
examples_dir = Path(__file__).parent.parent.parent.parent / "FMI" / "Examples"
1918

2019
shutil.rmtree(examples_dir, ignore_errors=True)
2120

2221
os.makedirs(examples_dir)
2322

24-
with open(examples_dir / 'package.mo', 'w') as file:
23+
with open(examples_dir / "package.mo", "w") as file:
2524
file.write("""within FMI;
2625
package Examples
2726
extends Modelica.Icons.ExamplesPackage;
2827
end Examples;
2928
""")
3029

31-
with open(examples_dir.parent / 'package.order', 'r') as f:
30+
with open(examples_dir.parent / "package.order", "r") as f:
3231
package_order = list(map(lambda line: line.strip(), f.readlines()))
3332

34-
if 'Examples' not in package_order:
35-
with open(examples_dir.parent / 'package.order', 'a') as file:
33+
if "Examples" not in package_order:
34+
with open(examples_dir.parent / "package.order", "a") as file:
3635
file.write("Examples\n")
3736

3837
for fmi_version in [2, 3]:
38+
os.makedirs(examples_dir / f"FMI{fmi_version}")
3939

40-
os.makedirs(examples_dir / f'FMI{fmi_version}')
41-
42-
with open(examples_dir / f'FMI{fmi_version}' / 'package.mo', 'w') as file:
40+
with open(examples_dir / f"FMI{fmi_version}" / "package.mo", "w") as file:
4341
file.write(f"""within FMI.Examples;
4442
package FMI{fmi_version}
4543
extends Modelica.Icons.ExamplesPackage;
4644
end FMI{fmi_version};
4745
""")
4846

49-
with open(examples_dir / 'package.order', 'a') as file:
47+
with open(examples_dir / "package.order", "a") as file:
5048
file.write(f"FMI{fmi_version}\n")
5149

52-
models = ['BouncingBall', 'Dahlquist', 'Feedthrough', 'Stair', 'Resource', 'VanDerPol']
50+
models = [
51+
"BouncingBall",
52+
"Dahlquist",
53+
"Feedthrough",
54+
"Stair",
55+
"Resource",
56+
"VanDerPol",
57+
]
5358

5459
if fmi_version == 3:
55-
models.append('StateSpace')
60+
models.append("StateSpace")
5661

5762
for model in models:
5863
import_fmu_to_modelica(
59-
fmu_path=dist / f'{fmi_version}.0' / f'{model}.fmu',
60-
model_path=examples_dir / f'FMI{fmi_version}' / f'{model}.mo',
61-
interface_type='CoSimulation',
64+
fmu_path=dist / f"{fmi_version}.0" / f"{model}.fmu",
65+
model_path=examples_dir / f"FMI{fmi_version}" / f"{model}.mo",
66+
interface_type="CoSimulation",
6267
)
6368

6469

65-
if __name__ == '__main__':
70+
if __name__ == "__main__":
6671
generate_examples()

modelica_fmi/src/modelica_fmi/generate_functions.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,79 @@
33
import jinja2
44

55

6-
loader = jinja2.FileSystemLoader(searchpath=Path(__file__).parent / 'templates')
6+
loader = jinja2.FileSystemLoader(searchpath=Path(__file__).parent / "templates")
77

88
environment = jinja2.Environment(
99
loader=loader,
1010
trim_blocks=True,
11-
block_start_string='@@',
12-
block_end_string='@@',
13-
variable_start_string='@=',
14-
variable_end_string='=@'
11+
block_start_string="@@",
12+
block_end_string="@@",
13+
variable_start_string="@=",
14+
variable_end_string="=@",
1515
)
1616

17-
library_dir = Path(__file__).parent.parent.parent.parent / 'FMI'
18-
19-
for variable_type, prefix in product(['Real', 'Integer', 'Boolean', 'String'], ['Get', 'Set']):
17+
library_dir = Path(__file__).parent.parent.parent.parent / "FMI"
2018

19+
for variable_type, prefix in product(
20+
["Real", "Integer", "Boolean", "String"], ["Get", "Set"]
21+
):
2122
for package, level in [
22-
(library_dir / 'FMI2' / 'Functions', ''),
23-
(library_dir / 'Internal' / 'FMI2', 'Internal')
23+
(library_dir / "FMI2" / "Functions", ""),
24+
(library_dir / "Internal" / "FMI2", "Internal"),
2425
]:
26+
template = environment.get_template(f"FMI2_{level}{prefix}.mo")
2527

26-
template = environment.get_template(f'FMI2_{level}{prefix}.mo')
27-
28-
class_text = template.render(
29-
variable_type=variable_type
30-
)
28+
class_text = template.render(variable_type=variable_type)
3129

32-
function_name = f'FMI2{prefix}{variable_type}'
30+
function_name = f"FMI2{prefix}{variable_type}"
3331

34-
with open(package / f'{function_name}.mo', 'w') as f:
32+
with open(package / f"{function_name}.mo", "w") as f:
3533
f.write(class_text)
3634

37-
package_order_file = package / 'package.order'
35+
package_order_file = package / "package.order"
3836

39-
with open(package_order_file, 'r') as f:
37+
with open(package_order_file, "r") as f:
4038
package_order = list(map(lambda line: line.strip(), f.readlines()))
4139

4240
if function_name not in package_order:
43-
with open(package_order_file, 'a') as f:
44-
f.write(function_name + '\n')
41+
with open(package_order_file, "a") as f:
42+
f.write(function_name + "\n")
4543

4644
for variable_type, (prefix, suffix) in product(
47-
['Float32', 'Float64', 'Int8', 'UInt8', 'Int16', 'UInt16', 'Int32', 'UInt32', 'Int64', 'UInt64', 'Boolean', 'String'],
48-
[('Get', ''), ('Set', ''), ('Get', 'Matrix'), ('Set', 'Matrix')]
45+
[
46+
"Float32",
47+
"Float64",
48+
"Int8",
49+
"UInt8",
50+
"Int16",
51+
"UInt16",
52+
"Int32",
53+
"UInt32",
54+
"Int64",
55+
"UInt64",
56+
"Boolean",
57+
"String",
58+
],
59+
[("Get", ""), ("Set", ""), ("Get", "Matrix"), ("Set", "Matrix")],
4960
):
50-
5161
for package, level in [
52-
(library_dir / 'FMI3' / 'Functions', ''),
53-
(library_dir / 'Internal' / 'FMI3', 'Internal')
62+
(library_dir / "FMI3" / "Functions", ""),
63+
(library_dir / "Internal" / "FMI3", "Internal"),
5464
]:
65+
template = environment.get_template(f"FMI3_{level}{prefix}{suffix}.mo")
5566

56-
template = environment.get_template(f'FMI3_{level}{prefix}{suffix}.mo')
57-
58-
class_text = template.render(
59-
variable_type=variable_type
60-
)
67+
class_text = template.render(variable_type=variable_type)
6168

62-
function_name = f'FMI3{prefix}{variable_type}{suffix}'
69+
function_name = f"FMI3{prefix}{variable_type}{suffix}"
6370

64-
with open(package / f'{function_name}.mo', 'w') as f:
71+
with open(package / f"{function_name}.mo", "w") as f:
6572
f.write(class_text)
6673

67-
package_order_file = package / 'package.order'
74+
package_order_file = package / "package.order"
6875

69-
with open(package_order_file, 'r') as f:
76+
with open(package_order_file, "r") as f:
7077
package_order = list(map(lambda line: line.strip(), f.readlines()))
7178

7279
if function_name not in package_order:
73-
with open(package_order_file, 'a') as f:
74-
f.write(function_name + '\n')
80+
with open(package_order_file, "a") as f:
81+
f.write(function_name + "\n")

0 commit comments

Comments
 (0)