cli2 3.4.0__tar.gz → 4.0.0__tar.gz

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 (70) hide show
  1. cli2-4.0.0/PKG-INFO +66 -0
  2. cli2-4.0.0/README.rst +29 -0
  3. cli2-4.0.0/cli2/__init__.py +42 -0
  4. cli2-4.0.0/cli2/ansible/__init__.py +8 -0
  5. cli2-3.4.0/cli2/ansible.py → cli2-4.0.0/cli2/ansible/action.py +26 -8
  6. cli2-3.4.0/cli2/pytest_ansible.py → cli2-4.0.0/cli2/ansible/playbook.py +0 -6
  7. cli2-4.0.0/cli2/ansible/pytest.py +7 -0
  8. cli2-4.0.0/cli2/cli.py +1169 -0
  9. cli2-4.0.0/cli2/cli2.py +97 -0
  10. {cli2-3.4.0 → cli2-4.0.0}/cli2/client.py +6 -8
  11. {cli2-3.4.0 → cli2-4.0.0}/cli2/configuration.py +3 -0
  12. {cli2-3.4.0 → cli2-4.0.0}/cli2/display.py +23 -2
  13. cli2-4.0.0/cli2/examples/__init__.py +0 -0
  14. cli2-3.4.0/cli2/example_client.py → cli2-4.0.0/cli2/examples/client.py +2 -0
  15. cli2-4.0.0/cli2/examples/conf.py +6 -0
  16. cli2-4.0.0/cli2/examples/example.py +27 -0
  17. cli2-4.0.0/cli2/examples/example_obj.py +32 -0
  18. cli2-4.0.0/cli2/examples/obj2.py +34 -0
  19. cli2-4.0.0/cli2/examples/test.py +38 -0
  20. cli2-4.0.0/cli2/lock.py +151 -0
  21. cli2-3.4.0/cli2/logging.py → cli2-4.0.0/cli2/log.py +68 -0
  22. {cli2-3.4.0 → cli2-4.0.0}/cli2/table.py +42 -1
  23. cli2-4.0.0/cli2.egg-info/PKG-INFO +66 -0
  24. cli2-4.0.0/cli2.egg-info/SOURCES.txt +52 -0
  25. cli2-4.0.0/cli2.egg-info/entry_points.txt +9 -0
  26. {cli2-3.4.0 → cli2-4.0.0}/setup.py +7 -7
  27. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_ansible.py +29 -0
  28. cli2-4.0.0/tests/test_cli.py +83 -0
  29. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_client.py +1 -1
  30. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_command.py +75 -79
  31. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_decorators.py +23 -26
  32. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_entry_point.py +3 -6
  33. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_group.py +44 -57
  34. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_inject.py +5 -7
  35. cli2-4.0.0/tests/test_lock.py +44 -0
  36. cli2-4.0.0/tests/test_node.py +67 -0
  37. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_restful.py +13 -10
  38. cli2-3.4.0/PKG-INFO +0 -98
  39. cli2-3.4.0/README.rst +0 -61
  40. cli2-3.4.0/cli2/__init__.py +0 -56
  41. cli2-3.4.0/cli2/argument.py +0 -388
  42. cli2-3.4.0/cli2/cli.py +0 -42
  43. cli2-3.4.0/cli2/command.py +0 -451
  44. cli2-3.4.0/cli2/entry_point.py +0 -68
  45. cli2-3.4.0/cli2/example_client_complex.py +0 -40
  46. cli2-3.4.0/cli2/group.py +0 -240
  47. cli2-3.4.0/cli2/locker.py +0 -62
  48. cli2-3.4.0/cli2/overrides.py +0 -8
  49. cli2-3.4.0/cli2/test_cli.py +0 -48
  50. cli2-3.4.0/cli2/test_node.py +0 -109
  51. cli2-3.4.0/cli2.egg-info/PKG-INFO +0 -98
  52. cli2-3.4.0/cli2.egg-info/SOURCES.txt +0 -48
  53. cli2-3.4.0/cli2.egg-info/entry_points.txt +0 -9
  54. {cli2-3.4.0 → cli2-4.0.0}/MANIFEST.in +0 -0
  55. {cli2-3.4.0 → cli2-4.0.0}/classifiers.txt +0 -0
  56. {cli2-3.4.0 → cli2-4.0.0}/cli2/asyncio.py +0 -0
  57. {cli2-3.4.0 → cli2-4.0.0}/cli2/colors.py +0 -0
  58. {cli2-3.4.0 → cli2-4.0.0}/cli2/decorators.py +0 -0
  59. /cli2-3.4.0/cli2/example_nesting.py → /cli2-4.0.0/cli2/examples/nesting.py +0 -0
  60. /cli2-3.4.0/cli2/example_obj.py → /cli2-4.0.0/cli2/examples/obj.py +0 -0
  61. {cli2-3.4.0 → cli2-4.0.0}/cli2/node.py +0 -0
  62. {cli2-3.4.0 → cli2-4.0.0}/cli2/sphinx.py +0 -0
  63. {cli2-3.4.0 → cli2-4.0.0}/cli2/test.py +0 -0
  64. {cli2-3.4.0 → cli2-4.0.0}/cli2.egg-info/dependency_links.txt +0 -0
  65. {cli2-3.4.0 → cli2-4.0.0}/cli2.egg-info/requires.txt +0 -0
  66. {cli2-3.4.0 → cli2-4.0.0}/cli2.egg-info/top_level.txt +0 -0
  67. {cli2-3.4.0 → cli2-4.0.0}/setup.cfg +0 -0
  68. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_configuration.py +0 -0
  69. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_display.py +0 -0
  70. {cli2-3.4.0/cli2 → cli2-4.0.0/tests}/test_table.py +0 -0
