pyinfra 3.0b0__py2.py3-none-any.whl → 3.0b2__py2.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 (115) hide show
  1. pyinfra/api/__init__.py +3 -0
  2. pyinfra/api/arguments.py +12 -5
  3. pyinfra/api/arguments_typed.py +19 -6
  4. pyinfra/api/command.py +5 -3
  5. pyinfra/api/config.py +115 -13
  6. pyinfra/api/connectors.py +5 -2
  7. pyinfra/api/exceptions.py +19 -0
  8. pyinfra/api/facts.py +34 -33
  9. pyinfra/api/host.py +51 -12
  10. pyinfra/api/inventory.py +4 -0
  11. pyinfra/api/operation.py +88 -42
  12. pyinfra/api/operations.py +10 -11
  13. pyinfra/api/state.py +11 -2
  14. pyinfra/api/util.py +24 -16
  15. pyinfra/connectors/base.py +4 -7
  16. pyinfra/connectors/chroot.py +5 -6
  17. pyinfra/connectors/docker.py +13 -19
  18. pyinfra/connectors/dockerssh.py +5 -4
  19. pyinfra/connectors/local.py +7 -7
  20. pyinfra/connectors/ssh.py +46 -25
  21. pyinfra/connectors/terraform.py +9 -6
  22. pyinfra/connectors/util.py +7 -8
  23. pyinfra/connectors/vagrant.py +11 -10
  24. pyinfra/context.py +1 -0
  25. pyinfra/facts/apk.py +2 -0
  26. pyinfra/facts/apt.py +2 -0
  27. pyinfra/facts/brew.py +2 -0
  28. pyinfra/facts/bsdinit.py +2 -0
  29. pyinfra/facts/cargo.py +2 -0
  30. pyinfra/facts/choco.py +3 -1
  31. pyinfra/facts/deb.py +9 -4
  32. pyinfra/facts/dnf.py +2 -0
  33. pyinfra/facts/docker.py +2 -0
  34. pyinfra/facts/files.py +2 -0
  35. pyinfra/facts/gem.py +2 -0
  36. pyinfra/facts/gpg.py +2 -0
  37. pyinfra/facts/hardware.py +30 -22
  38. pyinfra/facts/launchd.py +2 -0
  39. pyinfra/facts/lxd.py +2 -0
  40. pyinfra/facts/mysql.py +12 -6
  41. pyinfra/facts/npm.py +1 -0
  42. pyinfra/facts/openrc.py +2 -0
  43. pyinfra/facts/pacman.py +6 -2
  44. pyinfra/facts/pip.py +2 -0
  45. pyinfra/facts/pkg.py +2 -0
  46. pyinfra/facts/pkgin.py +2 -0
  47. pyinfra/facts/postgres.py +168 -0
  48. pyinfra/facts/postgresql.py +5 -162
  49. pyinfra/facts/rpm.py +12 -9
  50. pyinfra/facts/server.py +10 -13
  51. pyinfra/facts/snap.py +2 -0
  52. pyinfra/facts/systemd.py +28 -10
  53. pyinfra/facts/upstart.py +2 -0
  54. pyinfra/facts/util/packaging.py +3 -2
  55. pyinfra/facts/vzctl.py +2 -0
  56. pyinfra/facts/xbps.py +2 -0
  57. pyinfra/facts/yum.py +2 -0
  58. pyinfra/facts/zypper.py +2 -0
  59. pyinfra/operations/apk.py +3 -1
  60. pyinfra/operations/apt.py +16 -18
  61. pyinfra/operations/brew.py +10 -8
  62. pyinfra/operations/bsdinit.py +5 -3
  63. pyinfra/operations/cargo.py +3 -1
  64. pyinfra/operations/choco.py +3 -1
  65. pyinfra/operations/dnf.py +15 -19
  66. pyinfra/operations/files.py +86 -69
  67. pyinfra/operations/gem.py +3 -1
  68. pyinfra/operations/git.py +18 -16
  69. pyinfra/operations/iptables.py +33 -25
  70. pyinfra/operations/launchd.py +5 -6
  71. pyinfra/operations/lxd.py +7 -4
  72. pyinfra/operations/mysql.py +57 -53
  73. pyinfra/operations/npm.py +8 -1
  74. pyinfra/operations/openrc.py +5 -3
  75. pyinfra/operations/pacman.py +4 -5
  76. pyinfra/operations/pip.py +16 -9
  77. pyinfra/operations/pkg.py +3 -1
  78. pyinfra/operations/pkgin.py +3 -1
  79. pyinfra/operations/postgres.py +349 -0
  80. pyinfra/operations/postgresql.py +18 -335
  81. pyinfra/operations/puppet.py +3 -1
  82. pyinfra/operations/python.py +7 -3
  83. pyinfra/operations/selinux.py +42 -16
  84. pyinfra/operations/server.py +48 -43
  85. pyinfra/operations/snap.py +3 -1
  86. pyinfra/operations/ssh.py +12 -10
  87. pyinfra/operations/systemd.py +13 -9
  88. pyinfra/operations/sysvinit.py +6 -4
  89. pyinfra/operations/upstart.py +5 -3
  90. pyinfra/operations/util/files.py +24 -16
  91. pyinfra/operations/util/packaging.py +53 -37
  92. pyinfra/operations/util/service.py +18 -13
  93. pyinfra/operations/vzctl.py +12 -10
  94. pyinfra/operations/xbps.py +3 -1
  95. pyinfra/operations/yum.py +14 -18
  96. pyinfra/operations/zypper.py +8 -9
  97. pyinfra/version.py +5 -2
  98. {pyinfra-3.0b0.dist-info → pyinfra-3.0b2.dist-info}/METADATA +31 -29
  99. pyinfra-3.0b2.dist-info/RECORD +163 -0
  100. {pyinfra-3.0b0.dist-info → pyinfra-3.0b2.dist-info}/WHEEL +1 -1
  101. pyinfra_cli/commands.py +3 -2
  102. pyinfra_cli/inventory.py +38 -19
  103. pyinfra_cli/main.py +2 -0
  104. pyinfra_cli/prints.py +27 -105
  105. pyinfra_cli/util.py +3 -1
  106. tests/test_api/test_api_deploys.py +5 -5
  107. tests/test_api/test_api_operations.py +5 -5
  108. tests/test_connectors/test_ssh.py +105 -0
  109. tests/test_connectors/test_terraform.py +11 -8
  110. tests/test_connectors/test_vagrant.py +6 -6
  111. pyinfra-3.0b0.dist-info/RECORD +0 -162
  112. pyinfra_cli/inventory_dsl.py +0 -23
  113. {pyinfra-3.0b0.dist-info → pyinfra-3.0b2.dist-info}/LICENSE.md +0 -0
  114. {pyinfra-3.0b0.dist-info → pyinfra-3.0b2.dist-info}/entry_points.txt +0 -0
  115. {pyinfra-3.0b0.dist-info → pyinfra-3.0b2.dist-info}/top_level.txt +0 -0
pyinfra/operations/apt.py CHANGED
@@ -2,6 +2,8 @@
2
2
  Manage apt packages and repositories.
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  from datetime import timedelta
6
8
  from urllib.parse import urlparse
7
9
 
@@ -19,7 +21,7 @@ from .util.packaging import ensure_packages
19
21
  APT_UPDATE_FILENAME = "/var/lib/apt/periodic/update-success-stamp"
20
22
 
21
23
 
22
- def noninteractive_apt(command, force=False):
24
+ def noninteractive_apt(command: str, force=False):
23
25
  args = ["DEBIAN_FRONTEND=noninteractive apt-get -y"]
24
26
 
25
27
  if force:
@@ -37,7 +39,7 @@ def noninteractive_apt(command, force=False):
37
39
 
38
40
 
39
41
  @operation()
40
- def key(src=None, keyserver=None, keyid=None):
42
+ def key(src: str | None = None, keyserver: str | None = None, keyid: str | list[str] | None = None):
41
43
  """
42
44
  Add apt gpg keys with ``apt-key``.
43
45
 
@@ -103,7 +105,7 @@ def key(src=None, keyserver=None, keyid=None):
103
105
 
104
106
 
105
107
  @operation()
106
- def repo(src, present=True, filename=None):
108
+ def repo(src: str, present=True, filename: str | None = None):
107
109
  """
