algorand / pyteal

Algorand Smart Contracts in Python
https://pyteal.readthedocs.io
MIT License
288 stars 130 forks source link

Feature Gates without a Config File #687

Closed tzaffi closed 1 year ago

tzaffi commented 1 year ago

Addressing the pyteal.ini portion of https://github.com/algorand/pyteal/issues/677 by removing it as well as proposing a way to address https://github.com/algorand/pyteal/issues/601

Please see examples/applications/sourcemap.py for usage example.

Regarding Feature Gates Issue 601

re-quoting that issue:

The feature gating mechanism does not need to mirror Rust exactly. Criteria we want to support include:

Define a way to demarcate modules, classes, methods, and variables as experimental. Access to experimental capabilities is controlled by PyTeal release version. Only non-final (e.g. nightly builds, branch builds) versions can access experimental capabilities.

feature_gates.FeatureGates provides a mechanism for defining global booleans that are loaded before the rest of PyTeal is. An experimental code path could directly use these globals via FeatureGates.theFeature_isOn() or I can also imagine a decorator such as @FeatureGate.decorate_theFeature_isOn which actually runs an assert FeatureGates.theFeature_isOn() as part of the wrapped method. To avail the feature in a particular build, one could call FeatureGate.set_theFeature_isOn(True) and to officially release (without removing the decorators) is as simple as changing the default defined in FeatureGates._gates.theFeature_isOn

Optionally, providing an explicit opt-in mechanism to use experimental features.

That's available via -for example- FeatureGate.set_theFeature_isOn(True)