Skip to content

Commit 6cbee29

Browse files
lint and format
1 parent 08233b6 commit 6cbee29

10 files changed

Lines changed: 71 additions & 61 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ruff-lint:
1111

1212
pylint:
1313
@echo Running pylint check...
14-
@pylint .
14+
@pylint examples/ rocketserializer/ tests/
1515
@echo Pylint check completed.
1616

1717
lint: ruff-lint pylint

destroy-the-bank.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ def destroy_the_bank(file):
4747
for file in ork_files:
4848
try:
4949
destroy_the_bank(file)
50-
except Exception as e:
50+
except Exception:
5151
# Log any unexpected exceptions
5252
logging.exception(f"An unexpected error occurred in file: {file}")

examples/EPFL--BellaLui--2020/simulation.ipynb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30+
"import datetime\n",
31+
"\n",
3032
"from rocketpy import (\n",
3133
" Environment,\n",
32-
" SolidMotor,\n",
33-
" Rocket,\n",
3434
" Flight,\n",
35-
" TrapezoidalFins,\n",
36-
" EllipticalFins,\n",
37-
" RailButtons,\n",
3835
" NoseCone,\n",
36+
" Rocket,\n",
37+
" SolidMotor,\n",
3938
" Tail,\n",
40-
" Parachute,\n",
41-
")\n",
42-
"import datetime"
39+
" TrapezoidalFins,\n",
40+
")"
4341
]
4442
},
4543
{
@@ -510,7 +508,11 @@
510508
]
511509
}
512510
],
513-
"metadata": {},
511+
"metadata": {
512+
"language_info": {
513+
"name": "python"
514+
}
515+
},
514516
"nbformat": 4,
515517
"nbformat_minor": 5
516518
}

examples/NDRT--Rocket--2020/simulation.ipynb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30+
"import datetime\n",
31+
"\n",
3032
"from rocketpy import (\n",
3133
" Environment,\n",
32-
" SolidMotor,\n",
33-
" Rocket,\n",
3434
" Flight,\n",
35-
" TrapezoidalFins,\n",
36-
" EllipticalFins,\n",
37-
" RailButtons,\n",
3835
" NoseCone,\n",
39-
" Tail,\n",
4036
" Parachute,\n",
41-
")\n",
42-
"import datetime"
37+
" Rocket,\n",
38+
" SolidMotor,\n",
39+
" Tail,\n",
40+
" TrapezoidalFins,\n",
41+
")"
4342
]
4443
},
4544
{
@@ -541,7 +540,11 @@
541540
]
542541
}
543542
],
544-
"metadata": {},
543+
"metadata": {
544+
"language_info": {
545+
"name": "python"
546+
}
547+
},
545548
"nbformat": 4,
546549
"nbformat_minor": 5
547550
}

examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": 24,
34+
"execution_count": null,
3535
"id": "20ba7738",
3636
"metadata": {},
3737
"outputs": [],
3838
"source": [
39+
"import datetime\n",
40+
"\n",
3941
"from rocketpy import (\n",
4042
" Environment,\n",
41-
" SolidMotor,\n",
42-
" Rocket,\n",
4343
" Flight,\n",
44-
" TrapezoidalFins,\n",
45-
" EllipticalFins,\n",
46-
" RailButtons,\n",
4744
" NoseCone,\n",
48-
" Tail,\n",
4945
" Parachute,\n",
50-
")\n",
51-
"import datetime"
46+
" Rocket,\n",
47+
" SolidMotor,\n",
48+
" TrapezoidalFins,\n",
49+
")"
5250
]
5351
},
5452
{

rocketserializer/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .ork_extractor import ork_extractor
2+
3+
__all__ = ["ork_extractor"]

rocketserializer/nb_builder.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ def build_fins(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
329329
text = "trapezoidal_fins = {}\n"
330330
nb["cells"].append(nbf.v4.new_code_cell(text))
331331
for i in range(len(self.parameters["trapezoidal_fins"])):
332-
333332
trapezoidal_fins_i = self.parameters["trapezoidal_fins"][str(i)]
334333

335334
number = trapezoidal_fins_i["number"]
@@ -365,7 +364,6 @@ def build_fins(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
365364
text = "elliptical_fins = {}\n"
366365
nb["cells"].append(nbf.v4.new_code_cell(text))
367366
for i in range(len(self.parameters["elliptical_fins"])):
368-
369367
elliptical_fins_i = self.parameters["elliptical_fins"][str(i)]
370368

371369
number = elliptical_fins_i["number"]
@@ -410,7 +408,6 @@ def build_tails(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
410408
text = "tails = {}\n"
411409
nb["cells"].append(nbf.v4.new_code_cell(text))
412410
for i in range(len(self.parameters["tails"])):
413-
414411
tail_i = self.parameters["tails"][str(i)]
415412

416413
top_radius = tail_i["top_radius"]
@@ -467,7 +464,6 @@ def build_parachute(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
467464
text = "parachutes = {}\n"
468465
nb["cells"].append(nbf.v4.new_code_cell(text))
469466
for i in range(len(self.parameters["parachutes"])):
470-
471467
parachute_i = self.parameters["parachutes"][str(i)]
472468
cd_s = parachute_i["cd"] * parachute_i["area"]
473469
deploy_event = parachute_i["deploy_event"]

rocketserializer/openrocket_runtime.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ def ensure_java_compatibility(jar_path: Path):
106106
default_jvm_major = None
107107
try:
108108
default_jvm_major = _extract_java_major(jpype.getDefaultJVMPath())
109-
except Exception:
109+
except (
110+
jpype.JVMNotFoundException,
111+
jpype.JVMNotSupportedException,
112+
OSError,
113+
):
110114
default_jvm_major = None
111115

112116
if default_jvm_major and default_jvm_major >= required_major:
@@ -156,7 +160,7 @@ def _resolve_packages(self):
156160
legacy = jpype.JPackage("net").sf.openrocket
157161
_ = legacy.startup.Application
158162
return legacy, legacy
159-
except Exception:
163+
except (AttributeError, TypeError, RuntimeError):
160164
modern = jpype.JPackage("info").openrocket
161165
return modern.core, modern.swing
162166

@@ -168,10 +172,10 @@ def _block_loader(gui_module, field_name):
168172
loader = field.get(gui_module)
169173
field.setAccessible(False)
170174
loader.blockUntilLoaded()
171-
except Exception:
175+
except (AttributeError, TypeError, RuntimeError, jpype.JException):
172176
# New OpenRocket versions can change internals; loading still works
173177
# without explicitly waiting in most cases.
174-
return
178+
pass
175179

176180
def __enter__(self):
177181
ensure_java_compatibility(self.jar_path)
@@ -222,7 +226,7 @@ def __exit__(self, ex_type, ex, tb):
222226
try:
223227
for window in jpype.java.awt.Window.getWindows():
224228
window.dispose()
225-
except Exception:
229+
except (AttributeError, TypeError, RuntimeError, jpype.JException):
226230
pass
227231
jpype.shutdownJVM()
228232
finally:

tests/acceptance/test_ork_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
def test_ork_extractor(expected_results_file, fixture, request):
1818
# load the expected results
19-
with open(expected_results_file, "r") as f:
19+
with open(expected_results_file, "r", encoding="utf-8") as f:
2020
expected_results = json.load(f)
2121

2222
# get the settings from the fixture

tests/conftest.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,55 @@
1212
ROOT_DIR = Path(__file__).resolve().parents[1]
1313

1414

15-
def get_settings(filepath, output, ork):
16-
bs, _ = parse_ork_file(filepath)
15+
def get_settings(ork_filepath, output_dir, ork_document):
16+
bs, _ = parse_ork_file(ork_filepath)
1717

18-
output.mkdir(parents=True, exist_ok=True)
18+
output_dir.mkdir(parents=True, exist_ok=True)
1919

2020
settings = ork_extractor(
2121
bs=bs,
22-
filepath=str(filepath),
23-
output_folder=str(output),
24-
ork=ork,
22+
filepath=str(ork_filepath),
23+
output_folder=str(output_dir),
24+
ork=ork_document,
2525
)
2626
return settings
2727

2828

2929
with OpenRocketSession(select_latest_openrocket_jar(ROOT_DIR), "OFF") as session:
30-
3130
# Valetudo 2019
32-
filepath = ROOT_DIR / "examples" / "ProjetoJupiter--Valetudo--2019" / "rocket.ork"
33-
filepath = extract_ork_from_zip(filepath, filepath.parent)
34-
output = ROOT_DIR / "tests" / "acceptance" / "ProjetoJupiter--Valetudo--2019"
35-
ork = session.load_doc(str(filepath))
36-
settings1 = get_settings(filepath, output, ork)
31+
valetudo_filepath = (
32+
ROOT_DIR / "examples" / "ProjetoJupiter--Valetudo--2019" / "rocket.ork"
33+
)
34+
valetudo_filepath = extract_ork_from_zip(
35+
valetudo_filepath, valetudo_filepath.parent
36+
)
37+
valetudo_output_dir = (
38+
ROOT_DIR / "tests" / "acceptance" / "ProjetoJupiter--Valetudo--2019"
39+
)
40+
valetudo_doc = session.load_doc(str(valetudo_filepath))
41+
settings1 = get_settings(valetudo_filepath, valetudo_output_dir, valetudo_doc)
3742

3843
@pytest.fixture()
3944
def valetudo_settings():
4045
return settings1
4146

4247
# NDRT 2020
43-
filepath = ROOT_DIR / "examples" / "NDRT--Rocket--2020" / "rocket.ork"
44-
filepath = extract_ork_from_zip(filepath, filepath.parent)
45-
output = ROOT_DIR / "tests" / "acceptance" / "NDRT--Rocket--2020"
46-
ork = session.load_doc(str(filepath))
47-
settings2 = get_settings(filepath, output, ork)
48+
ndrt_filepath = ROOT_DIR / "examples" / "NDRT--Rocket--2020" / "rocket.ork"
49+
ndrt_filepath = extract_ork_from_zip(ndrt_filepath, ndrt_filepath.parent)
50+
ndrt_output_dir = ROOT_DIR / "tests" / "acceptance" / "NDRT--Rocket--2020"
51+
ndrt_doc = session.load_doc(str(ndrt_filepath))
52+
settings2 = get_settings(ndrt_filepath, ndrt_output_dir, ndrt_doc)
4853

4954
@pytest.fixture()
5055
def ndrt_settings():
5156
return settings2
5257

5358
# Bella Lui 2020
54-
filepath = ROOT_DIR / "examples" / "EPFL--BellaLui--2020" / "rocket.ork"
55-
filepath = extract_ork_from_zip(filepath, filepath.parent)
56-
output = ROOT_DIR / "tests" / "acceptance" / "EPFL--BellaLui--2020"
57-
ork = session.load_doc(str(filepath))
58-
settings3 = get_settings(filepath, output, ork)
59+
epfl_filepath = ROOT_DIR / "examples" / "EPFL--BellaLui--2020" / "rocket.ork"
60+
epfl_filepath = extract_ork_from_zip(epfl_filepath, epfl_filepath.parent)
61+
epfl_output_dir = ROOT_DIR / "tests" / "acceptance" / "EPFL--BellaLui--2020"
62+
epfl_doc = session.load_doc(str(epfl_filepath))
63+
settings3 = get_settings(epfl_filepath, epfl_output_dir, epfl_doc)
5964

6065
@pytest.fixture()
6166
def epfl_settings():

0 commit comments

Comments
 (0)