Skip to content

Commit

Permalink
Warn if HIDE_WINDOWS_*_ERRORS set in environment
Browse files Browse the repository at this point in the history
This warns if the HIDE_WINDOWS_KNOWN_ERRORS or
HIDE_WINDOWS_FREEZE_ERRORS environment variables are set. These
behave unexpectedly, including (and especially) in their effect on
the same-named git.util module attributes, and neither their
effects nor those of those attributes are documented in a way that
would have supported code outside the project relying on their
specific semantics.

The new warning message characterizes their status as deprecated.

- This is now the case for HIDE_WINDOWS_KNOWN_ERRORS, and
  almost so for the same-named attribute, whose existence (though
  not its meaning) can technically be relied on due to inclusion in
  `__all__` (which this does *not* change).

- But the HIDE_WINDOWS_FREEZE_ERRORS attribute was never guaranteed
  even to exist, so technically neither it nor the same-named
  environment variable are not *even* deprecated. The attribute's
  presence has never been reflected in the public interface of any
  GitPython component in any way.

However, these attributes are still used by the tests. Furthermore,
in the case of HIDE_WINDOWS_KNOWN_ERRORS, setting it is the only
way to disable the behavior of converting errors from some file
deletion operations into SkipTest exceptions on Windows. Since that
behavior has not yet changed, but is unlikely to be desired outside
of testing, no *attributes* are deprecated at this time, and no
effort to warn from accessing or using attributes is attempted.
  • Loading branch information
EliahKagan committed Oct 7, 2023
1 parent 9ba4222 commit 0f1aacb
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,28 @@

log = logging.getLogger(__name__)

# types############################################################

def _read_env_flag(name: str, default: bool) -> bool:
try:
value = os.environ[name]
except KeyError:
return default

log.warning(
"The %s environment variable is deprecated. Its effect has never been documented and changes without warning.",
name,
)

# FIXME: This should always return bool, as that is how it is used.
# FIXME: This should treat some values besides "" as expressing falsehood.
return value


#: We need an easy way to see if Appveyor TCs start failing,
#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy,
#: till then, we wish to hide them.
HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get("HIDE_WINDOWS_KNOWN_ERRORS", True)
HIDE_WINDOWS_FREEZE_ERRORS = is_win and os.environ.get("HIDE_WINDOWS_FREEZE_ERRORS", True)
HIDE_WINDOWS_KNOWN_ERRORS = is_win and _read_env_flag("HIDE_WINDOWS_KNOWN_ERRORS", True)
HIDE_WINDOWS_FREEZE_ERRORS = is_win and _read_env_flag("HIDE_WINDOWS_FREEZE_ERRORS", True)

# { Utility Methods

Expand Down

0 comments on commit 0f1aacb

Please sign in to comment.