keith-turner commented on a change in pull request #288: Refactor config URL: https://github.com/apache/fluo-muchos/pull/288#discussion_r332186305
########## File path: lib/muchos/config/decorators.py ########## @@ -0,0 +1,98 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from collections.abc import Iterable +from functools import wraps + + +_host_vars = [] +_play_vars = [] +_extra_vars = [] +_ansible_vars = dict( + host=[], + play=[], + extra=[] +) + +def get_ansible_vars(var_type): + return _ansible_vars.get(var_type) + +# ansible hosts inventory variables +def ansible_host_var(name=None): + return ansible_var_decorator('host', name) + +# ansible group/all variables +def ansible_play_var(name=None): + return ansible_var_decorator('play', name) + +# ansible extra variables +def ansible_extra_var(name=None): + return ansible_var_decorator('extra', name) + +def ansible_var_decorator(var_type, name): + def _decorator(func): + _ansible_vars[var_type].append((name if isinstance(name, str) else func.__name__, func.__qualname__.split('.')[0], func.__name__)) Review comment: This might be a terrible idea. When reading about decorators, I was also reading about function pointers. That made me wonder it it would make sense to replace `func.__name__` with just `func` for the last item? Like ```python _ansible_vars[var_type].append((name if isinstance(name, str) else func.__name__, func.__qualname__.split('.')[0], func)) ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