108
110
  Add/remove apt repositories.
109
111
 
@@ -162,7 +164,7 @@ def repo(src, present=True, filename=None):
162
164
 
163
165
 
164
166
  @operation(is_idempotent=False)
165
- def ppa(src, present=True):
167
+ def ppa(src: str, present=True):
166
168
  """
167
169
  Add/remove Ubuntu ppa repositories.
168
170
 
@@ -192,7 +194,7 @@ def ppa(src, present=True):
192
194
 
193
195
 
194
196
  @operation()
195
- def deb(src, present=True, force=False):
197
+ def deb(src: str, present=True, force=False):
196
198
  """
197
199
  Add/remove ``.deb`` file packages.
198
200
 
@@ -233,18 +235,14 @@ def deb(src, present=True, force=False):
233
235
  src = temp_filename
234
236
 
235
237
  # Check for file .deb information (if file is present)
236
- info = host.get_fact(DebPackage, name=src)
238
+ info = host.get_fact(DebPackage, package=src)
237
239
  current_packages = host.get_fact(DebPackages)
238
240
 
239
241
  exists = False
240
242
 
241
243
  # We have deb info! Check against installed packages
242
- if info:
243
- if (
244
- info["name"] in current_packages
245
- and info.get("version") in current_packages[info["name"]]
246
- ):
247
- exists = True
244
+ if info and info.get("version") in current_packages.get(info.get("name"), {}):
245
+ exists = True
248
246
 
249
247
  # Package does not exist and we want?
250
248
  if present:
@@ -277,7 +275,7 @@ def deb(src, present=True, force=False):
277
275
  "unless the ``cache_time`` argument is provided."
278
276
  ),
279
277
  )
280
- def update(cache_time=None):
278
+ def update(cache_time: int | None = None):
281
279
  """
282
280
  Updates apt repositories.
283
281
 
@@ -335,7 +333,7 @@ def upgrade(auto_remove: bool = False):
335
333
 
336
334
  # Upgrade all packages and remove unneeded transitive dependencies
337
335
  apt.upgrade(
338
- name="Upgrade apt packages and remove unneeded dependencies"
336
+ name="Upgrade apt packages and remove unneeded dependencies",
339
337
  auto_remove=True
340
338
  )
341
339
  """
@@ -370,17 +368,17 @@ def dist_upgrade():
370
368
 
371
369
  @operation()
372
370
  def packages(
373
- packages=None,
371
+ packages: str | list[str] | None = None,
374
372
  present=True,
375
373
  latest=False,
376
374
  update=False,
377
- cache_time=None,
375
+ cache_time: int | None = None,
378
376
  upgrade=False,
379
377
  force=False,
380
378
  no_recommends=False,
381
379
  allow_downgrades=False,
382
- extra_install_args=None,
383
- extra_uninstall_args=None,
380
+ extra_install_args: str | None = None,
381
+ extra_uninstall_args: str | None = None,
384
382
  ):
385
383
  """
386
384
  Install/remove/update packages & update apt.
@@ -2,7 +2,9 @@
2
2
  Manage brew packages on mac/OSX. See https://brew.sh/
3
3
  """
4
4
 
5
- import urllib
5
+ from __future__ import annotations
6
+
7
+ import urllib.parse
6
8
 
7
9
  from pyinfra import host
8
10
  from pyinfra.api import operation
@@ -37,7 +39,7 @@ _upgrade = upgrade # noqa: E305
37
39
 
