Skip to content
Merged
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
14 changes: 8 additions & 6 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install ruff pylint pytest
pip install -r requirements.in
- uses: psf/black@stable
with:
options: "--check ."
jupyter: true
- name: Run ruff format check
run: |
ruff format --check .
- name: Run ruff lint
run: |
ruff check .
- name: Run pylint
run: |
pylint rocketserializer/
pylint examples/ rocketserializer/ tests/
2 changes: 1 addition & 1 deletion .github/workflows/test-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.9, 3.12]
python-version: [3.9, 3.11]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
lint: isort black
format:
@ruff check --select I --fix
@ruff format .
@echo Ruff formatting completed.

isort:
isort .

black:
black .
ruff-lint:
@echo Running ruff check...
@ruff check
@echo Ruff linter check completed.

pylint:
pylint rocketserializer/ --output="pylint_report.txt"
@echo Running pylint check...
@pylint examples/ rocketserializer/ tests/
@echo Pylint check completed.

lint: ruff-lint pylint

tests:
pytest
Expand All @@ -18,3 +25,7 @@ tests:

# tests-integration:

install:
pip install -r requirements.in
pip install -r requirements-dev.txt
pip install -e .
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pip install rocketserializer
### Java

You need Java to be installed on your system to use `rocketserializer`.
We recommend downloading Java 17, which is required to run OpenRocket-23.09.
We recommend downloading Java 17, which is required to run recent OpenRocket
JARs (for example OpenRocket-24.12).

https://www.oracle.com/java/technologies/downloads/

Expand All @@ -47,7 +48,7 @@ https://www.oracle.com/java/technologies/downloads/
You also need to download the OpenRocket JAR file. You can download it from the
following link:

https://openrocket.info/downloads.html?vers=23.09#content-JAR
https://openrocket.info/downloads.html

Each version of OpenRocket has its own jar file, and it is important to use the
correct java version to run the jar file.
Expand All @@ -61,7 +62,7 @@ will be automatically installed:
- click>=8.0.0
- lxml
- numpy
- orhelper==0.1.3
- jpype1<1.5
- pyyaml
- rocketpy>=1.1.0
- nbformat>=5.2.0
Expand Down Expand Up @@ -89,7 +90,7 @@ The options are the following:

- `--filepath`: The .ork file to be serialized.
- `--output` : Path to the output folder. If not set, the output will be saved in the same folder as the `filepath`.
- `--ork_jar` : Specify the path to the OpenRocket jar file. If not set, the library will try to find the jar file in the current directory.
- `--ork_jar` : Specify the path to the OpenRocket jar file. If not set, the library will use the newest `OpenRocket*.jar` found in the current directory.
- `--encoding` : The encoding of the .ork file. By default, it is set to `utf-8`.
- `--verbose` : If you want to see the progress of the serialization, set this option to True. By default, it is set to False.

Expand Down Expand Up @@ -139,4 +140,4 @@ The 3 main ways of contributing to this project are:
- If you allow us to use and share your .ork file, we can add it to the test suite.
3. **Developing new features and fixing bugs thorough pull requests on GitHub.**
- If you want to develop new features, you are more than welcome to do so.
- Please reach out to the maintainers to discuss the new feature before starting the development.
- Please reach out to the maintainers to discuss the new feature before starting the development.
2 changes: 1 addition & 1 deletion destroy-the-bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def destroy_the_bank(file):
for file in ork_files:
try:
destroy_the_bank(file)
except Exception as e:
except Exception:
# Log any unexpected exceptions
logging.exception(f"An unexpected error occurred in file: {file}")
20 changes: 11 additions & 9 deletions examples/EPFL--BellaLui--2020/simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"from rocketpy import (\n",
" Environment,\n",
" SolidMotor,\n",
" Rocket,\n",
" Flight,\n",
" TrapezoidalFins,\n",
" EllipticalFins,\n",
" RailButtons,\n",
" NoseCone,\n",
" Rocket,\n",
" SolidMotor,\n",
" Tail,\n",
" Parachute,\n",
")\n",
"import datetime"
" TrapezoidalFins,\n",
")"
]
},
{
Expand Down Expand Up @@ -510,7 +508,11 @@
]
}
],
"metadata": {},
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
21 changes: 12 additions & 9 deletions examples/NDRT--Rocket--2020/simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"from rocketpy import (\n",
" Environment,\n",
" SolidMotor,\n",
" Rocket,\n",
" Flight,\n",
" TrapezoidalFins,\n",
" EllipticalFins,\n",
" RailButtons,\n",
" NoseCone,\n",
" Tail,\n",
" Parachute,\n",
")\n",
"import datetime"
" Rocket,\n",
" SolidMotor,\n",
" Tail,\n",
" TrapezoidalFins,\n",
")"
]
},
{
Expand Down Expand Up @@ -541,7 +540,11 @@
]
}
],
"metadata": {},
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
16 changes: 7 additions & 9 deletions examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"id": "20ba7738",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"from rocketpy import (\n",
" Environment,\n",
" SolidMotor,\n",
" Rocket,\n",
" Flight,\n",
" TrapezoidalFins,\n",
" EllipticalFins,\n",
" RailButtons,\n",
" NoseCone,\n",
" Tail,\n",
" Parachute,\n",
")\n",
"import datetime"
" Rocket,\n",
" SolidMotor,\n",
" TrapezoidalFins,\n",
")"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
black[jupyter]
pylint
isort
flake8
mypy
pytest==7.4.0
pytest-coverage
pytest-coverage
ruff
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bs4
click>=8.0.0
lxml
numpy
orhelper==0.1.3
jpype1<1.5
pyyaml
rocketpy>=1.1.0
nbformat>=5.2.0
2 changes: 2 additions & 0 deletions rocketserializer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .ork_extractor import ork_extractor

__all__ = ["ork_extractor"]
2 changes: 1 addition & 1 deletion rocketserializer/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parse_ork_file(ork_path: Path):
try:
with open(ork_path, encoding="utf-8") as file:
bs = BeautifulSoup(file, features="xml")
datapoints = bs.findAll("datapoint")
datapoints = bs.find_all("datapoint")
logger.info(
"Successfully parsed .ork file at '%s' with %d datapoints",
ork_path.as_posix(),
Expand Down
66 changes: 28 additions & 38 deletions rocketserializer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from pathlib import Path

import click
import orhelper

from ._helpers import extract_ork_from_zip, parse_ork_file
from .nb_builder import NotebookBuilder
from .openrocket_runtime import OpenRocketSession, select_latest_openrocket_jar
from .ork_extractor import ork_extractor

logging.basicConfig(
Expand Down Expand Up @@ -138,18 +138,15 @@ def ork2json(filepath, output=None, ork_jar=None, encoding="utf-8", verbose=Fals
raise ValueError(message)

if not ork_jar:
# get any .jar file in the current directory that starts with "OpenRocket"
ork_jar = [
f for f in os.listdir() if f.startswith("OpenRocket") and f.endswith(".jar")
]
if len(ork_jar) == 0:
raise ValueError(
"[ork2json] It was not possible to find the OpenRocket .jar file in "
"the current directory. Please specify the path to the .jar file."
)
ork_jar = ork_jar[0]
logger.info(
"[ork2json] Found OpenRocket .jar file: '%s'", Path(ork_jar).as_posix()
ork_jar = select_latest_openrocket_jar(Path.cwd())
logger.info("[ork2json] Found OpenRocket .jar file: '%s'", ork_jar.as_posix())
else:
ork_jar = Path(ork_jar)

if not ork_jar.exists():
raise FileNotFoundError(
"[ork2json] The specified OpenRocket .jar file does not exist: "
f"'{ork_jar.as_posix()}'"
)

if not output:
Expand All @@ -160,17 +157,11 @@ def ork2json(filepath, output=None, ork_jar=None, encoding="utf-8", verbose=Fals
Path(output).as_posix(),
)

# orhelper options are: OFF, ERROR, WARN, INFO, DEBUG, TRACE and ALL
# log_level = "OFF" if verbose else "OFF"
# TODO: even if the log level is set to OFF, the orhelper still prints msgs

with orhelper.OpenRocketInstance(ork_jar, log_level="OFF") as instance:
# create the output folder if it does not exist
if os.path.exists(output) is False:
os.mkdir(output)
with OpenRocketSession(ork_jar, log_level="OFF") as instance:
# create the output folder (including parents) if it does not exist
Path(output).mkdir(parents=True, exist_ok=True)

orh = orhelper.Helper(instance)
ork = orh.load_doc(str(filepath))
ork = instance.load_doc(str(filepath))

settings = ork_extractor(
bs=bs,
Expand Down Expand Up @@ -217,21 +208,20 @@ def ork2notebook(filepath, output, ork_jar=None, encoding="utf-8", verbose=False
"[ork2notebook] Output folder not specified. Using '%s' instead.",
Path(output).as_posix(),
)
ork2json(
[
"--filepath",
filepath,
"--output",
output,
"--ork_jar",
ork_jar,
"--encoding",
encoding,
"--verbose",
verbose,
],
standalone_mode=False,
)
args = [
"--filepath",
str(filepath),
"--output",
str(output),
"--encoding",
str(encoding),
"--verbose",
str(verbose),
]
if ork_jar:
args.extend(["--ork_jar", str(ork_jar)])

ork2json(args, standalone_mode=False)

instance = NotebookBuilder(parameters_json=os.path.join(output, "parameters.json"))
instance.build(destination=output)
4 changes: 2 additions & 2 deletions rocketserializer/components/fins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def search_trapezoidal_fins(bs, elements):
"sweep_length", "sweep_angle", "cant_angle", "section".
"""
settings = {}
fins = bs.findAll("trapezoidfinset")
fins = bs.find_all("trapezoidfinset")
logger.info("A total of %d trapezoidal fin sets were detected", len(fins))

if len(fins) == 0:
Expand Down Expand Up @@ -131,7 +131,7 @@ def search_elliptical_fins(bs, elements):
"section".
"""
settings = {}
fins = bs.findAll("ellipticalfinset")
fins = bs.find_all("ellipticalfinset")
logger.info("A total of %d elliptical fin sets were detected", len(fins))

if len(fins) == 0:
Expand Down
2 changes: 1 addition & 1 deletion rocketserializer/components/nose_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def search_nosecone(bs, elements=None, rocket_radius=None, just_radius=False):
if not nosecone:
nosecones = list(
filter(
lambda x: x.find("name").text == "Nosecone", bs.findAll("transition")
lambda x: x.find("name").text == "Nosecone", bs.find_all("transition")
)
)
if len(nosecones) == 0:
Expand Down
2 changes: 1 addition & 1 deletion rocketserializer/components/parachute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def search_parachutes(bs):
"""
settings = {}

chutes = bs.findAll("parachute")
chutes = bs.find_all("parachute")
logger.info("A total of %d parachutes were detected", len(chutes))

for idx, chute in enumerate(chutes):
Expand Down
Loading
Loading