cli2-4.0.0/PKG-INFO ADDED
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.2
2
+ Name: cli2
3
+ Version: 4.0.0
4
+ Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
+ Home-page: https://yourlabs.io/oss/cli2
6
+ Author: James Pic
7
+ Author-email: jamespic@gmail.com
8
+ License: MIT
9
+ Keywords: cli
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/x-rst
12
+ Requires-Dist: docstring_parser
13
+ Requires-Dist: pyyaml
14
+ Requires-Dist: pygments
15
+ Requires-Dist: structlog
16
+ Provides-Extra: client
17
+ Requires-Dist: httpx; extra == "client"
18
+ Requires-Dist: truststore; extra == "client"
19
+ Provides-Extra: test
20
+ Requires-Dist: freezegun; extra == "test"
21
+ Requires-Dist: pytest; extra == "test"
22
+ Requires-Dist: pytest-cov; extra == "test"
23
+ Requires-Dist: pytest-mock; extra == "test"
24
+ Requires-Dist: pytest-asyncio; extra == "test"
25
+ Requires-Dist: pytest-httpx; extra == "test"
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: keywords
32
+ Dynamic: license
33
+ Dynamic: provides-extra
34
+ Dynamic: requires-dist
35
+ Dynamic: requires-python
36
+ Dynamic: summary
37
+
38
+ .. image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
39
+ :target: https://yourlabs.io/oss/cli2/pipelines
40
+ .. image:: https://codecov.io/gh/yourlabs/cli2/branch/master/graph/badge.svg
41
+ :target: https://codecov.io/gh/yourlabs/cli2
42
+ .. image:: https://img.shields.io/pypi/v/cli2.svg
43
+ :target: https://pypi.python.org/pypi/cli2
44
+
45
+ cli2: Python Automation Framework
46
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
+
48
+ A Python command line and Ansible Action plugin framework that loves meta
49
+ programming: do less and get more out of it, perfect for many kinds of DevOps
50
+ gigs to automate everything.
51
+
52
+ Batteries included, all of which are useful on their own:
53
+
54
+ - beautiful CLI alternative to click, but much less verbose, allowing more
55
+ creative design patterns without any boilerplate thanks to introspection
56
+ - which comes with a Sphinx extension to extensively document your CLIs
57
+ - magic 12-factor configuration library
58
+ - extremely beautiful structlog configuration for colorful and readable logging
59
+ - httpx client wrapper that handles all kind of retries, data masking...
60
+ - magic ORM for HTTP resources based on that client
61
+ - Ansible Action plugin library with all the beautiful logging and a rich
62
+ testing library so that you can go straight to the point in pytest
63
+ - a good old fcntl based locking
64
+ - a command line to run any python function over a beautiful CLI
65
+
66
+ `Documentation available on RTFD <https://cli2.rtfd.io>`_.
cli2-4.0.0/README.rst ADDED
@@ -0,0 +1,29 @@
1
+ .. image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
2
+ :target: https://yourlabs.io/oss/cli2/pipelines
3
+ .. image:: https://codecov.io/gh/yourlabs/cli2/branch/master/graph/badge.svg
4
+ :target: https://codecov.io/gh/yourlabs/cli2
5
+ .. image:: https://img.shields.io/pypi/v/cli2.svg
6
+ :target: https://pypi.python.org/pypi/cli2
7
+
8
+ cli2: Python Automation Framework
9
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
+
11
+ A Python command line and Ansible Action plugin framework that loves meta
12
+ programming: do less and get more out of it, perfect for many kinds of DevOps
13
+ gigs to automate everything.
14
+
15
+ Batteries included, all of which are useful on their own:
16
+
17
+ - beautiful CLI alternative to click, but much less verbose, allowing more
18
+ creative design patterns without any boilerplate thanks to introspection
19
+ - which comes with a Sphinx extension to extensively document your CLIs
20
+ - magic 12-factor configuration library
21
+ - extremely beautiful structlog configuration for colorful and readable logging
22
+ - httpx client wrapper that handles all kind of retries, data masking...
23
+ - magic ORM for HTTP resources based on that client
24
+ - Ansible Action plugin library with all the beautiful logging and a rich
25
+ testing library so that you can go straight to the point in pytest
26
+ - a good old fcntl based locking
27
+ - a command line to run any python function over a beautiful CLI
28
+
29
+ `Documentation available on RTFD <https://cli2.rtfd.io>`_.
@@ -0,0 +1,42 @@
1
+ # flake8: noqa
2
+ from .cli import (
3
+ cmd,
4
+ arg,
5
+ hide,
6
+ retrieve,
7
+ Argument,
8
+ Command,
9
+ Group,
10
+ EntryPoint,
11
+ )
12
+ from .asyncio import async_resolve
13
+ from .colors import colors as c
14
+
15
+ from .configuration import Configuration, cfg
16
+ try:
17
+ from .client import (
18
+ ClientError,
19
+ ResponseError,
20
+ TokenGetError,
21
+ RefusedResponseError,
22
+ RetriesExceededError,
23
+ FieldError,
24
+ FieldValueError,
25
+ FieldExternalizeError,
26
+ Client,
27
+ DateTimeField,
28
+ Field,
29
+ Handler,
30
+ JSONStringField,
31
+ Model,
32
+ Paginator,
33
+ Related,
34
+ )
35
+ except ImportError:
36
+ raise
37
+ # httpx not installed
38
+ pass
39
+ from .display import diff, diff_data, render, print, highlight
40
+ from .lock import Lock
41
+ from .log import configure, log, get_logger
42
+ from .table import Table
@@ -0,0 +1,8 @@
1
+ # flake8: noqa
2
+ from .action import (
3
+ ansi_escape,
4
+ Option,
5
+ AnsibleError,
6
+ AnsibleOptionError,
7
+ ActionBase,
8
+ )
@@ -1,7 +1,5 @@
1
1
  """
2
2
  Experimental: my base class for Ansible actions.
3
-
4
- TODO: Turn this into a cool framework.
5
3
  """