38
40
  @operation()
39
41
  def packages(
40
- packages=None,
42
+ packages: str | list[str] | None = None,
41
43
  present=True,
42
44
  latest=False,
43
45
  update=False,
@@ -93,7 +95,7 @@ def packages(
93
95
  )
94
96
 
95
97
 
96
- def cask_args(host):
98
+ def cask_args():
97
99
  return ("", " --cask") if new_cask_cli(host.get_fact(BrewVersion)) else ("cask ", "")
98
100
 
99
101
 
@@ -103,12 +105,12 @@ def cask_upgrade():
103
105
  Upgrades all brew casks.
104
106
  """
105
107
 
106
- yield "brew %supgrade%s" % cask_args(host)
108
+ yield "brew %supgrade%s" % cask_args()
107
109
 
108
110
 
109
111
  @operation()
110
112
  def casks(
111
- casks=None,
113
+ casks: str | list[str] | None = None,
112
114
  present=True,
113
115
  latest=False,
114
116
  upgrade=False,
@@ -140,7 +142,7 @@ def casks(
140
142
  if upgrade:
141
143
  yield from cask_upgrade._inner()
142
144
 
143
- args = cask_args(host)
145
+ args = cask_args()
144
146
 
145
147
  yield from ensure_packages(
146
148
  host,
@@ -156,7 +158,7 @@ def casks(
156
158
 
157
159
 
158
160
  @operation()
159
- def tap(src=None, present=True, url=None):
161
+ def tap(src: str | None = None, present=True, url: str | None = None):
160
162
  """
161
163
  Add/remove brew taps.
162
164
 
@@ -199,7 +201,7 @@ def tap(src=None, present=True, url=None):
199
201
  host.noop("no tap was specified")
200
202
  return
201
203
 
202
- src = src or urllib.parse.urlparse(url).path.strip("/")
204
+ src = src or str(urllib.parse.urlparse(url).path).strip("/")
203
205
 
204
206
  if len(src.split("/")) != 2:
205
207
  host.noop("src '{0}' doesn't have two components.".format(src))
@@ -2,6 +2,8 @@
2
2
  Manage BSD init services (``/etc/rc.d``, ``/usr/local/etc/rc.d``).
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  from pyinfra import host
6
8
  from pyinfra.api import operation
7
9
  from pyinfra.facts.bsdinit import RcdStatus
@@ -13,12 +15,12 @@ from .util.service import handle_service_control
13
15
 
14
16
  @operation()
15
17
  def service(
16
- service,
18
+ service: str,
17
19
  running=True,
18
20
  restarted=False,
19
21
  reloaded=False,
20
- command=None,
21
- enabled=None,
22
+ command: str | None = None,
23
+ enabled: bool | None = None,
22
24
  ):
23
25
  """
24
26
  Manage the state of BSD init services.
@@ -2,6 +2,8 @@
2
2
  Manage cargo (aka Rust) packages.
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  from pyinfra import host
6
8
  from pyinfra.api import operation
7
9
  from pyinfra.facts.cargo import CargoPackages
@@ -10,7 +12,7 @@ from .util.packaging import ensure_packages
10
12
 
11
13
 
12
14
  @operation()
13
- def packages(packages=None, present=True, latest=False):
15
+ def packages(packages: str | list[str] | None = None, present=True, latest=False):
14
16
  """
15
17
  Install/remove/update cargo packages.
16
18
 
@@ -2,6 +2,8 @@
2
2
  Manage ``choco`` (Chocolatey) packages (https://chocolatey.org).
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  from pyinfra import host
6
8
  from pyinfra.api import operation
7
9
  from pyinfra.facts.choco import ChocoPackages
@@ -10,7 +12,7 @@ from .util.packaging import ensure_packages
10
12
 
11
13
 
12
14
  @operation()
13
- def packages(packages=None, present=True, latest=False):
15
+ def packages(packages: str | list[str] | None = None, present=True, latest=False):
14
16
  """
15
17
  Add/remove/update ``choco`` packages.
16
18
 
pyinfra/operations/dnf.py CHANGED
@@ -2,16 +2,17 @@
2
2
  Manage dnf packages and repositories. Note that dnf package names are case-sensitive.
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  from pyinfra import host, state
6
8
  from pyinfra.api import operation
7
9
  from pyinfra.facts.rpm import RpmPackageProvides, RpmPackages
8
10
 
9
- from . import files
10
11
  from .util.packaging import ensure_packages, ensure_rpm, ensure_yum_repo
11
12
 
12
13
 
13
14
  @operation(is_idempotent=False)
14
- def key(src):
15
+ def key(src: str):
15
16
  """
16
17
  Add dnf gpg keys with ``rpm``.
17
18
 
@@ -37,19 +38,19 @@ def key(src):
37
38
 
38
39
  @operation()
39
40
  def repo(
40
- src,
41
+ src: str,
41
42
  present=True,
42
- baseurl=None,
43
- description=None,
43
+ baseurl: str | None = None,
44
+ description: str | None = None,
44
45
  enabled=True,
45
46
  gpgcheck=True,
46
- gpgkey=None,
47
+ gpgkey: str | None = None,
47
48
  ):
48
49
  # NOTE: if updating this docstring also update `yum.repo`
49
50
  """
50
51
  Add/remove/update dnf repositories.
51
52
 
52
- + name: URL or name for the ``.repo`` file
53
+ + src: URL or name for the ``.repo`` file
53
54
  + present: whether the ``.repo`` file should be present
54
55
  + baseurl: the baseurl of the repo (if ``name`` is not a URL)
55
56
  + description: optional verbose description
@@ -81,9 +82,7 @@ def repo(
81
82
  """
82
83
 
83
84
  yield from ensure_yum_repo(
84
- state,
85
85
  host,
86
- files,
87
86
  src,
88
87
  baseurl,
89
88
  present,
@@ -95,7 +94,7 @@ def repo(
95
94
 
96
95
 
97
96
  @operation()
98
- def rpm(src, present=True):
97
+ def rpm(src: str, present=True):
99
98
  # NOTE: if updating this docstring also update `yum.rpm`
100
99
  """
101
100
  Add/remove ``.rpm`` file packages.
@@ -118,7 +117,7 @@ def rpm(src, present=True):
118
117
  )
119
118
  """
120
119
 
121
- yield from ensure_rpm(state, host, files, src, present, "dnf")
120
+ yield from ensure_rpm(state, host, src, present, "dnf")
122
121
 
123
122
 
124
123
  @operation(is_idempotent=False)
@@ -135,19 +134,19 @@ _update = update._inner # noqa: E305 (for use below where update is a kwarg)
135
134
 
136
135
  @operation()
137
136
  def packages(
138
- packages=None,
137
+ packages: str | list[str] | None = None,
139
138
  present=True,
140
139
  latest=False,
141
140
  update=False,
142
141
  clean=False,
143
142
  nobest=False,
144
- extra_install_args=None,
145
- extra_uninstall_args=None,
143
+ extra_install_args: str | None = None,
144
+ extra_uninstall_args: str | None = None,
146
145
  ):
147
146
  """
148
147
  Install/remove/update dnf packages & updates.
149
148
 
150
- + packages: list of packages to ensure
149
+ + packages: packages to ensure
151
150
  + present: whether the packages should be installed
152
151
  + latest: whether to upgrade packages without a specified version
153
152
  + update: run ``dnf update`` before installing packages
@@ -207,8 +206,5 @@ def packages(
207
206
  upgrade_command="dnf update -y",
208
207
  version_join="=",
209
208
  latest=latest,
210
- expand_package_fact=lambda package: host.get_fact(
211
- RpmPackageProvides,
212
- name=package,
213
- ),
209
+ expand_package_fact=lambda package: host.get_fact(RpmPackageProvides, package=package),
214
210
  )