Skip to content

Commit 4df05aa

Browse files
committed
Adds devops documentation page for deprecations
1 parent dde8597 commit 4df05aa

File tree

4 files changed

+96
-14
lines changed

4 files changed

+96
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pvlib/spa_c_files/spa.h
3939
pvlib/spa_c_files/spa_tester.c
4040

4141
# generated documentation
42+
docs/sphinx/source/contributing/generated
4243
docs/sphinx/source/reference/generated
43-
docs/sphinx/source/reference/*/generated
4444
docs/sphinx/source/savefig
4545
docs/sphinx/source/gallery
4646
docs/sphinx/source/sg_execution_times.rst
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. _devops:
2+
3+
Development Operations
4+
======================
5+
6+
This page provides information on specific development needs found in the pvlib-python ecosystem. Some specific Python concepts may be used in this section.
7+
8+
Deprecations
9+
------------
10+
Let's start by what is a deprecation: sometimes, a feature in the library is no longer needed because it has been superceded by better altenatives, or because better practices are considred beneficial. In this case, just doing that change (a removal, a rename) will probably be a **breaking change** for a number of users. Both developers and users desire to not get their code broken after a release in normal circumstances. There are a number of approaches to make these changes gradually, so at least there is some time in-between to warn about upcoming changes and to allow users to adapt their code.
11+
12+
There are two ways to warn about upcoming changes:
13+
14+
- Passively, by expecting users to read whatsnew entries, new version announcements on the mailing list, or by keeping a close eye on the repo activity.
15+
- Actively, via raising warnings with specific instructions when any of these deprecated features are used.
16+
17+
While the pros for the latter are almost obvious, there is a main weakness; it imposes a number of extra steps to take and more code to maintain by the developers. This guide strives to close that gap.
18+
19+
pvlib's submodule :py:mod:`pvlib._deprecation` has some utilities to ease the implementation of deprecations.
20+
21+
Deprecation Warnings and Messages
22+
---------------------------------
23+
This is about the ``Exception`` that gets raised, but quickly dismished by the interpreter after logging. They automatically leave a text trace in the output buffer (console) so it can be seen by the user. In code terms, the following line raises a warning:
24+
25+
.. code-block::
26+
27+
import warnings
28+
29+
warnings.warn("This feature is deprecated!")
30+
31+
As a general rule, try to be concise on what the problem is and how to fix that. By default, Python will automatically inform about where the issue was found (although that can be modified, again in code terms, by setting a custom ``stacklevel`` in the warning factory).
32+
33+
List of pvlib deprecation helpers
34+
---------------------------------
35+
36+
.. py:module:: pvlib._deprecation
37+
38+
.. currentmodule:: pvlib
39+
40+
.. autosummary::
41+
:toctree: generated/
42+
43+
_deprecation.deprecated
44+
_deprecation.renamed_kwarg_warning
45+
_deprecation.renamed_key_items_warning
46+
47+
Know your deprecation helper
48+
----------------------------
49+
Remember to import the submodule.
50+
51+
.. code-block::
52+
53+
from pvlib import _deprecation
54+
55+
.. contents:: Table of Contents
56+
:local:
57+
58+
Deprecate a function
59+
~~~~~~~~~~~~~~~~~~~~
60+
See :py:func:`pvlib._deprecation.deprecated`.
61+
62+
Rename keyword parameters
63+
~~~~~~~~~~~~~~~~~~~~~~~~~
64+
Applies both to *positional-or-keyword* parameters and *keyword-only* parameters.
65+
You can check out the differences at the `Python docs glossary <https://docs.python.org/3/glossary.html#term-parameter>`_.
66+
67+
See :py:func:`pvlib._deprecation.renamed_kwarg_warning`.
68+
69+
Rename an item from a collection
70+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+
For example, the key an item uses in a dictionary, the column in a ``pandas.DataFrame`` or any key-indexed object. Intended for objects returned by pvlib functions in the public API.
72+
73+
See :py:func:`pvlib._deprecation.renamed_key_items_warning`

docs/sphinx/source/contributing/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Contributing
1212
how_to_contribute_new_code
1313
style_guide
1414
testing
15+
devops

pvlib/_deprecation.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ def warn_deprecated(
169169
obj_type='attribute', addendum='', removal=''):
170170
"""
171171
Used to display deprecation in a standard way.
172+
172173
Parameters
173174
----------
174175
since : str
175176
The release at which this API became deprecated.
176177
message : str, optional
177178
Override the default deprecation message. The format
178-
specifier `%(name)s` may be used for the name of the function,
179-
and `%(alternative)s` may be used in the deprecation message
179+
specifier ``%(name)s`` may be used for the name of the function,
180+
and ``%(alternative)s`` may be used in the deprecation message
180181
to insert the name of an alternative to the deprecated
181182
function. `%(obj_type)s` may be used to insert a friendly name
182183
for the type of object being deprecated.
@@ -198,12 +199,14 @@ def warn_deprecated(
198199
The object type being deprecated.
199200
addendum : str, optional
200201
Additional text appended directly to the final message.
202+
201203
Examples
202204
--------
203-
Basic example::
204-
# To warn of the deprecation of "matplotlib.name_of_module"
205-
warn_deprecated('1.4.0', name='matplotlib.name_of_module',
206-
obj_type='module')
205+
Basic example:
206+
207+
>>> # To warn of the deprecation of "pvlib.name_of_module"
208+
>>> warn_deprecated('1.4.0', name='pvlib.name_of_module',
209+
>>> obj_type='module')
207210
"""
208211
message = '\n' + _generate_deprecation_message(
209212
since, message, name, alternative, pending, obj_type, addendum,
@@ -217,15 +220,16 @@ def deprecated(since, message='', name='', alternative='', pending=False,
217220
addendum='', removal=''):
218221
"""
219222
Decorator to mark a function or a class as deprecated.
223+
220224
Parameters
221225
----------
222226
since : str
223227
The release at which this API became deprecated. This is
224228
required.
225229
message : str, optional
226230
Override the default deprecation message. The format
227-
specifier `%(name)s` may be used for the name of the object,
228-
and `%(alternative)s` may be used in the deprecation message
231+
specifier ``%(name)s`` may be used for the name of the object,
232+
and ``%(alternative)s`` may be used in the deprecation message
229233
to insert the name of an alternative to the deprecated
230234
object.
231235
name : str, optional
@@ -234,9 +238,11 @@ def deprecated(since, message='', name='', alternative='', pending=False,
234238
though this is useful in the case of renamed functions, where
235239
the new function is just assigned to the name of the
236240
deprecated function. For example::
241+
237242
def new_function():
238243
...
239244
oldFunction = new_function
245+
240246
alternative : str, optional
241247
An alternative API that the user may use in place of the deprecated
242248
API. The deprecation warning will tell the user about this alternative
@@ -251,12 +257,14 @@ def new_function():
251257
with *pending*.
252258
addendum : str, optional
253259
Additional text appended directly to the final message.
260+
254261
Examples
255262
--------
256-
Basic example::
257-
@deprecated('1.4.0')
258-
def the_function_to_deprecate():
259-
pass
263+
Basic example:
264+
265+
>>> @deprecated('1.4.0')
266+
>>> def the_function_to_deprecate():
267+
>>> pass
260268
"""
261269

262270
def deprecate(obj, message=message, name=name, alternative=alternative,
@@ -335,7 +343,7 @@ def renamed_kwarg_warning(since, old_param_name, new_param_name, removal=""):
335343
336344
.. note::
337345
Documentation for the function may updated to reflect the new parameter
338-
name; it is suggested to add a |.. versionchanged::| directive.
346+
name; it is suggested to add a ``.. versionchanged::`` directive.
339347
340348
Parameters
341349
----------

0 commit comments

Comments
 (0)