Skip to content

Commit 270e35c

Browse files
authored
Merge pull request #22 from RocketPy-Team/enh/improve-cli-readability
ENH: Update ork2ipynb command to ork2notebook
2 parents be63fa7 + 266cbcb commit 270e35c

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ classifiers = [
4646

4747
[project.scripts]
4848
ork2json = "rocketserializer.cli:ork2json"
49-
ork2ipynb = "rocketserializer.cli:ork2ipynb"
49+
ork2notebook = "rocketserializer.cli:ork2notebook"
5050

5151

5252
[project.urls]

rocketserializer/cli.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,30 @@
2929
@click.group()
3030
@click.version_option()
3131
def cli():
32-
"""Rocket files Serializer.
33-
This library has as objective to convert .ork file into parameters
34-
that rocketpy is able to use for simulating the rocket. It will be generated
35-
a .json file which you can use with a template simulation to execute the
36-
simulation for your rocket.
32+
"""RocketSerializer.
33+
This library has as objective to convert .ork files into parameters.json, so
34+
that they can be used in rocketpy simulations. It also provides the option
35+
to convert the parameters.json file into a .ipynb file, so that the user can
36+
run the simulation using Jupyter Notebooks.
3737
3838
Examples
3939
--------
4040
To easily use the library, you can use the command line interface. For
4141
example, to generate a .json file from a .ork file, you can use the
42-
following command:
42+
following command on your terminal:
4343
>>> ork2json("rocket.ork", "rocket", "motor.eng")
4444
4545
If you want to use the library with Python, you can import the library and
4646
use the functions directly. For example, to generate a .json file from a
4747
.ork file, you can use the following code:
4848
4949
>>> from rocketserializer import ork2json
50-
>>> ork2json("rocket.ork", "rocket", "motor.eng")
51-
52-
If you want to convert a .ork file to a .py file, you can use the following
53-
command:
54-
55-
>>> serializer ork2py("rocket.ork", "rocket", "motor.eng")
50+
>>> ork2json([ "--filepath", "rocket.ork", "--eng", "motor.eng"])
5651
57-
Finally, if you want to convert a .ork file to a .ipynb file, you can use:
52+
If you want to convert a .ork file to a Jupyter Notebook, you can use the
53+
following command on your terminal:
5854
59-
>>> serializer ork2ipynb("rocket.ork", "rocket", "motor.eng")
55+
>>> ork2notebook("rocket.ork", "rocket", "motor.eng")
6056
"""
6157

6258

@@ -67,13 +63,6 @@ def cli():
6763
@click.option(
6864
"--output", type=click.Path(), required=False, help="The path to the output folder."
6965
)
70-
@click.option(
71-
"--eng",
72-
type=str,
73-
default=None,
74-
required=False,
75-
help="The path to the .eng file, if necessary.",
76-
)
7766
@click.option(
7867
"--ork_jar",
7968
type=click.Path(),
@@ -83,9 +72,7 @@ def cli():
8372
)
8473
@click.option("--encoding", type=str, default="utf-8", required=False)
8574
@click.option("--verbose", type=bool, default=False, required=False)
86-
def ork2json(
87-
filepath, output=None, eng=None, ork_jar=None, encoding="utf-8", verbose=False
88-
):
75+
def ork2json(filepath, output=None, ork_jar=None, encoding="utf-8", verbose=False):
8976
"""Generates a .json file from the .ork file.
9077
The .json file will be generated in the output folder using the information
9178
of the .ork file. It is possible to specify the .eng file to extract the
@@ -98,10 +85,6 @@ def ork2json(
9885
The path to the .ork file.
9986
output : str
10087
The path to the output folder.
101-
eng : str, optional
102-
The path to the .eng file. If unspecified, the thrust curve will be
103-
extracted from the .ork file. If specified, the thrust curve will be
104-
extracted from the .eng file.
10588
ork_jar : str, optional
10689
The path to the OpenRocket .jar file. If unspecified, the .jar file
10790
will be searched in the current directory.
@@ -194,7 +177,6 @@ def ork2json(
194177
filepath=str(filepath),
195178
output_folder=output,
196179
ork=ork,
197-
eng=eng,
198180
)
199181

200182
with open(
@@ -213,12 +195,13 @@ def ork2json(
213195
)
214196

215197

216-
@cli.command("ork2ipynb")
198+
@cli.command("ork2notebook")
217199
@click.option("--filepath", type=str, required=True)
218200
@click.option("--output", type=str, required=False)
219-
@click.option("--eng", type=str, default=None, required=False)
220201
@click.option("--ork_jar", type=str, default=None, required=False)
221-
def ork2ipynb(filepath, output, eng=None, ork_jar=None):
202+
@click.option("--encoding", type=str, default="utf-8", required=False)
203+
@click.option("--verbose", type=bool, default=False, required=False)
204+
def ork2notebook(filepath, output, ork_jar=None, encoding="utf-8", verbose=False):
222205
"""Generates a .ipynb file from the .ork file.
223206
224207
Notes
@@ -233,10 +216,12 @@ def ork2ipynb(filepath, output, eng=None, ork_jar=None):
233216
filepath,
234217
"--output",
235218
output,
236-
"--eng",
237-
eng,
238219
"--ork_jar",
239220
ork_jar,
221+
"--encoding",
222+
encoding,
223+
"--verbose",
224+
verbose,
240225
],
241226
standalone_mode=True,
242227
)

rocketserializer/ork_extractor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
logger = logging.getLogger(__name__)
1919

2020

21-
def ork_extractor(bs, filepath, output_folder, ork, eng):
21+
def ork_extractor(bs, filepath, output_folder, ork):
2222
"""Generates the parameters.json file with the parameters for rocketpy
2323
2424
Parameters
@@ -31,8 +31,6 @@ def ork_extractor(bs, filepath, output_folder, ork, eng):
3131
Path to the output folder.
3232
ork : orhelper
3333
An object representing the OpenRocket document.
34-
eng : str
35-
Engine file name.
3634
verbose : bool, optional
3735
Whether or not to print a message of successful execution, by default
3836
False.
@@ -113,7 +111,7 @@ def ork_extractor(bs, filepath, output_folder, ork, eng):
113111
logger.info("Drag curve generated.")
114112

115113
# get thrust curve
116-
thrust_path = eng or generate_thrust_curve(
114+
thrust_path = generate_thrust_curve(
117115
output_folder, datapoints, data_labels, time_vector
118116
)
119117
settings["motors"]["thrust_source"] = thrust_path

run-tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ork2json --filepath="examples\NDRT--Rocket--2020\rocket.ork"
33
ork2json --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
44
ork2json --filepath="examples\WERT--Prometheus--2022\rocket.ork"
55

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

0 commit comments

Comments
 (0)