6
4
 
7
5
  import asyncio
@@ -12,8 +10,6 @@ import os
12
10
  import re
13
11
  import traceback
14
12
 
15
- from cli2 import logging
16
-
17
13
  from ansible.plugins.action import ActionBase
18
14
 
19
15
  # colors:
@@ -154,14 +150,12 @@ class ActionBase(ActionBase):
154
150
  async def run_wrapped_async(self):
155
151
  self.verbosity = self.task_vars.get('ansible_verbosity', 0)
156
152
 
157
- if 'LOG_LEVEL' in os.environ or 'DEBUG' in os.environ:
158
- logging.configure()
159
- else:
153
+ if 'LOG_LEVEL' not in os.environ and 'DEBUG' not in os.environ:
160
154
  if self.verbosity == 1:
161
155
  os.environ['LOG_LEVEL'] = 'INFO'
162
156
  elif self.verbosity >= 2:
163
157
  os.environ['LOG_LEVEL'] = 'DEBUG'
164
- logging.configure()
158
+ cli2.configure()
165
159
 
166
160
  try:
167
161
  try:
@@ -174,6 +168,18 @@ class ActionBase(ActionBase):
174
168
 
175
169
  if isinstance(exc, AnsibleError):
176
170
  self.result['error'] = exc.message
171
+ elif isinstance(exc, cli2.ResponseError):
172
+ self.result.update(dict(
173
+ method=exc.method,
174
+ url=exc.url,
175
+ status_code=exc.status_code,
176
+ ))
177
+ key, value = self.client.response_log_data(exc.response)
178
+ if key:
179
+ self.result[f'response_{key}'] = value
180
+ key, value = self.client.request_log_data(exc.request)
181
+ if key:
182
+ self.result[f'request_{key}'] = value
177
183
  elif self.verbosity:
178
184
  traceback.print_exc()
179
185
 
@@ -265,9 +271,21 @@ class ActionBase(ActionBase):
265
271
  self._after_data = UNSET_DEFAULT
266
272
 
267
273
  def before_set(self, data, label='before'):
274
+ """
275
+ Set the data we're going to display the diff for at the end.
276
+
277
+ :param data: Dictionnary of data
278
+ :param label: Label to show in diff
279
+ """
268
280
  self._before_data = copy.deepcopy(data)
269
281
  self._before_label = label
270
282
 
271
283
  def after_set(self, data, label='after'):
284
+ """
285
+ Set the data we're going to display the diff for at the end.
286
+
287
+ :param data: Dictionnary of data
288
+ :param label: Label to show in diff
289
+ """
272
290
  self._after_data = copy.deepcopy(data)
273
291
  self._after_label = label
@@ -1,6 +1,5 @@
1
1
  import copy
2
2
  import os
3
- import pytest
4
3
  import re
5
4
  import shlex
6
5
  import shutil
@@ -214,8 +213,3 @@ class Playbook:
214
213
  if not exception:
215
214
  check_ansible_output_for_exception(result['exception'])
216
215
  return result
217
-
218
-
219
- @pytest.fixture
220
- def playbook(tmp_path, request):
221
- return Playbook(tmp_path, name=request.node.originalname)
@@ -0,0 +1,7 @@
1
+ import pytest
2
+ from .playbook import Playbook
3
+
4
+
5
+ @pytest.fixture
6
+ def playbook(tmp_path, request):
7
+ return Playbook(tmp_path, name=request.node.originalname)