Skip to content

Commit

Permalink
[Cherry-pick] solve ANSI escape sequences print error in cmd and pow…
Browse files Browse the repository at this point in the history
…ershell (#33689) (#33715)

解决windows cmd和powershell显示乱码的问题
  • Loading branch information
thisjiang authored Jun 22, 2021
1 parent 3b3bd93 commit a029d36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/paddle/fluid/dygraph/varbase_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import warnings
import weakref
import sys

import paddle
from .. import framework
Expand Down Expand Up @@ -372,6 +373,9 @@ def grad(self):
"""
msg = "tensor.grad will return the tensor value of the gradient."
warning_msg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
# ensure ANSI escape sequences print correctly in cmd and powershell
if sys.platform.lower() == 'win32':
warning_msg = "\nWarning:\n%s " % (msg)
warnings.warn(warning_msg)
return self._grad_ivar()

Expand Down
5 changes: 5 additions & 0 deletions python/paddle/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import warnings
import functools
import paddle
import sys

__all__ = []

Expand Down Expand Up @@ -99,6 +100,10 @@ def wrapper(*args, **kwargs):
func.__module__, func.__name__))

warningmsg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
# ensure ANSI escape sequences print correctly in cmd and powershell
if sys.platform.lower() == 'win32':
warningmsg = "\nWarning:\n%s " % (msg)

v_current = [int(i) for i in paddle.__version__.split(".")]
v_current += [0] * (4 - len(v_current))
v_since = [int(i) for i in _since.split(".")]
Expand Down

0 comments on commit a029d36

Please sign in to comment.