Unverified Kaydet (Commit) 74102c9a authored tarafından Berker Peksag's avatar Berker Peksag Kaydeden (comit) GitHub

bpo-13041: Use shutil.get_terminal_size() in argparse.HelpFormatter (GH-8459)

üst c0f0a766
...@@ -85,6 +85,7 @@ __all__ = [ ...@@ -85,6 +85,7 @@ __all__ = [
import os as _os import os as _os
import re as _re import re as _re
import shutil as _shutil
import sys as _sys import sys as _sys
from gettext import gettext as _, ngettext from gettext import gettext as _, ngettext
...@@ -164,10 +165,7 @@ class HelpFormatter(object): ...@@ -164,10 +165,7 @@ class HelpFormatter(object):
# default setting for width # default setting for width
if width is None: if width is None:
try: width = _shutil.get_terminal_size().columns
width = int(_os.environ['COLUMNS'])
except (KeyError, ValueError):
width = 80
width -= 2 width -= 2
self._prog = prog self._prog = prog
......
...@@ -23,9 +23,9 @@ class TestCase(unittest.TestCase): ...@@ -23,9 +23,9 @@ class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
# The tests assume that line wrapping occurs at 80 columns, but this # The tests assume that line wrapping occurs at 80 columns, but this
# behaviour can be overridden by setting the COLUMNS environment # behaviour can be overridden by setting the COLUMNS environment
# variable. To ensure that this assumption is true, unset COLUMNS. # variable. To ensure that this width is used, set COLUMNS to 80.
env = support.EnvironmentVarGuard() env = support.EnvironmentVarGuard()
env.unset("COLUMNS") env['COLUMNS'] = '80'
self.addCleanup(env.__exit__) self.addCleanup(env.__exit__)
...@@ -5122,6 +5122,7 @@ class TestImportStar(TestCase): ...@@ -5122,6 +5122,7 @@ class TestImportStar(TestCase):
class TestWrappingMetavar(TestCase): class TestWrappingMetavar(TestCase):
def setUp(self): def setUp(self):
super().setUp()
self.parser = ErrorRaisingArgumentParser( self.parser = ErrorRaisingArgumentParser(
'this_is_spammy_prog_with_a_long_name_sorry_about_the_name' 'this_is_spammy_prog_with_a_long_name_sorry_about_the_name'
) )
......
Use :func:`shutil.get_terminal_size` to calculate the terminal width
correctly in the ``argparse.HelpFormatter`` class. Initial patch by Zbyszek
Jędrzejewski-Szmek.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment