mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 00:07:51 -06:00
@api checked for semantic versions
CURA-6665
This commit is contained in:
parent
33cf7491ef
commit
08b1e0e9a8
1 changed files with 14 additions and 4 deletions
|
@ -2,15 +2,25 @@
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
import re
|
||||||
|
|
||||||
|
# An API version must be a semantic version "x.y.z" where ".z" is optional. So the valid formats are as follows:
|
||||||
|
# - x.y.z
|
||||||
|
# - x.y
|
||||||
|
SEMANTIC_VERSION_REGEX = re.compile(r"^[0-9]+\.[0-9]+(\.[0-9]+)?$")
|
||||||
|
|
||||||
|
|
||||||
## Decorator for functions that belong to a set of APIs. For now, this should only be used for officially supported
|
## Decorator for functions that belong to a set of APIs. For now, this should only be used for officially supported
|
||||||
# APIs, meaning that those APIs should be versioned and maintained.
|
# APIs, meaning that those APIs should be versioned and maintained.
|
||||||
#
|
#
|
||||||
# \param since The earliest version since when this API becomes supported. This means that since this version, this
|
# \param since_version The earliest version since when this API becomes supported. This means that since this version,
|
||||||
# API function is supposed to behave the same. This parameter is not used. It's just a documentation.
|
# this API function is supposed to behave the same. This parameter is not used. It's just a
|
||||||
#
|
# documentation.
|
||||||
def api(since = "Unknown"):
|
def api(since_version: str) -> callable:
|
||||||
|
# Make sure that APi versions are semantic versions
|
||||||
|
if not SEMANTIC_VERSION_REGEX.fullmatch(since_version):
|
||||||
|
raise ValueError("API since_version [%s] is not a semantic version." % since_version)
|
||||||
|
|
||||||
def api_decorator(function):
|
def api_decorator(function):
|
||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def api_wrapper(*args, **kwargs):
|
def api_wrapper(*args, **kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue