Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/invoke/__init__.py: 89%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1from typing import Any, Optional 

2 

3from ._version import __version_info__, __version__ # noqa 

4from .collection import Collection # noqa 

5from .config import Config # noqa 

6from .context import Context, MockContext # noqa 

7from .exceptions import ( # noqa 

8 AmbiguousEnvVar, 

9 AuthFailure, 

10 CollectionNotFound, 

11 Exit, 

12 ParseError, 

13 PlatformError, 

14 ResponseNotAccepted, 

15 SubprocessPipeError, 

16 ThreadException, 

17 UncastableEnvVar, 

18 UnexpectedExit, 

19 UnknownFileType, 

20 UnpicklableConfigMember, 

21 WatcherError, 

22 CommandTimedOut, 

23) 

24from .executor import Executor # noqa 

25from .loader import FilesystemLoader # noqa 

26from .parser import Argument, Parser, ParserContext, ParseResult # noqa 

27from .program import Program # noqa 

28from .runners import Runner, Local, Failure, Result, Promise # noqa 

29from .tasks import task, call, Call, Task # noqa 

30from .terminals import pty_size # noqa 

31from .watchers import FailingResponder, Responder, StreamWatcher # noqa 

32 

33 

34def run(command: str, **kwargs: Any) -> Optional[Result]: 

35 """ 

36 Run ``command`` in a subprocess and return a `.Result` object. 

37 

38 See `.Runner.run` for API details. 

39 

40 .. note:: 

41 This function is a convenience wrapper around Invoke's `.Context` and 

42 `.Runner` APIs. 

43 

44 Specifically, it creates an anonymous `.Context` instance and calls its 

45 `~.Context.run` method, which in turn defaults to using a `.Local` 

46 runner subclass for command execution. 

47 

48 .. versionadded:: 1.0 

49 """ 

50 return Context().run(command, **kwargs) 

51 

52 

53def sudo(command: str, **kwargs: Any) -> Optional[Result]: 

54 """ 

55 Run ``command`` in a ``sudo`` subprocess and return a `.Result` object. 

56 

57 See `.Context.sudo` for API details, such as the ``password`` kwarg. 

58 

59 .. note:: 

60 This function is a convenience wrapper around Invoke's `.Context` and 

61 `.Runner` APIs. 

62 

63 Specifically, it creates an anonymous `.Context` instance and calls its 

64 `~.Context.sudo` method, which in turn defaults to using a `.Local` 

65 runner subclass for command execution (plus sudo-related bits & 

66 pieces). 

67 

68 .. versionadded:: 1.4 

69 """ 

70 return Context().sudo(command, **kwargs)