Add a Singleton metaclass, use it with Display (#48935)

* Add a Singleton class, use it with Display

* update six import

* Move remaining failes to display singleton

* Fix rebase issues

* Singleton improvements

* Add code-smell for 'from __main__ import display'. ci_complete

* s/self/cls/g

* Add docs for no-main-display

* Address linting issues

* Add changelog fragment. ci_complete

* Implement reentrant lock for class instantiation in Singleton

* Add Display singleton porting guide
This commit is contained in:
Matt Martz 2018-11-20 17:06:51 -06:00 committed by GitHub
commit 9773a1f289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
149 changed files with 407 additions and 766 deletions

View file

@ -20,8 +20,8 @@ from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_va
def _warning(msg):
''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
try:
from __main__ import display
display.warning(msg)
from ansible.utils.display import Display
Display().warning(msg)
except Exception:
import sys
sys.stderr.write(' [WARNING] %s\n' % (msg))
@ -30,8 +30,8 @@ def _warning(msg):
def _deprecated(msg, version='2.8'):
''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
try:
from __main__ import display
display.deprecated(msg, version=version)
from ansible.utils.display import Display
Display().deprecated(msg, version=version)
except Exception:
import sys
sys.stderr.write(' [DEPRECATED] %s, to be removed in %s\n' % (msg, version))