Skip to content

Commit e6e73e8

Browse files
authored
doc: pydocstyle ruff rule (#1975)
* doc: first commit * doc: modified additional set of files. * doc: modified more files * doc: modified more files. * doc: modified more files * doc: modified more files. * doc: modified more files. * doc: modified more files. * doc: modified final set of files.
1 parent deb24c5 commit e6e73e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1602
-888
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ indent-style = "space"
6666
[tool.ruff.lint]
6767
select = [
6868
# "E", # pycodestyle, see https://beta.ruff.rs/docs/rules/#pycodestyle-e-w
69-
# "D", # pydocstyle, see https://beta.ruff.rs/docs/rules/#pydocstyle-d
69+
"D", # pydocstyle, see https://beta.ruff.rs/docs/rules/#pydocstyle-d
7070
# "F", # pyflakes, see https://beta.ruff.rs/docs/rules/#pyflakes-f
7171
# "I", # isort, see https://beta.ruff.rs/docs/rules/#isort-i
7272
# "N", # pep8-naming, see https://beta.ruff.rs/docs/rules/#pep8-naming-n

src/ansys/dpf/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
"""Version for ansys-dpf-core"""
23+
"""Version for ansys-dpf-core."""
2424

2525
# Minimal DPF server version supported
2626
min_server_version = "4.0"

src/ansys/dpf/core/animation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
"""Module contains the function for modal animation creation."""
24+
2325
import ansys.dpf.core as dpf
2426
import numpy as np
2527

@@ -34,8 +36,7 @@ def animate_mode(
3436
**kwargs,
3537
):
3638
# other option: instead of `type` use `min_factor` and `max_factor`.
37-
38-
"""Creates a modal animation based on Fields contained in the FieldsContainer.
39+
"""Create a modal animation based on Fields contained in the FieldsContainer.
3940
4041
This method creates a movie or a gif based on the time ids of a ``FieldsContainer``.
4142
For kwargs see pyvista.Plotter.open_movie/add_text/show.

src/ansys/dpf/core/animator.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# SOFTWARE.
2222

2323
"""
24-
Animator
24+
Animator.
2525
2626
This module contains the DPF animator class.
2727
@@ -37,16 +37,15 @@
3737

3838

3939
class _InternalAnimatorFactory:
40-
"""
41-
Factory for _InternalAnimator based on the backend."""
40+
"""Factory for _InternalAnimator based on the backend."""
4241

4342
@staticmethod
4443
def get_animator_class():
4544
return _PyVistaAnimator
4645

4746

4847
class _PyVistaAnimator(_PyVistaPlotter):
49-
"""This _InternalAnimator class is based on PyVista"""
48+
"""An InternalAnimator class based on PyVista."""
5049

5150
def __init__(self, **kwargs):
5251
super().__init__(**kwargs)
@@ -190,6 +189,8 @@ def animation():
190189

191190

192191
class Animator:
192+
"""The DPF animator class."""
193+
193194
def __init__(self, workflow=None, **kwargs):
194195
"""
195196
Create an Animator object.
@@ -228,6 +229,7 @@ def __init__(self, workflow=None, **kwargs):
228229
def workflow(self) -> core.Workflow:
229230
"""
230231
Workflow used to generate a Field at each frame of the animation.
232+
231233
By default, the "to_render" Field output will be plotted,
232234
and the "loop_over" input defines what the animation iterates on.
233235
Optionally, the workflow can also have a "deform_by" Field output,
@@ -267,7 +269,7 @@ def animate(
267269
**kwargs,
268270
):
269271
"""
270-
Animate the workflow of the Animator, using inputs
272+
Animate the workflow of the Animator, using inputs.
271273
272274
Parameters
273275
----------
@@ -316,6 +318,16 @@ def animate(
316318

317319

318320
def scale_factor_to_fc(scale_factor, fc):
321+
"""Scale the fields being animated by a factor.
322+
323+
Parameters
324+
----------
325+
scale_factor : int, float, list
326+
Scale factor to apply to the animated field.
327+
fc : FieldsContainer
328+
FieldsContainer containing the fields being animated.
329+
"""
330+
319331
def int_to_field(value, shape, scoping):
320332
field = core.fields_factory.field_from_array(np.full(shape=shape, fill_value=value))
321333
field.scoping = scoping

src/ansys/dpf/core/any.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
# SOFTWARE.
2222

2323
"""
24-
.. _ref_any:
25-
26-
Any
24+
Any.
2725
26+
Module containing the wrapper class representing all supported DPF datatypes.
2827
"""
2928

3029
import traceback
@@ -216,7 +215,6 @@ def new_from(obj, server=None):
216215
any : Any
217216
Wrapped any type.
218217
"""
219-
220218
inner_server = server if server is not None else obj._server
221219

222220
if not inner_server.meet_version("7.0"):
@@ -295,7 +293,6 @@ def cast(self, output_type=None):
295293
type
296294
Original object instance
297295
"""
298-
299296
self._internal_type = output_type if output_type is not None else self._internal_type
300297

301298
type_tuple = self._type_to_new_from_get_as_method(self._internal_type)
@@ -316,6 +313,7 @@ def cast(self, output_type=None):
316313
raise TypeError(f"{output_type} is not currently supported by the Any class.")
317314

318315
def __del__(self):
316+
"""Delete the entry."""
319317
try:
320318
if hasattr(self, "_deleter_func"):
321319
obj = self._deleter_func[1](self)

src/ansys/dpf/core/available_result.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
# SOFTWARE.
2222

2323
"""
24-
AvailableResult
24+
AvailableResult.
2525
26+
Module contains the class representing the results that an operator can request.
2627
"""
2728

2829
from typing import List
@@ -33,6 +34,8 @@
3334

3435
@unique
3536
class Homogeneity(Enum):
37+
"""Enum class listing all possible homogeneity names of results."""
38+
3639
acceleration = 0
3740
angle = 1
3841
angular_velocity = 2
@@ -147,6 +150,13 @@ def __init__(self, availableresult):
147150
self._qualifier_labels = availableresult.qualifier_labels
148151

149152
def __str__(self):
153+
"""Construct an informal string representation of available result.
154+
155+
Returns
156+
-------
157+
str
158+
Informal string representation of available result.
159+
"""
150160
txt = (
151161
"DPF Result\n----------\n"
152162
+ self.name
@@ -170,6 +180,13 @@ def __str__(self):
170180
return txt
171181

172182
def __repr__(self):
183+
"""Construct a formal string representation of available result.
184+
185+
Returns
186+
-------
187+
str
188+
Formal string representation of available result.
189+
"""
173190
return f"AvailableResult<name={self.name}>"
174191

175192
@property
@@ -257,13 +274,15 @@ def native_scoping_location(self):
257274

258275
@property
259276
def physical_name(self) -> str:
260-
"""Name of the result with spaces"""
277+
"""Name of the result with spaces."""
261278
return self._physics_name
262279

263280
@property
264281
def qualifiers(self) -> list:
265-
"""Returns the list of qualifiers (equivalent to label spaces)
266-
available for a given Result. These qualifiers can then be used to request the result
282+
"""
283+
Returns the list of qualifiers (equivalent to label spaces) available for a given Result.
284+
285+
These qualifiers can then be used to request the result
267286
on specified locations/properties.
268287
"""
269288
return self._qualifiers
@@ -329,6 +348,18 @@ def qualifier_combinations(self) -> List[dict]:
329348

330349

331350
def available_result_from_name(name) -> AvailableResult:
351+
"""Create an instance of AvailableResult from a specified results name.
352+
353+
Parameters
354+
----------
355+
name : str
356+
Valid property name.
357+
358+
Returns
359+
-------
360+
AvailableResult
361+
Instance created from specified result name.
362+
"""
332363
for key, item in _result_properties.items():
333364
if item["scripting_name"] == name:
334365
from types import SimpleNamespace

src/ansys/dpf/core/cache.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
"""Provides for caching evaluated results for faster re-evaluation."""
24+
2325
from typing import NamedTuple
2426

2527

2628
def class_handling_cache(cls):
2729
"""Class decorator used to handle cache.
30+
2831
To use it, add a ''_to_cache'' static attribute in the given class.
2932
This private dictionary should map class getters to their list of setters.
3033
At initialization, this decorator add a ''_cache'' property to the class.
@@ -53,11 +56,14 @@ def get_handler(mesh):
5356

5457

5558
class MethodIdentifier(NamedTuple):
59+
"""Provides for identifying a method."""
60+
5661
method_name: str
5762
args: list
5863
kwargs: dict
5964

6065
def __eq__(self, other):
66+
"""Compare two methods for equality."""
6167
if isinstance(other, str):
6268
return self.method_name == other
6369
else:
@@ -68,6 +74,7 @@ def __eq__(self, other):
6874
)
6975

7076
def __hash__(self):
77+
"""Fetch the hash corresponding to a method."""
7178
hash = self.method_name.__hash__()
7279
if self.args:
7380
hash += self.args.__hash__()
@@ -77,7 +84,8 @@ def __hash__(self):
7784

7885

7986
class CacheHandler:
80-
""" "Handle cache complexity.
87+
"""Handle cache complexity.
88+
8189
Is initialized by a class and a dictionary mapping the getters
8290
which support caching to their setters.
8391
When the getters of the dictionary are called, their parameters
@@ -112,6 +120,7 @@ def __init__(self, cls, getters_to_setters_dict):
112120
self.cached = {}
113121

114122
def handle(self, object, func, *args, **kwargs):
123+
"""Recover data which has already been cached."""
115124
identifier = MethodIdentifier(func.__name__, args, kwargs)
116125
if identifier in self.cached:
117126
return self.cached[identifier]
@@ -128,19 +137,19 @@ def handle(self, object, func, *args, **kwargs):
128137
return func(object, *args, **kwargs)
129138

130139
def clear(self):
140+
"""Clear cached data."""
131141
self.cached = {}
132142

133143

134144
def _handle_cache(func):
135-
"""Calls the cache handler to either recover cached data, either cache the data
136-
or clear some cached data if the method is a setter.
145+
"""Call the cache handler to either recover cached data, either cache the data or clear some cached data if the method is a setter.
137146
138147
.. note::
139148
The method must be used as a decorator.
140149
"""
141150

142151
def wrapper(self, *args, **kwargs):
143-
"""Call the original function"""
152+
"""Call the original function."""
144153
if hasattr(self, "_cache"):
145154
return self._cache.handle(self, func, *args, **kwargs)
146155
else:
@@ -150,15 +159,14 @@ def wrapper(self, *args, **kwargs):
150159

151160

152161
def _setter(func):
153-
"""Add a private attribute to the class (``self._is_set = True``)
154-
when a method with this decorator is used.
162+
"""Add a private attribute to the class (``self._is_set = True``) when a method with this decorator is used.
155163
156164
.. note::
157165
The method must be used as a decorator.
158166
"""
159167

160168
def wrapper(self, *args, **kwargs):
161-
"""Call the original function"""
169+
"""Call the original function."""
162170
if hasattr(self, "_is_set"):
163171
self._is_set = True
164172
else:

src/ansys/dpf/core/check_version.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def server_meet_version(required_version, server):
5252

5353

5454
def server_meet_version_and_raise(required_version, server, msg=None):
55-
"""Check if a given server version matches with a required version and raise
56-
an exception if it does not match.
55+
"""Check if a given server version matches with a required version and raise an exception if it does not match.
5756
5857
Parameters
5958
----------
@@ -76,7 +75,6 @@ def server_meet_version_and_raise(required_version, server, msg=None):
7675
bool
7776
``True`` when successful, ``False`` when failed.
7877
"""
79-
8078
if not server_meet_version(required_version, server):
8179
if msg is not None:
8280
raise dpf_errors.DpfVersionNotSupported(required_version, msg=msg)
@@ -142,8 +140,7 @@ def decorator(func):
142140

143141
@wraps(func)
144142
def wrapper(self, *args, **kwargs):
145-
"""Call the original function"""
146-
143+
"""Call the original function."""
147144
if isinstance(self._server, weakref.ref):
148145
server = self._server()
149146
else:

src/ansys/dpf/core/collection.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
# SOFTWARE.
2222

2323
# -*- coding: utf-8 -*-
24-
"""
25-
Collection
26-
27-
"""
24+
"""Module containing the class representing dpf objects organized by label spaces."""
2825

2926
from __future__ import annotations
3027
from ansys.dpf.core.any import Any
@@ -72,6 +69,7 @@ def __init__(self, collection=None, server=None, entries_type: type = None):
7269
self._internal_obj = self._api.collection_of_any_new()
7370

7471
def create_subtype(self, obj_by_copy):
72+
"""Create dpf instance of any type, which has been cast to its original type."""
7573
return create_dpf_instance(Any, obj_by_copy, self._server).cast(self.entries_type)
7674

7775
def get_entries(self, label_space):
@@ -123,7 +121,7 @@ def add_entry(self, label_space, entry):
123121

124122

125123
def CollectionFactory(subtype, BaseClass=Collection):
126-
"""Creates classes deriving from Collection at runtime for a given subtype."""
124+
"""Create classes deriving from Collection at runtime for a given subtype."""
127125

128126
def __init__(self, **kwargs):
129127
BaseClass.__init__(self, **kwargs)

0 commit comments

Comments
 (0)