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
Provenance
- Commit
1f40020- Tree
b6502fc- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
4f936ac- Parent 2
6f6cbbb
4 files changed+17 added−9 removed
modified:src/click/_termui_impl.py+13 added-5 removed
15 unmodified lines16 import typing as t17 from gettext import gettext as _18 from io import StringIO19 from pathlib import Path20-from shutil import which20 from types import TracebackType21 22 from ._compat import _default_text_stdout23 from ._compat import CYGWIN209 unmodified lines233 }234 ).rstrip()235 236 def render_progress(self) -> None:238- import shutil239-237 if self.hidden:238 return239 240 if not self._is_atty:5 unmodified lines246 247 buf = []248 # Update width in case the terminal has been resized249 if self.autowidth:250+ import shutil251+252 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 lines419 """420 # Split the command into the invoked CLI and its parameters.421 if not cmd_parts:422 return False423+424+ import shutil425+426 cmd = cmd_parts[0]427 cmd_params = cmd_parts[1:]428 427- 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 lines511 """512 # Split the command into the invoked CLI and its parameters.513 if not cmd_parts:514 return False515+516+ import shutil517+518 cmd = cmd_parts[0]519 515- 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 lines577 if rv:578 return rv579 if WIN:580 return "notepad"581+582+ from shutil import which583+584 for editor in "sensible-editor", "vim", "nano":585 if which(editor) is not None:586 return editor587 return "vi"260 unmodified linesmodified:src/click/formatting.py+2 added-2 removed
117 unmodified lines118 indent_increment: int = 2,119 width: int | None = None,120 max_width: int | None = None,121 ) -> None:122- import shutil123-122 self.indent_increment = indent_increment123 if max_width is None:124 max_width = 80125 if width is None:126+ import shutil127+128 width = FORCED_WIDTH129 if width is None:130 width = max(min(shutil.get_terminal_size().columns, max_width) - 2, 50)131 self.width = width170 unmodified linesmodified:src/click/testing.py+2 added-1 removed
3 unmodified lines4 import contextlib5 import io6 import os7 import shlex8-import shutil8 import sys9 import tempfile10 import typing as t11 from types import TracebackType557 unmodified lines569 finally:570 os.chdir(cwd)571 572 if temp_dir is None:573+ import shutil574+575 try:576 shutil.rmtree(dt)577 except OSError:578 passmodified:tests/test_imports.py-1 removed
41 unmodified lines42 "io",43 "itertools",44 "os",45 "re",46- "shutil",46 "stat",47 "struct",48 "sys",49 "threading",21 unmodified lines