From 3430bde60ae65b54c08ffa73de1f16643c7c3bfd Mon Sep 17 00:00:00 2001 From: "Odegard, Ken" Date: Thu, 13 Jul 2017 11:44:10 +0200 Subject: Expanded ability of import Renamed GIT_PYTHON_NOWARN to GIT_PYTHON_INITERR and added values for quiet import, warning import, and raise import. These respectively mean that no message or error is printed if git is non-existent, a plain warning is printed but the import succeeds, and an ImportError exception is raised. --- git/cmd.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index ae7721df..0bf0fee4 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -232,11 +232,20 @@ class Git(LazyMixin): # executable cls.GIT_PYTHON_GIT_EXECUTABLE = cls.git_exec_name - # test if the user didn't want a warning - nowarn = os.environ.get("GIT_PYTHON_NOWARN", "false") - nowarn = nowarn.lower() in ["t", "true", "y", "yes"] - - if not nowarn: + # determine what the user wanted to happen + # we expect GIT_PYTHON_INITERR to either be unset or be one of + # the following values: + # q|quiet|s|silence + # w|warn|warning + # r|raise|e|error + initerr_quiet = ["q", "quiet", "s", "silence"] + initerr_warn = ["w", "warn", "warning"] + initerr_raise = ["r", "raise", "e", "error"] + + initerr = os.environ.get("GIT_PYTHON_INITERR", "warn").lower() + if initerr in initerr_quiet: + pass + elif initerr in initerr_warn: print(dedent("""\ WARNING: %s All git commands will error until this is rectified. @@ -244,6 +253,19 @@ class Git(LazyMixin): This initial warning can be silenced in the future by setting the environment variable: export GIT_PYTHON_NOWARN=true """) % err) + elif initerr in initerr_raise: + raise ImportError(err) + else: + err = dedent("""\ + GIT_PYTHON_INITERR environment variable has been set but it has been set with an invalid value. + + Use only the following values: + (1) q|quiet|s|silence: for no warning or exception + (2) w|warn|warning: for a printed warning + (3) r|raise|e|error: for a raised exception + """) + raise ImportError(err) + else: # after the first setup (when GIT_PYTHON_GIT_EXECUTABLE # is no longer None) we raise an exception and reset the -- cgit v1.2.1