|
5 | 5 | carefully as it may impact all the rest of the project. |
6 | 6 | """ |
7 | 7 |
|
8 | | -import base64 |
9 | | -import functools |
10 | 8 | import operator |
11 | 9 | import warnings |
12 | 10 | from bisect import bisect_left |
13 | 11 | from collections.abc import Iterable |
14 | 12 | from copy import deepcopy |
15 | | -from enum import Enum |
16 | 13 | from functools import cached_property |
17 | 14 | from inspect import signature |
18 | 15 | from pathlib import Path |
19 | 16 |
|
20 | | -import dill |
21 | 17 | import matplotlib.pyplot as plt |
22 | 18 | import numpy as np |
23 | 19 | from scipy import integrate, linalg, optimize |
|
29 | 25 | ) |
30 | 26 |
|
31 | 27 | from rocketpy.plots.plot_helpers import show_or_save_plot |
| 28 | +from rocketpy.tools import deprecated |
32 | 29 |
|
33 | 30 | # Numpy 1.x compatibility, |
34 | 31 | # TODO: remove these lines when all dependencies support numpy>=2.0.0 |
|
51 | 48 | EXTRAPOLATION_TYPES = {"zero": 0, "natural": 1, "constant": 2} |
52 | 49 |
|
53 | 50 |
|
54 | | -def deprecated(reason=None, version=None, alternative=None): |
55 | | - """Decorator to mark functions or methods as deprecated. |
56 | | -
|
57 | | - This decorator issues a DeprecationWarning when the decorated function |
58 | | - is called, indicating that it will be removed in future versions. |
59 | | - """ |
60 | | - |
61 | | - def decorator(func): |
62 | | - @functools.wraps(func) |
63 | | - def wrapper(*args, **kwargs): |
64 | | - if reason: |
65 | | - message = reason |
66 | | - else: |
67 | | - message = f"The function `{func.__name__}` is deprecated" |
68 | | - |
69 | | - if version: |
70 | | - message += f" and will be removed in {version}" |
71 | | - |
72 | | - if alternative: |
73 | | - message += f". Use `{alternative}` instead" |
74 | | - |
75 | | - message += "." |
76 | | - warnings.warn(message, DeprecationWarning, stacklevel=2) |
77 | | - return func(*args, **kwargs) |
78 | | - |
79 | | - return wrapper |
80 | | - |
81 | | - return decorator |
82 | | - |
83 | | - |
84 | | -def to_hex_encode(obj, encoder=base64.b85encode): |
85 | | - """Converts an object to hex representation using dill.""" |
86 | | - return encoder(dill.dumps(obj)).hex() |
87 | | - |
88 | | - |
89 | | -def from_hex_decode(obj_bytes, decoder=base64.b85decode): |
90 | | - """Converts an object from hex representation using dill.""" |
91 | | - return dill.loads(decoder(bytes.fromhex(obj_bytes))) |
92 | | - |
93 | | - |
94 | | -class SourceType(Enum): |
95 | | - """Enumeration of the source types for the Function class. |
96 | | - The source can be either a callable or an array. |
97 | | - """ |
98 | | - |
99 | | - CALLABLE = 0 |
100 | | - ARRAY = 1 |
101 | | - |
102 | | - |
103 | 51 | class Function: # pylint: disable=too-many-public-methods |
104 | 52 | """Class converts a python function or a data sequence into an object |
105 | 53 | which can be handled more naturally, enabling easy interpolation, |
|
0 commit comments