Skip to content

Commit 2e75a52

Browse files
committed
Document FEATURE_FLAGS
1 parent 891491f commit 2e75a52

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Documentation for LabThings-FastAPI
1515
blobs.rst
1616
concurrency.rst
1717
using_things.rst
18+
updates_and_features.rst
1819
see_also.rst
1920
examples.rst
2021
wot_core_concepts.rst

docs/source/properties.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ Note that the constraints for functional properties are set by assigning a dicti
165165

166166
.. note::
167167

168-
Property values are not validated when they are set directly, only via HTTP. This behaviour may change in the future.
168+
Currently, property values are not validated when they are set directly in Python, only via HTTP.
169+
Setting ``lt.FEATURE_FLAGS.validate_properties_on_set = True`` enables validation when they are set in Python. This may become default behaviour in the future.
169170

170171
HTTP interface
171172
--------------
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _optional_features:
2+
3+
Optional Features and updates
4+
=============================
5+
6+
LabThings allows some features to be turned on and off globally, using the `.FEATURE_FLAGS` object.
7+
This was introduced as a way to smooth the upgrade process for downstream projects, meaning that when a new version of LabThings is released, they need not adopt all the new features at once.
8+
9+
Typically, your application will set the feature flags once, just after importing LabThings. For example, to validate properties when they are written to in Python, we would do:
10+
11+
.. code-block: python
12+
13+
import labthings_fastapi as lt
14+
15+
16+
lt.FEATURE_FLAGS.validate_properties_on_set = True
17+
18+
When new features are intended to become non-optional, the usual procedure will be:
19+
20+
* Introduce the feature in a release, but disable it by default. It may be activated by setting a flag to `True`\ .
21+
* At some point (either the release that introduces it, or a future release) a `DeprecationWarning` will be raised by relevant code if the feature has not been enabled.
22+
* A subsequent release will enable the feature by default, but it may still be disabled by setting the flag to `False`\ . This will raise a `DeprecationWarning`\ .
23+
* Another release will remove the feature flag and the feature will be permanently enabled.
24+
25+
Introducing a feature that's disabled by default, and adding `DeprecationWarning`\ s, are not "breaking changes" as they require no change to downstream code.
26+
Enabling a feature by default, or removing the ability to disable a feature, would constitute a "breaking change".
27+
While our major version is zero, the intention is that patch releases (e.g. ```0.1.0``` to ``0.1.1``) should not make breaking changes, but minor releases (e.g. ``0.1.0`` to ``0.2.0``) may do so.
28+
After `v1.0.0` LabThings should follow the Semantic Versioning convention and make breaking changes only when the major version changes.

src/labthings_fastapi/feature_flags.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@dataclass
22-
class LabthingsFeatureFlags:
22+
class LabThingsFeatureFlags:
2323
"""Control over optional features of LabThings."""
2424

2525
validate_properties_on_set: bool = False
@@ -54,4 +54,9 @@ def set_temporarily(
5454
setattr(self, k, v)
5555

5656

57-
FEATURE_FLAGS = LabthingsFeatureFlags()
57+
FEATURE_FLAGS = LabThingsFeatureFlags()
58+
r"""This module-level object allows features of LabThings to be controlled.
59+
60+
See the documentation for the class `.LabThingsFeatureFlags` for details of the
61+
flags and what they do. More information is available in :ref:`optional_features`\ .
62+
"""

0 commit comments

Comments
 (0)