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

View File

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

View File

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

View File

@ -77,7 +77,7 @@ deps =
-r{toxinidir}/doc/requirements.txt
commands =
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]
commands =
@ -153,6 +153,7 @@ filterwarnings =
ignore:invalid escape sequence:DeprecationWarning:.*netaddr.*
ignore:invalid escape sequence:DeprecationWarning:.*prettytable
ignore:invalid escape sequence:DeprecationWarning:.*subunit.*
ignore:invalid escape sequence:DeprecationWarning:.*docutils.*
# python 3.7
ignore:Using or importing the ABCs:DeprecationWarning:unittest2.*
# python 3.8