pyinfra 0.11.dev3__py3-none-any.whl → 3.6__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 (204) hide show
  1. pyinfra/__init__.py +9 -12
  2. pyinfra/__main__.py +4 -0
  3. pyinfra/api/__init__.py +19 -3
  4. pyinfra/api/arguments.py +413 -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 +73 -18
  12. pyinfra/api/facts.py +267 -200
  13. pyinfra/api/host.py +416 -50
  14. pyinfra/api/inventory.py +121 -160
  15. pyinfra/api/metadata.py +69 -0
  16. pyinfra/api/operation.py +432 -262
  17. pyinfra/api/operations.py +273 -260
  18. pyinfra/api/state.py +302 -248
  19. pyinfra/api/util.py +309 -369
  20. pyinfra/connectors/base.py +173 -0
  21. pyinfra/connectors/chroot.py +212 -0
  22. pyinfra/connectors/docker.py +405 -0
  23. pyinfra/connectors/dockerssh.py +297 -0
  24. pyinfra/connectors/local.py +238 -0
  25. pyinfra/connectors/scp/__init__.py +1 -0
  26. pyinfra/connectors/scp/client.py +204 -0
  27. pyinfra/connectors/ssh.py +727 -0
  28. pyinfra/connectors/ssh_util.py +114 -0
  29. pyinfra/connectors/sshuserclient/client.py +309 -0
  30. pyinfra/connectors/sshuserclient/config.py +102 -0
  31. pyinfra/connectors/terraform.py +135 -0
  32. pyinfra/connectors/util.py +417 -0
  33. pyinfra/connectors/vagrant.py +183 -0
  34. pyinfra/context.py +145 -0
  35. pyinfra/facts/__init__.py +7 -6
  36. pyinfra/facts/apk.py +22 -7
  37. pyinfra/facts/apt.py +117 -60
  38. pyinfra/facts/brew.py +100 -15
  39. pyinfra/facts/bsdinit.py +23 -0
  40. pyinfra/facts/cargo.py +37 -0
  41. pyinfra/facts/choco.py +47 -0
  42. pyinfra/facts/crontab.py +195 -0
  43. pyinfra/facts/deb.py +94 -0
  44. pyinfra/facts/dnf.py +48 -0
  45. pyinfra/facts/docker.py +96 -23
  46. pyinfra/facts/efibootmgr.py +113 -0
  47. pyinfra/facts/files.py +629 -58
  48. pyinfra/facts/flatpak.py +77 -0
  49. pyinfra/facts/freebsd.py +70 -0
  50. pyinfra/facts/gem.py +19 -6
  51. pyinfra/facts/git.py +59 -14
  52. pyinfra/facts/gpg.py +150 -0
  53. pyinfra/facts/hardware.py +313 -167
  54. pyinfra/facts/iptables.py +72 -62
  55. pyinfra/facts/launchd.py +44 -0
  56. pyinfra/facts/lxd.py +17 -4
  57. pyinfra/facts/mysql.py +122 -86
  58. pyinfra/facts/npm.py +17 -9
  59. pyinfra/facts/openrc.py +71 -0
  60. pyinfra/facts/opkg.py +246 -0
  61. pyinfra/facts/pacman.py +50 -7
  62. pyinfra/facts/pip.py +24 -7
  63. pyinfra/facts/pipx.py +82 -0
  64. pyinfra/facts/pkg.py +15 -6
  65. pyinfra/facts/pkgin.py +35 -0
  66. pyinfra/facts/podman.py +54 -0
  67. pyinfra/facts/postgres.py +178 -0
  68. pyinfra/facts/postgresql.py +6 -147
  69. pyinfra/facts/rpm.py +105 -0
  70. pyinfra/facts/runit.py +77 -0
  71. pyinfra/facts/selinux.py +161 -0
  72. pyinfra/facts/server.py +762 -285
  73. pyinfra/facts/snap.py +88 -0
  74. pyinfra/facts/systemd.py +139 -0
  75. pyinfra/facts/sysvinit.py +59 -0
  76. pyinfra/facts/upstart.py +35 -0
  77. pyinfra/facts/util/__init__.py +17 -0
  78. pyinfra/facts/util/databases.py +4 -6
  79. pyinfra/facts/util/packaging.py +37 -6
  80. pyinfra/facts/util/units.py +30 -0
  81. pyinfra/facts/util/win_files.py +99 -0
  82. pyinfra/facts/vzctl.py +20 -13
  83. pyinfra/facts/xbps.py +35 -0
  84. pyinfra/facts/yum.py +34 -40
  85. pyinfra/facts/zfs.py +77 -0
  86. pyinfra/facts/zypper.py +42 -0
  87. pyinfra/local.py +45 -83
  88. pyinfra/operations/__init__.py +12 -0
  89. pyinfra/operations/apk.py +99 -0
  90. pyinfra/operations/apt.py +496 -0
  91. pyinfra/operations/brew.py +232 -0
  92. pyinfra/operations/bsdinit.py +59 -0
  93. pyinfra/operations/cargo.py +45 -0
  94. pyinfra/operations/choco.py +61 -0
  95. pyinfra/operations/crontab.py +194 -0
  96. pyinfra/operations/dnf.py +213 -0
  97. pyinfra/operations/docker.py +492 -0
  98. pyinfra/operations/files.py +2014 -0
  99. pyinfra/operations/flatpak.py +95 -0
  100. pyinfra/operations/freebsd/__init__.py +12 -0
  101. pyinfra/operations/freebsd/freebsd_update.py +70 -0
  102. pyinfra/operations/freebsd/pkg.py +219 -0
  103. pyinfra/operations/freebsd/service.py +116 -0
  104. pyinfra/operations/freebsd/sysrc.py +92 -0
  105. pyinfra/operations/gem.py +48 -0
  106. pyinfra/operations/git.py +420 -0
  107. pyinfra/operations/iptables.py +312 -0
  108. pyinfra/operations/launchd.py +45 -0
  109. pyinfra/operations/lxd.py +69 -0
  110. pyinfra/operations/mysql.py +610 -0
  111. pyinfra/operations/npm.py +57 -0
  112. pyinfra/operations/openrc.py +63 -0
  113. pyinfra/operations/opkg.py +89 -0
  114. pyinfra/operations/pacman.py +82 -0
  115. pyinfra/operations/pip.py +206 -0
  116. pyinfra/operations/pipx.py +103 -0
  117. pyinfra/operations/pkg.py +71 -0
  118. pyinfra/operations/pkgin.py +92 -0
  119. pyinfra/operations/postgres.py +437 -0
  120. pyinfra/operations/postgresql.py +30 -0
  121. pyinfra/operations/puppet.py +41 -0
  122. pyinfra/operations/python.py +73 -0
  123. pyinfra/operations/runit.py +184 -0
  124. pyinfra/operations/selinux.py +190 -0
  125. pyinfra/operations/server.py +1100 -0
  126. pyinfra/operations/snap.py +118 -0
  127. pyinfra/operations/ssh.py +217 -0
  128. pyinfra/operations/systemd.py +150 -0
  129. pyinfra/operations/sysvinit.py +142 -0
  130. pyinfra/operations/upstart.py +68 -0
  131. pyinfra/operations/util/__init__.py +12 -0
  132. pyinfra/operations/util/docker.py +407 -0
  133. pyinfra/operations/util/files.py +247 -0
  134. pyinfra/operations/util/packaging.py +338 -0
  135. pyinfra/operations/util/service.py +46 -0
  136. pyinfra/operations/vzctl.py +137 -0
  137. pyinfra/operations/xbps.py +78 -0
  138. pyinfra/operations/yum.py +213 -0
  139. pyinfra/operations/zfs.py +176 -0
  140. pyinfra/operations/zypper.py +193 -0
  141. pyinfra/progress.py +44 -32
  142. pyinfra/py.typed +0 -0
  143. pyinfra/version.py +9 -1
  144. pyinfra-3.6.dist-info/METADATA +142 -0
  145. pyinfra-3.6.dist-info/RECORD +160 -0
  146. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info}/WHEEL +1 -2
  147. pyinfra-3.6.dist-info/entry_points.txt +12 -0
  148. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info/licenses}/LICENSE.md +1 -1
  149. pyinfra_cli/__init__.py +1 -0
  150. pyinfra_cli/cli.py +793 -0
  151. pyinfra_cli/commands.py +66 -0
  152. pyinfra_cli/exceptions.py +155 -65
  153. pyinfra_cli/inventory.py +233 -89
  154. pyinfra_cli/log.py +39 -43
  155. pyinfra_cli/main.py +26 -495
  156. pyinfra_cli/prints.py +215 -156
  157. pyinfra_cli/util.py +172 -105
  158. pyinfra_cli/virtualenv.py +25 -20
  159. pyinfra/api/connectors/__init__.py +0 -21
  160. pyinfra/api/connectors/ansible.py +0 -99
  161. pyinfra/api/connectors/docker.py +0 -178
  162. pyinfra/api/connectors/local.py +0 -169
  163. pyinfra/api/connectors/ssh.py +0 -402
  164. pyinfra/api/connectors/sshuserclient/client.py +0 -105
  165. pyinfra/api/connectors/sshuserclient/config.py +0 -90
  166. pyinfra/api/connectors/util.py +0 -63
  167. pyinfra/api/connectors/vagrant.py +0 -155
  168. pyinfra/facts/init.py +0 -176
  169. pyinfra/facts/util/files.py +0 -102
  170. pyinfra/hook.py +0 -41
  171. pyinfra/modules/__init__.py +0 -11
  172. pyinfra/modules/apk.py +0 -64
  173. pyinfra/modules/apt.py +0 -272
  174. pyinfra/modules/brew.py +0 -122
  175. pyinfra/modules/files.py +0 -711
  176. pyinfra/modules/gem.py +0 -30
  177. pyinfra/modules/git.py +0 -115
  178. pyinfra/modules/init.py +0 -344
  179. pyinfra/modules/iptables.py +0 -271
  180. pyinfra/modules/lxd.py +0 -45
  181. pyinfra/modules/mysql.py +0 -347
  182. pyinfra/modules/npm.py +0 -47
  183. pyinfra/modules/pacman.py +0 -60
  184. pyinfra/modules/pip.py +0 -99
  185. pyinfra/modules/pkg.py +0 -43
  186. pyinfra/modules/postgresql.py +0 -245
  187. pyinfra/modules/puppet.py +0 -20
  188. pyinfra/modules/python.py +0 -37
  189. pyinfra/modules/server.py +0 -524
  190. pyinfra/modules/ssh.py +0 -150
  191. pyinfra/modules/util/files.py +0 -52
  192. pyinfra/modules/util/packaging.py +0 -118
  193. pyinfra/modules/vzctl.py +0 -133
  194. pyinfra/modules/yum.py +0 -171
  195. pyinfra/pseudo_modules.py +0 -64
  196. pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
  197. pyinfra-0.11.dev3.dist-info/METADATA +0 -135
  198. pyinfra-0.11.dev3.dist-info/RECORD +0 -95
  199. pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
  200. pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
  201. pyinfra_cli/__main__.py +0 -40
  202. pyinfra_cli/config.py +0 -92
  203. /pyinfra/{modules/util → connectors}/__init__.py +0 -0
  204. /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,96 @@
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
+ """
30
+
31
+
32
+ class FactProcessError(FactError, RuntimeError):
33
+ """
34
+ Exception raised when the data gathered for a fact cannot be processed.
35
+ """
5
36
 
6
37
 
7
38
  class OperationError(PyinfraError):
8
- '''
39
+ """
9
40
  Exception raised during fact gathering staging if an operation is unable to
10
41
  generate output/change state.
11
- '''
42
+ """
43
+
44
+
45
+ class OperationTypeError(OperationError, TypeError):
46
+ """
47
+ Exception raised when an operation is passed invalid argument types.
48
+ """
49
+
50
+
51
+ class OperationValueError(OperationError, ValueError):
52
+ """
53
+ Exception raised when an operation is passed invalid argument values.
54
+ """
12
55
 
13
56
 
14
57
  class DeployError(PyinfraError):
15
- '''
58
+ """
16
59
  User exception for raising in deploys or sub deploys.
17
- '''
60
+ """
18
61
 
19
62
 
20
63
  class InventoryError(PyinfraError):
21
- '''
64
+ """
22
65
  Exception raised for inventory related errors.
23
- '''
66
+ """
24
67
 
25
68
 
26
- class NoConnectorError(PyinfraError, TypeError):
27
- '''
69
+ class NoConnectorError(PyinfraError, ValueError):
70
+ """
28
71
  Raised when a requested connector is missing.
29
- '''
72
+ """
30
73
 
31
74
 
32
- class NoHostError(PyinfraError, TypeError):
33
- '''
75
+ class NoHostError(PyinfraError, KeyError):
76
+ """
34
77
  Raised when an inventory is missing a host.
35
- '''
78
+ """
79
+
80
+
81
+ class NoGroupError(PyinfraError, KeyError):
82
+ """
83
+ Raised when an inventory is missing a group.
84
+ """
85
+
86
+
87
+ class ConnectorDataTypeError(PyinfraError, TypeError):
88
+ """
89
+ Raised when host connector data has invalid types.
90
+ """
36
91
 
37
92
 
38
- class NoGroupError(PyinfraError, TypeError):
39
- '''
40
- Raise when an inventory is missing a group.
41
- '''
93
+ class ArgumentTypeError(PyinfraError, TypeError):
94
+ """
95
+ Raised when global arguments are passed with invalid types.
96
+ """