Skip to content

Commit

Permalink
Merge pull request #587 from RocketPy-Team/mnt/delete-cached-property
Browse files Browse the repository at this point in the history
DEP: delete deprecated rocketpy.tools.cached_property
  • Loading branch information
Gui-FernandesBR authored Apr 25, 2024
2 parents a011c5a + 684b997 commit c31c6f8
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- DEP: delete deprecated rocketpy.tools.cached_property [#587](https://github.com/RocketPy-Team/RocketPy/pull/587)
- DOC: Improvements of Environment docstring phrasing [#565](https://github.com/RocketPy-Team/RocketPy/pull/565)
- MNT: Refactor flight prints module [#579](https://github.com/RocketPy-Team/RocketPy/pull/579)
- DOC: Convert CompareFlights example notebooks to .rst files [#576](https://github.com/RocketPy-Team/RocketPy/pull/576)
Expand Down
6 changes: 1 addition & 5 deletions rocketpy/environment/environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import json
from collections import defaultdict
from functools import cached_property

import netCDF4
import numpy as np
Expand All @@ -22,11 +23,6 @@
from ..units import convert_units
from .environment import Environment

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property

# TODO: the average_wind_speed_profile_by_hour and similar methods could be more abstract than currently are


Expand Down
6 changes: 1 addition & 5 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
import warnings
from collections.abc import Iterable
from copy import deepcopy
from functools import cached_property
from inspect import signature
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
from scipy import integrate, linalg, optimize

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property

NUMERICAL_TYPES = (float, int, complex, np.ndarray, np.integer, np.floating)


Expand Down
3 changes: 1 addition & 2 deletions rocketpy/mathutils/vector_matrix.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from cmath import isclose
from functools import cached_property
from itertools import product

from rocketpy.tools import cached_property


class Vector:
"""Pure python basic R3 vector class designed for simple operations.
Expand Down
7 changes: 2 additions & 5 deletions rocketpy/motors/hybrid_motor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import cached_property

from rocketpy.tools import parallel_axis_theorem_from_com

from ..mathutils.function import Function, funcify_method, reset_funcified_methods
Expand All @@ -7,11 +9,6 @@
from .motor import Motor
from .solid_motor import SolidMotor

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property


class HybridMotor(Motor):
"""Class to specify characteristics and useful operations for Hybrid
Expand Down
7 changes: 1 addition & 6 deletions rocketpy/motors/liquid_motor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import warnings
from functools import cached_property

import numpy as np

Expand All @@ -13,11 +13,6 @@
from ..prints.liquid_motor_prints import _LiquidMotorPrints
from .motor import Motor

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property


class LiquidMotor(Motor):
"""Class to specify characteristics and useful operations for Liquid
Expand Down
6 changes: 1 addition & 5 deletions rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import warnings
from abc import ABC, abstractmethod
from functools import cached_property

import numpy as np

Expand All @@ -9,11 +10,6 @@
from ..prints.motor_prints import _MotorPrints
from ..tools import parallel_axis_theorem_from_com, tuple_handler

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property


class Motor(ABC):
"""Abstract class to specify characteristics and useful operations for
Expand Down
7 changes: 2 additions & 5 deletions rocketpy/motors/solid_motor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import cached_property

import numpy as np
from scipy import integrate

Expand All @@ -6,11 +8,6 @@
from ..prints.solid_motor_prints import _SolidMotorPrints
from .motor import Motor

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property


class SolidMotor(Motor):
"""Class to specify characteristics and useful operations for solid motors.
Expand Down
5 changes: 1 addition & 4 deletions rocketpy/motors/tank_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

cache = lru_cache(maxsize=None)

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property
from functools import cached_property


class TankGeometry:
Expand Down
7 changes: 2 additions & 5 deletions rocketpy/plots/flight_plots.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from functools import cached_property

import matplotlib.pyplot as plt
import numpy as np

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property


class _FlightPlots:
"""Class that holds plot methods for Flight class.
Expand Down
1 change: 0 additions & 1 deletion rocketpy/rocket/aero_surface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import warnings
from abc import ABC, abstractmethod
from functools import cached_property

import numpy as np
from scipy.optimize import fsolve
Expand Down
26 changes: 0 additions & 26 deletions rocketpy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,10 @@
from cftime import num2pydate
from packaging import version as packaging_version

_NOT_FOUND = object()

# Mapping of module name and the name of the package that should be installed
INSTALL_MAPPING = {"IPython": "ipython"}


class cached_property:
def __init__(self, func):
self.func = func
self.attrname = None
self.__doc__ = func.__doc__

def __set_name__(self, owner, name):
self.attrname = name

def __get__(self, instance, owner=None):
if instance is None:
return self
if self.attrname is None:
raise TypeError(
"Cannot use cached_property instance without calling __set_name__ on it."
)
cache = instance.__dict__
val = cache.get(self.attrname, _NOT_FOUND)
if val is _NOT_FOUND:
val = self.func(instance)
cache[self.attrname] = val
return val


def tuple_handler(value):
"""Transforms the input value into a tuple that
represents a range. If the input is an input or float,
Expand Down

0 comments on commit c31c6f8

Please sign in to comment.