cli2 5.1.8__tar.gz → 5.2.1rc1__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 (60) hide show
  1. {cli2-5.1.8/cli2.egg-info → cli2-5.2.1rc1}/PKG-INFO +2 -1
  2. {cli2-5.1.8 → cli2-5.2.1rc1}/README.rst +1 -0
  3. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/__init__.py +2 -0
  4. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/cli.py +19 -3
  5. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/test.py +2 -2
  6. {cli2-5.1.8 → cli2-5.2.1rc1/cli2.egg-info}/PKG-INFO +2 -1
  7. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2.egg-info/SOURCES.txt +1 -0
  8. {cli2-5.1.8 → cli2-5.2.1rc1}/setup.py +1 -1
  9. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_command.py +2 -2
  10. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_inject.py +1 -1
  11. cli2-5.2.1rc1/tests/test_prompt2.py +144 -0
  12. {cli2-5.1.8 → cli2-5.2.1rc1}/MANIFEST.in +0 -0
  13. {cli2-5.1.8 → cli2-5.2.1rc1}/classifiers.txt +0 -0
  14. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/asyncio.py +0 -0
  15. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/cli2.py +0 -0
  16. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/colors.py +0 -0
  17. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/configuration.py +0 -0
  18. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/decorators.py +0 -0
  19. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/display.py +0 -0
  20. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/__init__.py +0 -0
  21. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/conf.py +0 -0
  22. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/example.py +0 -0
  23. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/example_obj.py +0 -0
  24. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/nesting.py +0 -0
  25. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/obj.py +0 -0
  26. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/obj2.py +0 -0
  27. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/examples/test.py +0 -0
  28. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/interactive.py +0 -0
  29. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/lock.py +0 -0
  30. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/log.py +0 -0
  31. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/mask.py +0 -0
  32. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/node.py +0 -0
  33. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/notlevenshtein.py +0 -0
  34. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/sphinx.py +0 -0
  35. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/table.py +0 -0
  36. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2/theme.py +0 -0
  37. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2.egg-info/dependency_links.txt +0 -0
  38. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2.egg-info/entry_points.txt +0 -0
  39. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2.egg-info/requires.txt +0 -0
  40. {cli2-5.1.8 → cli2-5.2.1rc1}/cli2.egg-info/top_level.txt +0 -0
  41. {cli2-5.1.8 → cli2-5.2.1rc1}/setup.cfg +0 -0
  42. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_ansible.py +0 -0
  43. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_ansible_variables.py +0 -0
  44. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_asyncio.py +0 -0
  45. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_cli.py +0 -0
  46. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_client.py +0 -0
  47. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_client_test.py +0 -0
  48. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_configuration.py +0 -0
  49. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_decorators.py +0 -0
  50. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_display.py +0 -0
  51. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_entry_point.py +0 -0
  52. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_group.py +0 -0
  53. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_interactive.py +0 -0
  54. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_lock.py +0 -0
  55. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_log.py +0 -0
  56. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_mask.py +0 -0
  57. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_node.py +0 -0
  58. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_notlevenshtein.py +0 -0
  59. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_restful.py +0 -0
  60. {cli2-5.1.8 → cli2-5.2.1rc1}/tests/test_table.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cli2
3
- Version: 5.1.8
3
+ Version: 5.2.1rc1
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -63,5 +63,6 @@ Batteries included, all of which are useful on their own:
63
63
  testing library so that you can go straight to the point in pytest
64
64
  - a good old fcntl based locking
65
65
  - a command line to run any python function over a beautiful CLI
66
+ - **AI assisted programing CLI & framework with code2**
66
67
 
67
68
  `Documentation available on RTFD <https://cli2.rtfd.io>`_.
@@ -25,5 +25,6 @@ Batteries included, all of which are useful on their own:
25
25
  testing library so that you can go straight to the point in pytest
26
26
  - a good old fcntl based locking
27
27
  - a command line to run any python function over a beautiful CLI
28
+ - **AI assisted programing CLI & framework with code2**
28
29
 
29
30
  `Documentation available on RTFD <https://cli2.rtfd.io>`_.
@@ -8,6 +8,8 @@ from .cli import (
8
8
  Command,
9
9
  Group,
10
10
  EntryPoint,
11
+ Cli2Error,
12
+ Cli2ValueError,
11
13
  )
12
14
  from .asyncio import async_resolve, async_run, Queue
13
15
  from .colors import colors as c
@@ -14,6 +14,14 @@ from .asyncio import async_resolve
14
14
  from .colors import colors
15
15
 
16
16
 
17
+ class Cli2Error(Exception):
18
+ pass
19
+
20
+
21
+ class Cli2ValueError(Cli2Error):
22
+ pass
23
+
24
+
17
25
  class Overrides(dict):
18
26
  """
19
27
  Lazy overrides dict
@@ -652,9 +660,14 @@ class Command(EntryPoint, dict):
652
660
  except KeyboardInterrupt:
653
661
  print('exiting cleanly...')
654
662
  self.exit_code = 1
663
+ except Exception as exc:
664
+ self.handle_exception(exc)
655
665
  finally:
656
666
  self.post_result = self.post_call()
657
667
 
668
+ def handle_exception(self, exc):
669
+ raise exc
670
+
658
671
  async def async_call(self, *argv):
659
672
  """ Call with async stuff in single event loop """
660
673
  error = self.parse(*argv)
@@ -669,8 +682,11 @@ class Command(EntryPoint, dict):
669
682
 
670
683
  await self.factories_resolve()
671
684
 
672
- result = self.call(*self.bound.args, **self.bound.kwargs)
673
- return await async_resolve(result, output=True)
685
+ try:
686
+ result = self.call(*self.bound.args, **self.bound.kwargs)
687
+ return await async_resolve(result, output=True)
688
+ except Exception as exc:
689
+ self.handle_exception(exc)
674
690
 
675
691
  async def factories_resolve(self):
676
692
  """ Resolve all factories values. """
@@ -1047,7 +1063,7 @@ class Argument:
1047
1063
  if self.default != self.param.empty:
1048
1064
  return self.default
1049
1065
  msg = f'{self.param.name} has no CLI bound value nor default'
1050
- raise ValueError(msg) from exc
1066
+ raise Cli2ValueError(msg) from exc
1051
1067
 
1052
1068
  @value.setter
1053
1069
  def value(self, value):
@@ -21,8 +21,8 @@ def autotest(path, cmd, ignore=None, env=None):
21
21
  """
22
22
  environ = copy.copy(os.environ)
23
23
  if env:
24
- for key, value in env.items():
25
- environ[key] = value
24
+ environ.update(env)
25
+ environ['CLI2_THEME'] = 'standard'
26
26
  environ['FORCE_TERMSIZE'] = '1'
