Get rid of decorator lib

This lib is used only in two places and the latest release fails now.

Change-Id: Ia79008c6ac7dc3be92afdea5f8ffabcd697e7599
This commit is contained in:
Andrey Kurilin 2021-04-08 14:21:12 +03:00
parent a72a6e1ce5
commit ee09cab546
4 changed files with 29 additions and 20 deletions

View File

@ -13,12 +13,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import functools
import inspect
import os import os
import decorator
from rally import exceptions from rally import exceptions
PATH_GLOBALS = "~/.rally/globals" PATH_GLOBALS = "~/.rally/globals"
ENV_ENV = "RALLY_ENV" ENV_ENV = "RALLY_ENV"
ENV_DEPLOYMENT = "RALLY_DEPLOYMENT" ENV_DEPLOYMENT = "RALLY_DEPLOYMENT"
@ -124,16 +125,23 @@ def get_global(global_key, do_raise=False):
def default_from_global(arg_name, env_name, def default_from_global(arg_name, env_name,
cli_arg_name, cli_arg_name,
message=MSG_MISSING_ARG): message=MSG_MISSING_ARG):
def default_from_global(f, *args, **kwargs): def wrapper(func):
id_arg_index = f.__code__.co_varnames.index(arg_name)
args = list(args) @functools.wraps(func)
if args[id_arg_index] is None: def inner(*args, **kwargs):
args[id_arg_index] = get_global(env_name) params = list(inspect.signature(func).parameters)
if not args[id_arg_index]: id_arg_index = params.index(arg_name)
print(message % {"arg_name": cli_arg_name})
return(1) args = list(args)
return f(*args, **kwargs) if ((len(args) <= id_arg_index or args[id_arg_index] is None)
return decorator.decorator(default_from_global) and arg_name not in kwargs):
kwargs[arg_name] = get_global(env_name)
if not kwargs[arg_name]:
print(message % {"arg_name": cli_arg_name})
return 1
return func(*args, **kwargs)
return inner
return wrapper
def with_default_env(): def with_default_env():

View File

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import functools
import os import os
import decorator
from rally.common.plugin import discover from rally.common.plugin import discover
@ -53,7 +52,9 @@ def load():
PLUGINS_LOADED = True PLUGINS_LOADED = True
@decorator.decorator def ensure_plugins_are_loaded(func):
def ensure_plugins_are_loaded(f, *args, **kwargs): @functools.wraps(func)
load() def wrapper(*args, **kwargs):
return f(*args, **kwargs) load()
return func(*args, **kwargs)
return wrapper

View File

@ -4,7 +4,6 @@
# Rally core dependencies # Rally core dependencies
alembic!=1.2.0 # MIT alembic!=1.2.0 # MIT
decorator # new BSD License
Jinja2 # BSD-3-Clause Jinja2 # BSD-3-Clause
jsonschema # MIT jsonschema # MIT
oslo.config!=4.3.0,!=4.4.0 # Apache Software License oslo.config!=4.3.0,!=4.4.0 # Apache Software License

View File

@ -77,7 +77,7 @@ deps =
-r{toxinidir}/doc/requirements.txt -r{toxinidir}/doc/requirements.txt
commands = commands =
rm -rf doc/build rm -rf doc/build
sphinx-build -b html doc/source doc/build/html sphinx-build -v -b html doc/source doc/build/html
[testenv:genconfig] [testenv:genconfig]
commands = commands =
@ -153,6 +153,7 @@ filterwarnings =
ignore:invalid escape sequence:DeprecationWarning:.*netaddr.* ignore:invalid escape sequence:DeprecationWarning:.*netaddr.*
ignore:invalid escape sequence:DeprecationWarning:.*prettytable ignore:invalid escape sequence:DeprecationWarning:.*prettytable
ignore:invalid escape sequence:DeprecationWarning:.*subunit.* ignore:invalid escape sequence:DeprecationWarning:.*subunit.*
ignore:invalid escape sequence:DeprecationWarning:.*docutils.*
# python 3.7 # python 3.7
ignore:Using or importing the ABCs:DeprecationWarning:unittest2.* ignore:Using or importing the ABCs:DeprecationWarning:unittest2.*
# python 3.8 # python 3.8