Skip to content

Commit

Permalink
Merge pull request #22 from RocketPy-Team/enh/improve-cli-readability
Browse files Browse the repository at this point in the history
ENH: Update ork2ipynb command to ork2notebook
  • Loading branch information
juliomachad0 authored Jun 15, 2024
2 parents be63fa7 + 266cbcb commit 270e35c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ classifiers = [

[project.scripts]
ork2json = "rocketserializer.cli:ork2json"
ork2ipynb = "rocketserializer.cli:ork2ipynb"
ork2notebook = "rocketserializer.cli:ork2notebook"


[project.urls]
Expand Down
53 changes: 19 additions & 34 deletions rocketserializer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,30 @@
@click.group()
@click.version_option()
def cli():
"""Rocket files Serializer.
This library has as objective to convert .ork file into parameters
that rocketpy is able to use for simulating the rocket. It will be generated
a .json file which you can use with a template simulation to execute the
simulation for your rocket.
"""RocketSerializer.
This library has as objective to convert .ork files into parameters.json, so
that they can be used in rocketpy simulations. It also provides the option
to convert the parameters.json file into a .ipynb file, so that the user can
run the simulation using Jupyter Notebooks.
Examples
--------
To easily use the library, you can use the command line interface. For
example, to generate a .json file from a .ork file, you can use the
following command:
following command on your terminal:
>>> ork2json("rocket.ork", "rocket", "motor.eng")
If you want to use the library with Python, you can import the library and
use the functions directly. For example, to generate a .json file from a
.ork file, you can use the following code:
>>> from rocketserializer import ork2json
>>> ork2json("rocket.ork", "rocket", "motor.eng")
If you want to convert a .ork file to a .py file, you can use the following
command:
>>> serializer ork2py("rocket.ork", "rocket", "motor.eng")
>>> ork2json([ "--filepath", "rocket.ork", "--eng", "motor.eng"])
Finally, if you want to convert a .ork file to a .ipynb file, you can use:
If you want to convert a .ork file to a Jupyter Notebook, you can use the
following command on your terminal:
>>> serializer ork2ipynb("rocket.ork", "rocket", "motor.eng")
>>> ork2notebook("rocket.ork", "rocket", "motor.eng")
"""


Expand All @@ -67,13 +63,6 @@ def cli():
@click.option(
"--output", type=click.Path(), required=False, help="The path to the output folder."
)
@click.option(
"--eng",
type=str,
default=None,
required=False,
help="The path to the .eng file, if necessary.",
)
@click.option(
"--ork_jar",
type=click.Path(),
Expand All @@ -83,9 +72,7 @@ def cli():
)
@click.option("--encoding", type=str, default="utf-8", required=False)
@click.option("--verbose", type=bool, default=False, required=False)
def ork2json(
filepath, output=None, eng=None, ork_jar=None, encoding="utf-8", verbose=False
):
def ork2json(filepath, output=None, ork_jar=None, encoding="utf-8", verbose=False):
"""Generates a .json file from the .ork file.
The .json file will be generated in the output folder using the information
of the .ork file. It is possible to specify the .eng file to extract the
Expand All @@ -98,10 +85,6 @@ def ork2json(
The path to the .ork file.
output : str
The path to the output folder.
eng : str, optional
The path to the .eng file. If unspecified, the thrust curve will be
extracted from the .ork file. If specified, the thrust curve will be
extracted from the .eng file.
ork_jar : str, optional
The path to the OpenRocket .jar file. If unspecified, the .jar file
will be searched in the current directory.
Expand Down Expand Up @@ -194,7 +177,6 @@ def ork2json(
filepath=str(filepath),
output_folder=output,
ork=ork,
eng=eng,
)

with open(
Expand All @@ -213,12 +195,13 @@ def ork2json(
)


@cli.command("ork2ipynb")
@cli.command("ork2notebook")
@click.option("--filepath", type=str, required=True)
@click.option("--output", type=str, required=False)
@click.option("--eng", type=str, default=None, required=False)
@click.option("--ork_jar", type=str, default=None, required=False)
def ork2ipynb(filepath, output, eng=None, ork_jar=None):
@click.option("--encoding", type=str, default="utf-8", required=False)
@click.option("--verbose", type=bool, default=False, required=False)
def ork2notebook(filepath, output, ork_jar=None, encoding="utf-8", verbose=False):
"""Generates a .ipynb file from the .ork file.
Notes
Expand All @@ -233,10 +216,12 @@ def ork2ipynb(filepath, output, eng=None, ork_jar=None):
filepath,
"--output",
output,
"--eng",
eng,
"--ork_jar",
ork_jar,
"--encoding",
encoding,
"--verbose",
verbose,
],
standalone_mode=True,
)
Expand Down
6 changes: 2 additions & 4 deletions rocketserializer/ork_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logger = logging.getLogger(__name__)


def ork_extractor(bs, filepath, output_folder, ork, eng):
def ork_extractor(bs, filepath, output_folder, ork):
"""Generates the parameters.json file with the parameters for rocketpy
Parameters
Expand All @@ -31,8 +31,6 @@ def ork_extractor(bs, filepath, output_folder, ork, eng):
Path to the output folder.
ork : orhelper
An object representing the OpenRocket document.
eng : str
Engine file name.
verbose : bool, optional
Whether or not to print a message of successful execution, by default
False.
Expand Down Expand Up @@ -113,7 +111,7 @@ def ork_extractor(bs, filepath, output_folder, ork, eng):
logger.info("Drag curve generated.")

# get thrust curve
thrust_path = eng or generate_thrust_curve(
thrust_path = generate_thrust_curve(
output_folder, datapoints, data_labels, time_vector
)
settings["motors"]["thrust_source"] = thrust_path
Expand Down
8 changes: 4 additions & 4 deletions run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ork2json --filepath="examples\NDRT--Rocket--2020\rocket.ork"
ork2json --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
ork2json --filepath="examples\WERT--Prometheus--2022\rocket.ork"

ork2ipynb --filepath="examples\EPFL--BellaLui--2020\rocket.ork"
ork2ipynb --filepath="examples\NDRT--Rocket--2020\rocket.ork"
ork2ipynb --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
ork2ipynb --filepath="examples\WERT--Prometheus--2022\rocket.ork"
ork2notebook --filepath="examples\EPFL--BellaLui--2020\rocket.ork"
ork2notebook --filepath="examples\NDRT--Rocket--2020\rocket.ork"
ork2notebook --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
ork2notebook --filepath="examples\WERT--Prometheus--2022\rocket.ork"

0 comments on commit 270e35c

Please sign in to comment.