From ee09cab5463c077f6f568d687e5f2323ccbde885 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Thu, 8 Apr 2021 14:21:12 +0300 Subject: [PATCH] Get rid of decorator lib This lib is used only in two places and the latest release fails now. Change-Id: Ia79008c6ac7dc3be92afdea5f8ffabcd697e7599 --- rally/cli/envutils.py | 32 ++++++++++++++++++++------------ rally/plugins/__init__.py | 13 +++++++------ requirements.txt | 1 - tox.ini | 3 ++- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/rally/cli/envutils.py b/rally/cli/envutils.py index 1bd8aa533f..c305b42938 100755 --- a/rally/cli/envutils.py +++ b/rally/cli/envutils.py @@ -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(): diff --git a/rally/plugins/__init__.py b/rally/plugins/__init__.py index 5ea7975199..795ece79dc 100644 --- a/rally/plugins/__init__.py +++ b/rally/plugins/__init__.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 540034c264..ee7de9f2a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index 92debd2e11..d66fb6c9c4 100644 --- a/tox.ini +++ b/tox.ini @@ -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