Skip to content
Myr

Properly lazily import shutil (#3023)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rowlando13 · committed by GitHub · parents 4f936ac, 6f6cbbb · Browse files · 4 files+17 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+17 added−9 removed

  • tests:+0 added−1 removed
  • other:+17 added−8 removed

4 files+17 added−9 removed

modified:src/click/_termui_impl.py+13 added-5 removed
15 unmodified lines
16import typing as t17from gettext import gettext as _18from io import StringIO19from pathlib import Path20from shutil import which20from types import TracebackType2122from ._compat import _default_text_stdout23from ._compat import CYGWIN
209 unmodified lines
233 }234 ).rstrip()235236 def render_progress(self) -> None:238 import shutil239237 if self.hidden:238 return239240 if not self._is_atty:
5 unmodified lines
246247 buf = []248 # Update width in case the terminal has been resized249 if self.autowidth:250 import shutil251252 old_width = self.width253 self.width = 0254 clutter_length = term_len(self.format_progress_line())255 new_width = max(0, shutil.get_terminal_size().columns - clutter_length)
163 unmodified lines
419 """420 # Split the command into the invoked CLI and its parameters.421 if not cmd_parts:422 return False423424 import shutil425426 cmd = cmd_parts[0]427 cmd_params = cmd_parts[1:]428427 cmd_filepath = which(cmd)429 cmd_filepath = shutil.which(cmd)430 if not cmd_filepath:431 return False432 # Resolves symlinks and produces a normalized absolute path string.433 cmd_path = Path(cmd_filepath).resolve()
77 unmodified lines
511 """512 # Split the command into the invoked CLI and its parameters.513 if not cmd_parts:514 return False515516 import shutil517518 cmd = cmd_parts[0]519515 cmd_filepath = which(cmd)520 cmd_filepath = shutil.which(cmd)521 if not cmd_filepath:522 return False523 # Resolves symlinks and produces a normalized absolute path string.524 cmd_path = Path(cmd_filepath).resolve()
52 unmodified lines
577 if rv:578 return rv579 if WIN:580 return "notepad"581582 from shutil import which583584 for editor in "sensible-editor", "vim", "nano":585 if which(editor) is not None:586 return editor587 return "vi"
260 unmodified lines
modified:src/click/formatting.py+2 added-2 removed
117 unmodified lines
118 indent_increment: int = 2,119 width: int | None = None,120 max_width: int | None = None,121 ) -> None:122 import shutil123122 self.indent_increment = indent_increment123 if max_width is None:124 max_width = 80125 if width is None:126 import shutil127128 width = FORCED_WIDTH129 if width is None:130 width = max(min(shutil.get_terminal_size().columns, max_width) - 2, 50)131 self.width = width
170 unmodified lines
modified:src/click/testing.py+2 added-1 removed
3 unmodified lines
4import contextlib5import io6import os7import shlex8import shutil8import sys9import tempfile10import typing as t11from types import TracebackType
557 unmodified lines
569 finally:570 os.chdir(cwd)571572 if temp_dir is None:573 import shutil574575 try:576 shutil.rmtree(dt)577 except OSError:578 pass
modified:tests/test_imports.py-1 removed
41 unmodified lines
42 "io",43 "itertools",44 "os",45 "re",46 "shutil",46 "stat",47 "struct",48 "sys",49 "threading",
21 unmodified lines