Skip to content

Commit

Permalink
Merge pull request #631 from RocketPy-Team/dev/adds-flake8-as-pylint-…
Browse files Browse the repository at this point in the history
…fallback

DEV: adds flake8 as a pylint fallback
  • Loading branch information
Gui-FernandesBR authored Jul 6, 2024
2 parents 6fc797c + fd4941c commit e953e0d
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ jobs:
python -m pip install --upgrade pip
pip install .[all]
pip install .[tests]
pip install pylint isort
pip install pylint isort flake8 black
- name: Run isort
run: isort --check-only rocketpy/ tests/ docs/ --profile black
- name: Run black
uses: psf/black@stable
with:
options: "--check rocketpy/ tests/ docs/"
jupyter: true
- name: Run flake8
run: flake8 rocketpy/ tests/
- name: Run pylint
run: |
pylint rocketpy/
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ install:
pip install -r requirements-optional.txt
pip install -e .

format: isort black

isort:
isort --profile black rocketpy/ tests/ docs/

black:
black rocketpy/ tests/ docs/


lint: flake8 pylint

flake8:
flake8 rocketpy/ tests/

pylint:
-pylint rocketpy --output=.pylint-report.txt

Expand Down
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ exclude_also = [
max-line-length = 88
max-module-lines = 3000
ignore = [
'W503', # conflicts with black
'E203', # conflicts with black
'E501', # line too long, already checked by black and pylint
'E266', # too many leading '#' for block comment, this is pointless
'F401', # imported but unused, already checked by pylint
'W503', # conflicts with black (line break before binary operator)
'E203', # conflicts with black (whitespace before ':')
'E501', # ignored now because it is hard to fix the whole code (line too long)
'E266', # this is pointless (too many leading '#' for block comment)
'F401', # too many errors on __init__.py files (imported but unused)
'E722', # pylint already checks for bare except
'E226', # black does not adjust errors like this
'E731', # pylint already checks for this (lambda functions)
]
exclude = [
'.git,__pycache__',
Expand Down
8 changes: 4 additions & 4 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3658,14 +3658,14 @@ def geodesic_to_utm(
F = (1 - e2 / 4 - 3 * A / 64 - 5 * B / 256) * lat
G = (3 * e2 / 8 + 3 * A / 32 + 45 * B / 1024) * C
H = (15 * A / 256 + 45 * B / 1024) * D
I = (35 * B / 3072) * E
aux_i = (35 * B / 3072) * E

# Evaluate other reference parameters
n = semi_major_axis / ((1 - e2 * (np.sin(lat) ** 2)) ** 0.5)
t = np.tan(lat) ** 2
c = e2lin * (np.cos(lat) ** 2)
ag = (lon - lon_mc) * np.cos(lat)
m = semi_major_axis * (F - G + H - I)
m = semi_major_axis * (F - G + H - aux_i)

# Evaluate new auxiliary parameters
J = (1 - t + c) * ag * ag * ag / 6
Expand Down Expand Up @@ -3764,7 +3764,7 @@ def utm_to_geodesic(
d = (x - 500000) / (n1 * K0)

# Calculate other auxiliary values
I = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24
aux_i = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24
J = (
(61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 252 * e2lin - 3 * c1 * c1)
* (d**6)
Expand All @@ -3778,7 +3778,7 @@ def utm_to_geodesic(
)

# Finally calculate the coordinates in lat/lot
lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - I + J)
lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - aux_i + J)
lon = central_meridian * np.pi / 180 + (K + L) / np.cos(lat1)

# Convert final lat/lon to Degrees
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,7 @@ def __validate_inputs(self, inputs):
)
if self.__dom_dim__ > 1:
if inputs is None:
return [f"Input {i+1}" for i in range(self.__dom_dim__)]
return [f"Input {i + 1}" for i in range(self.__dom_dim__)]
if isinstance(inputs, list):
if len(inputs) == self.__dom_dim__ and all(
isinstance(i, str) for i in inputs
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/prints/environment_prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def gravity_details(self):
print("\nGravity Details\n")
print(f"Acceleration of gravity at surface level: {surface_gravity:9.4f} m/s²")
print(
f"Acceleration of gravity at {max_expected_height/1000:7.3f} "
f"Acceleration of gravity at {max_expected_height / 1000:7.3f} "
f"km (ASL): {ceiling_gravity:.4f} m/s²\n"
)

Expand Down
6 changes: 4 additions & 2 deletions rocketpy/prints/hybrid_motor_prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def nozzle_details(self):
print("Nozzle Details")
print(f"Outlet Radius: {self.hybrid_motor.nozzle_radius} m")
print(f"Throat Radius: {self.hybrid_motor.solid.throat_radius} m")
print(f"Outlet Area: {np.pi*self.hybrid_motor.nozzle_radius**2:.6f} m²")
print(f"Throat Area: {np.pi*self.hybrid_motor.solid.throat_radius**2:.6f} m²")
print(f"Outlet Area: {np.pi * self.hybrid_motor.nozzle_radius ** 2:.6f} m²")
print(
f"Throat Area: {np.pi * self.hybrid_motor.solid.throat_radius ** 2:.6f} m²"
)
print(f"Position: {self.hybrid_motor.nozzle_position} m\n")

def grain_details(self):
Expand Down
6 changes: 3 additions & 3 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,13 +1670,13 @@ def u_dot_generalized(
## Nozzle gyration tensor
S_nozzle = self.rocket.nozzle_gyration_tensor
## Inertia tensor
I = self.rocket.get_inertia_tensor_at_time(t)
inertia_tensor = self.rocket.get_inertia_tensor_at_time(t)
## Inertia tensor time derivative in the body frame
I_dot = self.rocket.get_inertia_tensor_derivative_at_time(t)

# Calculate the Inertia tensor relative to CM
H = (r_CM.cross_matrix @ -r_CM.cross_matrix) * total_mass
I_CM = I - H
I_CM = inertia_tensor - H

# Prepare transformation matrices
K = Matrix.transformation(e)
Expand Down Expand Up @@ -1820,7 +1820,7 @@ def u_dot_generalized(
)

T21 = (
((I @ w) ^ w)
((inertia_tensor @ w) ^ w)
+ T05 @ w
- (weight_in_body_frame ^ r_CM)
+ Vector([M1, M2, M3])
Expand Down
8 changes: 4 additions & 4 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Monte Carlo Simulation Module for RocketPy
This module defines the `MonteCarlo` class, which is used to perform Monte Carlo
simulations of rocket flights. The Monte Carlo simulation is a powerful tool for
understanding the variability and uncertainty in the performance of rocket flights
simulations of rocket flights. The Monte Carlo simulation is a powerful tool for
understanding the variability and uncertainty in the performance of rocket flights
by running multiple simulations with varied input parameters.
Notes
-----
This module is still under active development, and some features or attributes may
change in future versions. Users are encouraged to check for updates and read the
This module is still under active development, and some features or attributes may
change in future versions. Users are encouraged to check for updates and read the
latest documentation.
"""

Expand Down
10 changes: 5 additions & 5 deletions tests/acceptance/test_bella_lui_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Importing libraries
import matplotlib as mpl
import numpy as np
from scipy.signal import savgol_filter

from rocketpy import Environment, Flight, Function, Rocket, SolidMotor

Expand Down Expand Up @@ -103,20 +104,20 @@ def test_bella_lui_rocket_data_asserts_acceptance():
)
BellaLui.set_rail_buttons(0.1, -0.5)
BellaLui.add_motor(K828FJ, parameters.get("distance_rocket_nozzle")[0])
NoseCone = BellaLui.add_nose(
BellaLui.add_nose(
length=parameters.get("nose_length")[0],
kind="tangent",
position=parameters.get("nose_distance_to_cm")[0]
+ parameters.get("nose_length")[0],
)
fin_set = BellaLui.add_trapezoidal_fins(
BellaLui.add_trapezoidal_fins(
3,
span=parameters.get("fin_span")[0],
root_chord=parameters.get("fin_root_chord")[0],
tip_chord=parameters.get("fin_tip_chord")[0],
position=parameters.get("fin_distance_to_cm")[0],
)
tail = BellaLui.add_tail(
BellaLui.add_tail(
top_radius=parameters.get("tail_top_radius")[0],
bottom_radius=parameters.get("tail_bottom_radius")[0],
length=parameters.get("tail_length")[0],
Expand All @@ -130,7 +131,7 @@ def drogue_trigger(p, h, y):
# activate drogue when vz < 0 m/s.
return True if y[5] < 0 else False

Drogue = BellaLui.add_parachute(
BellaLui.add_parachute(
"Drogue",
cd_s=parameters.get("CdS_drogue")[0],
trigger=drogue_trigger,
Expand Down Expand Up @@ -213,7 +214,6 @@ def drogue_trigger(p, h, y):
acceleration_rcp.append(test_flight.az(test_flight.t_final))

# Acceleration comparison (will not be used in our publication)
from scipy.signal import savgol_filter

# Calculate the acceleration as a velocity derivative
acceleration_kalt = [0]
Expand Down
17 changes: 6 additions & 11 deletions tests/acceptance/test_ndrt_2020_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
from scipy.signal import savgol_filter

from rocketpy import Environment, Flight, Function, Rocket, SolidMotor
from rocketpy import Environment, Flight, Rocket, SolidMotor


def test_ndrt_2020_rocket_data_asserts_acceptance():
Expand All @@ -17,11 +17,6 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
# Drift: 2275 ft

# Importing libraries
import numpy as np
import pandas as pd
from scipy.signal import savgol_filter

from rocketpy import Environment, Flight, Function, Rocket, SolidMotor

# Defining all parameters
parameters = {
Expand Down Expand Up @@ -118,20 +113,20 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
)
NDRT2020.set_rail_buttons(0.2, -0.5, 45)
NDRT2020.add_motor(L1395, parameters.get("distance_rocket_nozzle")[0])
nose_cone = NDRT2020.add_nose(
NDRT2020.add_nose(
length=parameters.get("nose_length")[0],
kind="tangent",
position=parameters.get("nose_distance_to_cm")[0]
+ parameters.get("nose_length")[0],
)
fin_set = NDRT2020.add_trapezoidal_fins(
NDRT2020.add_trapezoidal_fins(
3,
span=parameters.get("fin_span")[0],
root_chord=parameters.get("fin_root_chord")[0],
tip_chord=parameters.get("fin_tip_chord")[0],
position=parameters.get("fin_distance_to_cm")[0],
)
transition = NDRT2020.add_tail(
NDRT2020.add_tail(
top_radius=parameters.get("transition_top_radius")[0],
bottom_radius=parameters.get("transition_bottom_radius")[0],
length=parameters.get("transition_length")[0],
Expand All @@ -151,15 +146,15 @@ def main_trigger(p, h, y):
# activate main when vz < 0 m/s and z < 167.64 m (AGL) or 550 ft (AGL)
return True if y[5] < 0 and h < 167.64 else False

Drogue = NDRT2020.add_parachute(
NDRT2020.add_parachute(
"Drogue",
cd_s=parameters.get("cd_s_drogue")[0],
trigger=drogue_trigger,
sampling_rate=105,
lag=parameters.get("lag_rec")[0],
noise=(0, 8.3, 0.5),
)
Main = NDRT2020.add_parachute(
NDRT2020.add_parachute(
"Main",
cd_s=parameters.get("cd_s_main")[0],
trigger=main_trigger,
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/rockets/rocket_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,21 @@ def prometheus_cd_at_ma(mach):
prometheus.set_rail_buttons(0.69, 0.21, 60)

prometheus.add_motor(motor=generic_motor_cesaroni_M1520, position=0)
nose_cone = prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229)
fin_set = prometheus.add_trapezoidal_fins(
prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229)
prometheus.add_trapezoidal_fins(
n=3,
span=0.13,
root_chord=0.268,
tip_chord=0.136,
position=0.273,
sweep_length=0.066,
)
drogue_chute = prometheus.add_parachute(
prometheus.add_parachute(
"Drogue",
cd_s=1.6 * np.pi * 0.3048**2, # Cd = 1.6, D_chute = 24 in
trigger="apogee",
)
main_chute = prometheus.add_parachute(
prometheus.add_parachute(
"Main",
cd_s=2.2 * np.pi * 0.9144**2, # Cd = 2.2, D_chute = 72 in
trigger=457.2, # 1500 ft
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_rolling_flight(

test_rocket.set_rail_buttons(0.082, -0.618)
test_rocket.add_motor(cesaroni_m1670, position=-1.373)
fin_set = test_rocket.add_trapezoidal_fins(
test_rocket.add_trapezoidal_fins(
4,
span=0.100,
root_chord=0.120,
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def test_geodesic_coordinate_geodesic_to_utm_converts_coordinate():
semi_major_axis=6378137.0, # WGS84
flattening=1 / 298.257223563, # WGS84
)
assert np.isclose(x, 315468.64, atol=1e-5) == True
assert np.isclose(y, 3651938.65, atol=1e-5) == True
assert np.isclose(x, 315468.64, atol=1e-5)
assert np.isclose(y, 3651938.65, atol=1e-5)
assert utm_zone == 13
assert utm_letter == "S"
assert hemis == "N"
Expand All @@ -101,8 +101,8 @@ class and checks the conversion results from UTM to geodesic
semi_major_axis=6378137.0, # WGS84
flattening=1 / 298.257223563, # WGS84
)
assert np.isclose(lat, 32.99025, atol=1e-5) == True
assert np.isclose(lon, -106.9750, atol=1e-5) == True
assert np.isclose(lat, 32.99025, atol=1e-5)
assert np.isclose(lon, -106.9750, atol=1e-5)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Unit tests for the Function class. Each method in tis module tests an
"""Unit tests for the Function class. Each method in tis module tests an
individual method of the Function class. The tests are made on both the
expected behaviour and the return instances."""

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def test_compare(mock_show, flight_calisto):
x_attributes=["time"],
)

assert isinstance(fig, plt.Figure) == True
assert isinstance(fig, plt.Figure)
2 changes: 1 addition & 1 deletion tests/unit/test_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_add_fins_assert_cp_cm_plus_fins(calisto, dimensionless_calisto, m):


@pytest.mark.parametrize(
"""cdm_position, grain_cm_position, nozzle_position, coord_direction,
"""cdm_position, grain_cm_position, nozzle_position, coord_direction,
motor_position, expected_motor_cdm, expected_motor_cpp""",
[
(0.317, 0.397, 0, "nozzle_to_combustion_chamber", -1.373, -1.056, -0.976),
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/test_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ def test_mass_based_tank():
tank and a simplified tank.
"""
lox = Fluid(name="LOx", density=1141.7)
propane = Fluid(
name="Propane",
density=493,
)
n2 = Fluid(
name="Nitrogen Gas",
density=51.75,
Expand Down

0 comments on commit e953e0d

Please sign in to comment.