27
27
  environ['PATH'] = ':'.join([
28
28
  environ.get('HOME', '') + '/.local/bin',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cli2
3
- Version: 5.1.8
3
+ Version: 5.2.1rc1
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -63,5 +63,6 @@ Batteries included, all of which are useful on their own:
63
63
  testing library so that you can go straight to the point in pytest
64
64
  - a good old fcntl based locking
65
65
  - a command line to run any python function over a beautiful CLI
66
+ - **AI assisted programing CLI & framework with code2**
66
67
 
67
68
  `Documentation available on RTFD <https://cli2.rtfd.io>`_.
@@ -53,5 +53,6 @@ tests/test_log.py
53
53
  tests/test_mask.py
54
54
  tests/test_node.py
55
55
  tests/test_notlevenshtein.py
56
+ tests/test_prompt2.py
56
57
  tests/test_restful.py
57
58
  tests/test_table.py
@@ -44,7 +44,7 @@ from setuptools import setup
44
44
 
45
45
  setup(
46
46
  name='cli2',
47
- version='5.1.8',
47
+ version='5.2.1rc1',
48
48
  setup_requires='setupmeta',
49
49
  packages=['cli2'],
50
50
  install_requires=[
@@ -100,7 +100,7 @@ def test_vararg_after_kwarg():
100
100
 
101
101
  cmd.parse('x')
102
102
  assert cmd['one'].value == 'x'
103
- with pytest.raises(ValueError):
103
+ with pytest.raises(cli2.Cli2ValueError):
104
104
  cmd['two'].value
105
105
 
106
106
 
@@ -318,7 +318,7 @@ def test_kwarg_priority():
318
318
  """docstring"""
319
319
  cmd = cli2.Command(foo)
320
320
  cmd.parse('foo=bar')
321
- with pytest.raises(ValueError):
321
+ with pytest.raises(cli2.Cli2ValueError):
322
322
  cmd['missing'].value
323
323
 
324
324
 
@@ -21,7 +21,7 @@ with open(__file__, 'r') as f:
21
21
  # default should not be enabled
22
22
  dict(),
23
23
  [],
24
- ValueError,
24
+ cli2.Cli2ValueError,
25
25
  ),
26
26
  # test bools
27
27
  (
@@ -0,0 +1,144 @@
1
+ from cli2.test import autotest
2
+ from pathlib import Path
3
+ import pytest
4
+ import os
5
+
6
+ from unittest import mock
7
+ from prompt2 import cli, Model, Prompt
8
+
9
+
10
+ def test_paths():
11
+ assert cli.cli('paths') == [
12
+ str(Prompt.LOCAL_PATH),
13
+ str(Prompt.USER_PATH),
14
+ ]
15
+
16
+
17
+ @pytest.fixture
18
+ def user():
19
+ return Path(os.getenv('PROMPT2_USER_PATH')) / 'user.txt'
20
+
21
+
22
+ @pytest.fixture
23
+ def local():
24
+ return Path(os.getenv('PROMPT2_LOCAL_PATH')) / 'local.txt'
25
+
26
+
27
+ @pytest.fixture
28
+ def kwargs(prompt2_env, user, local):
29
+ prompt2_env['DEBUG'] = '1'
30
+ return dict(
31
+ ignore=[
32
+ str(user.parent.parent),
33
+ str(local.parent.parent),
34
+ str(Path(__file__).parent.parent),
35
+ ],
36
+ env=prompt2_env,
37
+ )
38
+
39
+
40
+ @pytest.mark.asyncio
41
+ async def test_python(prompt2_env):
42
+ model = Model.get()
43
+
44
+ prompt = Prompt()
45
+ prompt.parts.append('make a hello world in python')
46
+ result = await model(prompt)
47
+ assert 'To run this:' in result
48
+ result = await model(prompt, 'wholefile')
49
+ assert result == 'print("Hello, World!")'
50
+
51
+
52
+ def test_parsers(kwargs):
53
+ autotest(
54
+ 'tests/prompt2/test_parsers.txt',
55
+ 'prompt2 parsers',
56
+ **kwargs,
57
+ )
58
+ autotest(
59
+ 'tests/prompt2/test_parser_success.txt',
60
+ 'prompt2 parser wholefile',
61
+ **kwargs,
62
+ )
63
+ autotest(
64
+ 'tests/prompt2/test_parser_fail.txt',
65
+ 'prompt2 parser',
66
+ **kwargs,
67
+ )
68
+
69
+
70
+ def test_crud(user, kwargs):
71
+ autotest(
72
+ 'tests/prompt2/test_edit_user.txt',
73
+ 'prompt2 edit user',
74
+ **kwargs,
75
+ )
76
+ autotest(
77
+ 'tests/prompt2/test_edit_local.txt',
78
+ 'prompt2 edit local local',
79
+ **kwargs,
80
+ )
81
+ autotest(
82
+ 'tests/prompt2/test_list.txt',
83
+ 'prompt2 list',
84
+ **kwargs,
85
+ )
86
+ autotest(
87
+ 'tests/prompt2/test_show_user.txt',
88
+ 'prompt2 show user',
89
+ **kwargs,
90
+ )
91
+ autotest(
92
+ 'tests/prompt2/test_show_local.txt',
93
+ 'prompt2 show local',
94
+ **kwargs,
95
+ )
96
+ autotest(
97
+ 'tests/prompt2/test_render_local.txt',
98
+ 'prompt2 render local',
99
+ **kwargs,
100
+ )
101
+ with user.open('w') as f:
102
+ f.write('With context {{ foo }}')
103
+ autotest(
104
+ 'tests/prompt2/test_render_user_fail.txt',
105
+ 'prompt2 render user',
106
+ **kwargs,
107
+ )
108
+ autotest(
109
+ 'tests/prompt2/test_render_user_success.txt',
110
+ 'prompt2 render user foo=bar',
111
+ **kwargs,
112
+ )
113
+ autotest(
114
+ 'tests/prompt2/test_messages_user_fail.txt',
115
+ 'prompt2 messages user',
116
+ **kwargs,
117
+ )
118
+ autotest(
119
+ 'tests/prompt2/test_messages_user_success.txt',
120
+ 'prompt2 messages user foo=bar',
121
+ **kwargs,
122
+ )
123
+ autotest(
124
+ 'tests/prompt2/test_send_user_fail.txt',
125
+ 'prompt2 send user',
126
+ **kwargs,
127
+ )
128
+ autotest(
129
+ 'tests/prompt2/test_send_user_success.txt',
130
+ 'prompt2 send user foo=bar',
131
+ **kwargs,
132
+ )
133
+ with user.open('w') as f:
134
+ f.write('Write hello world in python')
135
+ autotest(
136
+ 'tests/prompt2/test_send_code_noparser.txt',
137
+ 'prompt2 send user',
138
+ **kwargs,
139
+ )
140
+ autotest(
141
+ 'tests/prompt2/test_send_code_withparser.txt',
142
+ 'prompt2 send user wholefile',
143
+ **kwargs,
144
+ )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes