pyinfra 0.11.dev3__py3-none-any.whl → 3.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. pyinfra/__init__.py +9 -12
  2. pyinfra/__main__.py +4 -0
  3. pyinfra/api/__init__.py +18 -3
  4. pyinfra/api/arguments.py +406 -0
  5. pyinfra/api/arguments_typed.py +79 -0
  6. pyinfra/api/command.py +274 -0
  7. pyinfra/api/config.py +222 -28
  8. pyinfra/api/connect.py +33 -13
  9. pyinfra/api/connectors.py +27 -0
  10. pyinfra/api/deploy.py +65 -66
  11. pyinfra/api/exceptions.py +67 -18
  12. pyinfra/api/facts.py +253 -202
  13. pyinfra/api/host.py +413 -50
  14. pyinfra/api/inventory.py +121 -160
  15. pyinfra/api/operation.py +432 -262
  16. pyinfra/api/operations.py +273 -260
  17. pyinfra/api/state.py +302 -248
  18. pyinfra/api/util.py +291 -368
  19. pyinfra/connectors/base.py +173 -0
  20. pyinfra/connectors/chroot.py +212 -0
  21. pyinfra/connectors/docker.py +381 -0
  22. pyinfra/connectors/dockerssh.py +297 -0
  23. pyinfra/connectors/local.py +238 -0
  24. pyinfra/connectors/scp/__init__.py +1 -0
  25. pyinfra/connectors/scp/client.py +204 -0
  26. pyinfra/connectors/ssh.py +670 -0
  27. pyinfra/connectors/ssh_util.py +114 -0
  28. pyinfra/connectors/sshuserclient/client.py +309 -0
  29. pyinfra/connectors/sshuserclient/config.py +102 -0
  30. pyinfra/connectors/terraform.py +135 -0
  31. pyinfra/connectors/util.py +410 -0
  32. pyinfra/connectors/vagrant.py +183 -0
  33. pyinfra/context.py +145 -0
  34. pyinfra/facts/__init__.py +7 -6
  35. pyinfra/facts/apk.py +22 -7
  36. pyinfra/facts/apt.py +117 -60
  37. pyinfra/facts/brew.py +100 -15
  38. pyinfra/facts/bsdinit.py +23 -0
  39. pyinfra/facts/cargo.py +37 -0
  40. pyinfra/facts/choco.py +47 -0
  41. pyinfra/facts/crontab.py +195 -0
  42. pyinfra/facts/deb.py +94 -0
  43. pyinfra/facts/dnf.py +48 -0
  44. pyinfra/facts/docker.py +96 -23
  45. pyinfra/facts/efibootmgr.py +113 -0
  46. pyinfra/facts/files.py +630 -58
  47. pyinfra/facts/flatpak.py +77 -0
  48. pyinfra/facts/freebsd.py +70 -0
  49. pyinfra/facts/gem.py +19 -6
  50. pyinfra/facts/git.py +59 -14
  51. pyinfra/facts/gpg.py +150 -0
  52. pyinfra/facts/hardware.py +313 -167
  53. pyinfra/facts/iptables.py +72 -62
  54. pyinfra/facts/launchd.py +44 -0
  55. pyinfra/facts/lxd.py +17 -4
  56. pyinfra/facts/mysql.py +122 -86
  57. pyinfra/facts/npm.py +17 -9
  58. pyinfra/facts/openrc.py +71 -0
  59. pyinfra/facts/opkg.py +246 -0
  60. pyinfra/facts/pacman.py +50 -7
  61. pyinfra/facts/pip.py +24 -7
  62. pyinfra/facts/pipx.py +82 -0
  63. pyinfra/facts/pkg.py +15 -6
  64. pyinfra/facts/pkgin.py +35 -0
  65. pyinfra/facts/podman.py +54 -0
  66. pyinfra/facts/postgres.py +178 -0
  67. pyinfra/facts/postgresql.py +6 -147
  68. pyinfra/facts/rpm.py +105 -0
  69. pyinfra/facts/runit.py +77 -0
  70. pyinfra/facts/selinux.py +161 -0
  71. pyinfra/facts/server.py +746 -285
  72. pyinfra/facts/snap.py +88 -0
  73. pyinfra/facts/systemd.py +139 -0
  74. pyinfra/facts/sysvinit.py +59 -0
  75. pyinfra/facts/upstart.py +35 -0
  76. pyinfra/facts/util/__init__.py +17 -0
  77. pyinfra/facts/util/databases.py +4 -6
  78. pyinfra/facts/util/packaging.py +37 -6
  79. pyinfra/facts/util/units.py +30 -0
  80. pyinfra/facts/util/win_files.py +99 -0
  81. pyinfra/facts/vzctl.py +20 -13
  82. pyinfra/facts/xbps.py +35 -0
  83. pyinfra/facts/yum.py +34 -40
  84. pyinfra/facts/zfs.py +77 -0
  85. pyinfra/facts/zypper.py +42 -0
  86. pyinfra/local.py +45 -83
  87. pyinfra/operations/__init__.py +12 -0
  88. pyinfra/operations/apk.py +98 -0
  89. pyinfra/operations/apt.py +488 -0
  90. pyinfra/operations/brew.py +231 -0
  91. pyinfra/operations/bsdinit.py +59 -0
  92. pyinfra/operations/cargo.py +45 -0
  93. pyinfra/operations/choco.py +61 -0
  94. pyinfra/operations/crontab.py +191 -0
  95. pyinfra/operations/dnf.py +210 -0
  96. pyinfra/operations/docker.py +446 -0
  97. pyinfra/operations/files.py +1939 -0
  98. pyinfra/operations/flatpak.py +94 -0
  99. pyinfra/operations/freebsd/__init__.py +12 -0
  100. pyinfra/operations/freebsd/freebsd_update.py +70 -0
  101. pyinfra/operations/freebsd/pkg.py +219 -0
  102. pyinfra/operations/freebsd/service.py +116 -0
  103. pyinfra/operations/freebsd/sysrc.py +92 -0
  104. pyinfra/operations/gem.py +47 -0
  105. pyinfra/operations/git.py +419 -0
  106. pyinfra/operations/iptables.py +311 -0
  107. pyinfra/operations/launchd.py +45 -0
  108. pyinfra/operations/lxd.py +68 -0
  109. pyinfra/operations/mysql.py +609 -0
  110. pyinfra/operations/npm.py +57 -0
  111. pyinfra/operations/openrc.py +63 -0
  112. pyinfra/operations/opkg.py +88 -0
  113. pyinfra/operations/pacman.py +81 -0
  114. pyinfra/operations/pip.py +205 -0
  115. pyinfra/operations/pipx.py +102 -0
  116. pyinfra/operations/pkg.py +70 -0
  117. pyinfra/operations/pkgin.py +91 -0
  118. pyinfra/operations/postgres.py +436 -0
  119. pyinfra/operations/postgresql.py +30 -0
  120. pyinfra/operations/puppet.py +40 -0
  121. pyinfra/operations/python.py +72 -0
  122. pyinfra/operations/runit.py +184 -0
  123. pyinfra/operations/selinux.py +189 -0
  124. pyinfra/operations/server.py +1099 -0
  125. pyinfra/operations/snap.py +117 -0
  126. pyinfra/operations/ssh.py +216 -0
  127. pyinfra/operations/systemd.py +149 -0
  128. pyinfra/operations/sysvinit.py +141 -0
  129. pyinfra/operations/upstart.py +68 -0
  130. pyinfra/operations/util/__init__.py +12 -0
  131. pyinfra/operations/util/docker.py +251 -0
  132. pyinfra/operations/util/files.py +247 -0
  133. pyinfra/operations/util/packaging.py +336 -0
  134. pyinfra/operations/util/service.py +46 -0
  135. pyinfra/operations/vzctl.py +137 -0
  136. pyinfra/operations/xbps.py +77 -0
  137. pyinfra/operations/yum.py +210 -0
  138. pyinfra/operations/zfs.py +175 -0
  139. pyinfra/operations/zypper.py +192 -0
  140. pyinfra/progress.py +44 -32
  141. pyinfra/py.typed +0 -0
  142. pyinfra/version.py +9 -1
  143. pyinfra-3.5.1.dist-info/METADATA +141 -0
  144. pyinfra-3.5.1.dist-info/RECORD +159 -0
  145. {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info}/WHEEL +1 -2
  146. pyinfra-3.5.1.dist-info/entry_points.txt +12 -0
  147. {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info/licenses}/LICENSE.md +1 -1
  148. pyinfra_cli/__init__.py +1 -0
  149. pyinfra_cli/cli.py +780 -0
  150. pyinfra_cli/commands.py +66 -0
  151. pyinfra_cli/exceptions.py +155 -65
  152. pyinfra_cli/inventory.py +233 -89
  153. pyinfra_cli/log.py +39 -43
  154. pyinfra_cli/main.py +26 -495
  155. pyinfra_cli/prints.py +215 -156
  156. pyinfra_cli/util.py +172 -105
  157. pyinfra_cli/virtualenv.py +25 -20
  158. pyinfra/api/connectors/__init__.py +0 -21
  159. pyinfra/api/connectors/ansible.py +0 -99
  160. pyinfra/api/connectors/docker.py +0 -178
  161. pyinfra/api/connectors/local.py +0 -169
  162. pyinfra/api/connectors/ssh.py +0 -402
  163. pyinfra/api/connectors/sshuserclient/client.py +0 -105
  164. pyinfra/api/connectors/sshuserclient/config.py +0 -90
  165. pyinfra/api/connectors/util.py +0 -63
  166. pyinfra/api/connectors/vagrant.py +0 -155
  167. pyinfra/facts/init.py +0 -176
  168. pyinfra/facts/util/files.py +0 -102
  169. pyinfra/hook.py +0 -41
  170. pyinfra/modules/__init__.py +0 -11
  171. pyinfra/modules/apk.py +0 -64
  172. pyinfra/modules/apt.py +0 -272
  173. pyinfra/modules/brew.py +0 -122
  174. pyinfra/modules/files.py +0 -711
  175. pyinfra/modules/gem.py +0 -30
  176. pyinfra/modules/git.py +0 -115
  177. pyinfra/modules/init.py +0 -344
  178. pyinfra/modules/iptables.py +0 -271
  179. pyinfra/modules/lxd.py +0 -45
  180. pyinfra/modules/mysql.py +0 -347
  181. pyinfra/modules/npm.py +0 -47
  182. pyinfra/modules/pacman.py +0 -60
  183. pyinfra/modules/pip.py +0 -99
  184. pyinfra/modules/pkg.py +0 -43
  185. pyinfra/modules/postgresql.py +0 -245
  186. pyinfra/modules/puppet.py +0 -20
  187. pyinfra/modules/python.py +0 -37
  188. pyinfra/modules/server.py +0 -524
  189. pyinfra/modules/ssh.py +0 -150
  190. pyinfra/modules/util/files.py +0 -52
  191. pyinfra/modules/util/packaging.py +0 -118
  192. pyinfra/modules/vzctl.py +0 -133
  193. pyinfra/modules/yum.py +0 -171
  194. pyinfra/pseudo_modules.py +0 -64
  195. pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
  196. pyinfra-0.11.dev3.dist-info/METADATA +0 -135
  197. pyinfra-0.11.dev3.dist-info/RECORD +0 -95
  198. pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
  199. pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
  200. pyinfra_cli/__main__.py +0 -40
  201. pyinfra_cli/config.py +0 -92
  202. /pyinfra/{modules/util → connectors}/__init__.py +0 -0
  203. /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
pyinfra/api/deploy.py CHANGED
@@ -1,22 +1,30 @@
1
- '''
1
+ """
2
2
  Deploys come in two forms: on-disk, eg deploy.py, and @deploy wrapped functions.
3
3
  The latter enable re-usable (across CLI and API based execution) pyinfra extension
4
4
  creation (eg pyinfra-openstack).
5
- '''
5
+ """
6
6
 
7
7
  from functools import wraps
8
+ from typing import TYPE_CHECKING, Any, Callable, Optional, cast
8
9
 
9
- from pyinfra import logger, pseudo_host, pseudo_state
10
- from pyinfra.pseudo_modules import PseudoModule
10
+ from typing_extensions import ParamSpec
11
11
 
12
+ import pyinfra
13
+ from pyinfra import context
14
+ from pyinfra.context import ctx_host, ctx_state
15
+
16
+ from .arguments import pop_global_arguments
17
+ from .arguments_typed import PyinfraOperation
12
18
  from .exceptions import PyinfraError
13
19
  from .host import Host
14
- from .state import State
15
- from .util import get_caller_frameinfo, pop_op_kwargs
20
+ from .util import get_call_location
21
+
22
+ if TYPE_CHECKING:
23
+ from pyinfra.api.state import State
16
24
 
17
25
 
18
- def add_deploy(state, deploy_func, *args, **kwargs):
19
- '''
26
+ def add_deploy(state: "State", deploy_func: Callable[..., Any], *args, **kwargs) -> None:
27
+ """
20
28
  Prepare & add an deploy to pyinfra.state by executing it on all hosts.
21
29
 
22
30
  Args:
@@ -24,75 +32,66 @@ def add_deploy(state, deploy_func, *args, **kwargs):
24
32
  deploy_func (function): the operation function from one of the modules,
25
33
  ie ``server.user``
26
34
  args/kwargs: passed to the operation function
27
- '''
35
+ """
36
+
37
+ if pyinfra.is_cli:
38
+ raise PyinfraError(
39
+ (
40
+ "`add_deploy` should not be called when pyinfra is executing in CLI mode! ({0})"
41
+ ).format(get_call_location()),
42
+ )
43
+
44
+ hosts = kwargs.pop("host", state.inventory.iter_active_hosts())
45
+ if isinstance(hosts, Host):
46
+ hosts = [hosts]
28
47
 
29
- frameinfo = get_caller_frameinfo()
30
- kwargs['frameinfo'] = frameinfo
48
+ with ctx_state.use(state):
49
+ for deploy_host in hosts:
50
+ with ctx_host.use(deploy_host):
51
+ deploy_func(*args, **kwargs)
31
52
 
32
- for host in state.inventory:
33
- deploy_func(state, host, *args, **kwargs)
34
53
 
54
+ P = ParamSpec("P")
35
55
 
36
- def deploy(func_or_name, data_defaults=None):
37
- '''
56
+
57
+ def deploy(
58
+ name: Optional[str] = None, data_defaults: Optional[dict] = None
59
+ ) -> Callable[[Callable[P, Any]], PyinfraOperation[P]]:
60
+ """
38
61
  Decorator that takes a deploy function (normally from a pyinfra_* package)
39
62
  and wraps any operations called inside with any deploy-wide kwargs/data.
40
- '''
63
+ """
41
64
 
42
- # If not decorating, return function with config attached
43
- if isinstance(func_or_name, str):
44
- name = func_or_name
65
+ if name and not isinstance(name, str):
66
+ raise PyinfraError(
67
+ (
68
+ "The `deploy` decorator must be called, ie `@deploy()`, "
69
+ "see: https://docs.pyinfra.com/en/3.x/compatibility.html#upgrading-pyinfra-from-2-x-3-x" # noqa
70
+ )
71
+ )
45
72
 
46
- def decorator(f):
47
- setattr(f, 'deploy_name', name)
73
+ def decorator(func: Callable[P, Any]) -> PyinfraOperation[P]:
74
+ func.deploy_name = name or func.__name__ # type: ignore[attr-defined]
75
+ if data_defaults:
76
+ func.deploy_data = data_defaults # type: ignore[attr-defined]
77
+ return _wrap_deploy(func)
48
78
 
49
- if data_defaults:
50
- setattr(f, 'deploy_data', data_defaults)
79
+ return decorator
51
80
 
52
- return deploy(f)
53
81
 
54
- return decorator
82
+ def _wrap_deploy(func: Callable[P, Any]) -> PyinfraOperation[P]:
83
+ @wraps(func)
84
+ def decorated_func(*args: P.args, **kwargs: P.kwargs) -> Any:
85
+ deploy_kwargs, _ = pop_global_arguments(context.state, context.host, kwargs)
55
86
 
56
- # Actually decorate!
57
- func = func_or_name
87
+ deploy_data = getattr(func, "deploy_data", None)
58
88
 
59
- @wraps(func)
60
- def decorated_func(*args, **kwargs):
61
- # If we're in CLI mode, there's no state/host passed down, we need to
62
- # use the global "pseudo" modules.
63
- if len(args) < 2 or not (
64
- isinstance(args[0], (State, PseudoModule))
65
- and isinstance(args[1], (Host, PseudoModule))
89
+ with context.host.deploy(
90
+ name=func.deploy_name, # type: ignore[attr-defined]
91
+ kwargs=deploy_kwargs,
92
+ data=deploy_data,
66
93
  ):
67
- state = pseudo_state._module
68
- host = pseudo_host._module
69
-
70
- if state.in_deploy:
71
- raise PyinfraError((
72
- 'Nested deploy called without state/host: {0}'
73
- ).format(func))
74
-
75
- # Otherwise (API mode) we just trim off the commands
76
- else:
77
- args_copy = list(args)
78
- state, host = args[0], args[1]
79
- args = args_copy[2:]
80
-
81
- # In API mode we have the kwarg - if a nested deploy we actually
82
- # want the frame of the caller (ie inside the deploy package).
83
- frameinfo = kwargs.pop('frameinfo', get_caller_frameinfo())
84
- logger.debug('Adding deploy, called @ {0}:{1}'.format(
85
- frameinfo.filename, frameinfo.lineno,
86
- ))
87
-
88
- deploy_kwargs = pop_op_kwargs(state, kwargs)
89
-
90
- # Name the deploy
91
- deploy_name = getattr(func, 'deploy_name', func.__name__)
92
- deploy_data = getattr(func, 'deploy_data', None)
93
-
94
- with state.deploy(deploy_name, deploy_kwargs, deploy_data, frameinfo.lineno):
95
- # Execute the deploy, passing state and host
96
- func(state, host, *args, **kwargs)
97
-
98
- return decorated_func
94
+ return func(*args, **kwargs)
95
+
96
+ decorated_func._inner = func # type: ignore[attr-defined]
97
+ return cast(PyinfraOperation[P], decorated_func)
pyinfra/api/exceptions.py CHANGED
@@ -1,41 +1,90 @@
1
1
  class PyinfraError(Exception):
2
- '''
2
+ """
3
3
  Generic pyinfra exception.
4
- '''
4
+ """
5
+
6
+
7
+ class ConnectError(PyinfraError):
8
+ """
9
+ Exception raised when connecting fails.
10
+ """
11
+
12
+
13
+ class FactError(PyinfraError):
14
+ """
15
+ Exception raised during fact gathering staging if a fact is unable to
16
+ generate output/change state.
17
+ """
18
+
19
+
20
+ class FactTypeError(FactError, TypeError):
21
+ """
22
+ Exception raised when a fact is passed invalid argument types.
23
+ """
24
+
25
+
26
+ class FactValueError(FactError, ValueError):
27
+ """
28
+ Exception raised when a fact is passed invalid argument values.
29
+ """
5
30
 
6
31
 
7
32
  class OperationError(PyinfraError):
8
- '''
33
+ """
9
34
  Exception raised during fact gathering staging if an operation is unable to
10
35
  generate output/change state.
11
- '''
36
+ """
37
+
38
+
39
+ class OperationTypeError(OperationError, TypeError):
40
+ """
41
+ Exception raised when an operation is passed invalid argument types.
42
+ """
43
+
44
+
45
+ class OperationValueError(OperationError, ValueError):
46
+ """
47
+ Exception raised when an operation is passed invalid argument values.
48
+ """
12
49
 
13
50
 
14
51
  class DeployError(PyinfraError):
15
- '''
52
+ """
16
53
  User exception for raising in deploys or sub deploys.
17
- '''
54
+ """
18
55
 
19
56
 
20
57
  class InventoryError(PyinfraError):
21
- '''
58
+ """
22
59
  Exception raised for inventory related errors.
23
- '''
60
+ """
24
61
 
25
62
 
26
- class NoConnectorError(PyinfraError, TypeError):
27
- '''
63
+ class NoConnectorError(PyinfraError, ValueError):
64
+ """
28
65
  Raised when a requested connector is missing.
29
- '''
66
+ """
30
67
 
31
68
 
32
- class NoHostError(PyinfraError, TypeError):
33
- '''
69
+ class NoHostError(PyinfraError, KeyError):
70
+ """
34
71
  Raised when an inventory is missing a host.
35
- '''
72
+ """
73
+
74
+
75
+ class NoGroupError(PyinfraError, KeyError):
76
+ """
77
+ Raised when an inventory is missing a group.
78
+ """
79
+
80
+
81
+ class ConnectorDataTypeError(PyinfraError, TypeError):
82
+ """
83
+ Raised when host connector data has invalid types.
84
+ """
36
85
 
37
86
 
38
- class NoGroupError(PyinfraError, TypeError):
39
- '''
40
- Raise when an inventory is missing a group.
41
- '''
87
+ class ArgumentTypeError(PyinfraError, TypeError):
88
+ """
89
+ Raised when global arguments are passed with invalid types.
90
+ """