wizlib 0.9.3__tar.gz → 0.9.4__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.

Potentially problematic release.


This version of wizlib might be problematic. Click here for more details.

@@ -1,14 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 0.9.3
4
- Summary: A collection of Python modules that are useful across multiple projects
5
- Author-email: Francis Potter <wizlib@steampunkwizard.ca>
3
+ Version: 0.9.4
4
+ Summary: A collection of Python modules that might be useful across multiple projects
6
5
  License: MIT
7
- Requires-Python: >=3.8
6
+ Author: Steampunk Wizard
7
+ Author-email: wizlib@steampunkwizard.ca
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
13
+ Requires-Dist: gnureadline (>=8.1.2,<9.0.0) ; sys_platform == "darwin"
14
+ Requires-Dist: pyreadline3 (>=3.4.1,<4.0.0) ; sys_platform == "win32"
8
15
  Description-Content-Type: text/markdown
9
- Requires-Dist: gnureadline; platform_system == "Darwin"
10
- Requires-Dist: pyreadline3; platform_system == "Windows"
11
- Requires-Dist: PyYAML>=6.0.1
12
16
 
13
17
  # WizLib
14
18
 
@@ -133,3 +137,4 @@ Emacs keys are enabled by default; I'm able to use the arrow keys on my Mac so y
133
137
  Logo by [Freepik](https://www.freepik.com/?_gl=1*1y9rvc9*test_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*test_ga_523JXC6VL7*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..*fp_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*fp_ga_1ZY8468CQB*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..)
134
138
 
135
139
 
140
+
@@ -0,0 +1,28 @@
1
+ [tool.poetry]
2
+ name = "wizlib"
3
+ version = "0.9.4"
4
+ description = "A collection of Python modules that might be useful across multiple projects"
5
+ authors = ["Steampunk Wizard <wizlib@steampunkwizard.ca>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.11"
11
+ PyYAML = "^6.0.1"
12
+ pyreadline3 = { version="^3.4.1", markers="sys_platform=='win32'" }
13
+ gnureadline = { version="^8.1.2", markers="sys_platform=='darwin'" }
14
+
15
+ [tool.poetry.group.dev.dependencies]
16
+ coverage = "^7.3.1"
17
+ pycodestyle = "^2.11.0"
18
+ autopep8 = "^2.0.4"
19
+
20
+ [build-system]
21
+ requires = ["poetry-core"]
22
+ build-backend = "poetry.core.masonry.api"
23
+
24
+ [tool.poetry-dynamic-versioning]
25
+ enable = false
26
+ vcs = "git"
27
+ format = "{base}"
28
+
wizlib-0.9.3/.version DELETED
@@ -1 +0,0 @@
1
- 0.9.3
@@ -1,25 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "wizlib"
7
- authors = [
8
- {name = "Francis Potter", email = "wizlib@steampunkwizard.ca"}
9
- ]
10
- description = "A collection of Python modules that are useful across multiple projects"
11
- readme = "README.md"
12
- requires-python = ">=3.8"
13
- license = {text = "MIT"}
14
- dependencies = [
15
- "gnureadline; platform_system=='Darwin'",
16
- "pyreadline3; platform_system=='Windows'",
17
- "PyYAML>=6.0.1"
18
- ]
19
- dynamic = ["version"]
20
-
21
- [tool.setuptools.package-dir]
22
- wizlib = "wizlib"
23
-
24
- [tool.setuptools.dynamic]
25
- version = {file = [".version"]}
wizlib-0.9.3/setup.cfg DELETED
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
@@ -1,9 +0,0 @@
1
- from test.data_class_family.atriarch import Atriarch
2
- from unittest import TestCase
3
-
4
-
5
- class TestClassFamily(TestCase):
6
-
7
- def test_family_children(self):
8
- cx = Atriarch.family_children()
9
- self.assertEqual(len(cx), 1)
@@ -1,57 +0,0 @@
1
- from unittest import TestCase
2
- from unittest.mock import patch
3
- from io import StringIO
4
- import os
5
-
6
- from wizlib.command_handler import CommandHandler
7
- from .data_command import TestCommand
8
-
9
-
10
- class TestCommandSync(TestCase):
11
-
12
- def test_from_handler(self):
13
- r, s = CommandHandler(TestCommand).handle(['play'])
14
- self.assertEqual(r, 'Play!')
15
-
16
- def test_default(self):
17
- r, s = CommandHandler(TestCommand).handle()
18
- self.assertEqual(r, 'Play!')
19
-
20
- @patch('sys.stdout', StringIO())
21
- def test_wrong_command(self):
22
- h = CommandHandler(TestCommand)
23
- c = h.get_command(['eat'])
24
- self.assertIsNone(c)
25
-
26
- @patch('sys.stdout', StringIO())
27
- def test_handle_wrong_command(self):
28
- h = CommandHandler(TestCommand)
29
- r, s = h.handle(['eat'])
30
- self.assertIsNone(r)
31
-
32
- def test_command_arg(self):
33
- h = CommandHandler(TestCommand)
34
- c = h.get_command(['play', '--dd', 't'])
35
- self.assertEqual(c.dd, 't')
36
-
37
- def test_atriarch_args(self):
38
- h = CommandHandler(TestCommand)
39
- c = h.get_command(['--xx', 'y', 'play'])
40
- self.assertEqual(c.xx, 'y')
41
-
42
- def test_error(self):
43
- with patch('sys.stdout', o := StringIO()):
44
- with patch('sys.argv', ['', 'error']):
45
- CommandHandler.shell(TestCommand)
46
- o.seek(0)
47
- r = o.read()
48
- self.assertIn('division by zero', r)
49
- self.assertEqual(len(r.splitlines()), 3)
50
-
51
- @patch('sys.stdout', StringIO())
52
- def test_error_debug(self):
53
- os.environ['DEBUG'] = '1'
54
- with self.assertRaises(ZeroDivisionError):
55
- with patch('sys.argv', ['', 'error']):
56
- CommandHandler.shell(TestCommand)
57
- del os.environ['DEBUG']
@@ -1,90 +0,0 @@
1
- from unittest import TestCase
2
- from argparse import ArgumentParser
3
- import os
4
- from unittest.mock import patch
5
- from pathlib import Path
6
-
7
- from wizlib.config_machine import ConfigMachine
8
- from .data_config_machine.sample import SampleMachine
9
- from .data_config_machine.sample import SampleCommandMachine
10
- from .data_config_machine.sample import SampleOtherMachine
11
-
12
-
13
- class TestConfig(TestCase):
14
-
15
- def test_direct_arg(self):
16
- test_machine = SampleMachine(foo='bar')
17
- f = test_machine.config_get('foo')
18
- self.assertEqual(f, 'bar')
19
-
20
- def test_config_file_arg(self):
21
- sample = SampleMachine(
22
- config='test/data_config_machine/test-config.yml')
23
- f = sample.config_get('foo')
24
- self.assertEqual(f, 'erg')
25
-
26
- def test_nested_entry(self):
27
- sample = SampleMachine(
28
- config='test/data_config_machine/test-config.yml')
29
- f = sample.config_get('bar-zing')
30
- self.assertEqual(f, 'ech')
31
-
32
- def test_nested_entry_fail(self):
33
- sample = SampleMachine(
34
- config='test/data_config_machine/test-config.yml')
35
- f = sample.config_get('bar-za')
36
- self.assertIsNone(f)
37
-
38
- def test_specific_env_var(self):
39
- os.environ['DEF_G'] = 'ju'
40
- test_machine = SampleMachine()
41
- f = test_machine.config_get('def-g')
42
- del os.environ['DEF_G']
43
- self.assertEqual(f, 'ju')
44
-
45
- def test_conf_file_env_var(self):
46
- os.environ['MYAPP_CONFIG'] = 'test/data_config_machine/test-config.yml'
47
- test_machine = SampleMachine()
48
- f = test_machine.config_get('bar-zing')
49
- del os.environ['MYAPP_CONFIG']
50
- self.assertEqual(f, 'ech')
51
-
52
- def test_conf_file_env_var_specific_name(self):
53
- os.environ['MYAPP2_CONFIG'] = \
54
- 'test/data_config_machine/test-config.yml'
55
- test_machine = SampleMachine(appname='myapp2')
56
- f = test_machine.config_get('bar-zing')
57
- del os.environ['MYAPP2_CONFIG']
58
- self.assertEqual(f, 'ech')
59
-
60
- def test_local_config_file(self):
61
- with patch('pathlib.Path.cwd',
62
- lambda: Path('test/data_config_machine')):
63
- test_machine = SampleMachine()
64
- f = test_machine.config_get('bar-zing')
65
- self.assertEqual(f, 'ech')
66
-
67
- def test_home_config_file(self):
68
- with patch('pathlib.Path.home',
69
- lambda: Path('test/data_config_machine')):
70
- test_machine = SampleMachine()
71
- f = test_machine.config_get('bar-zing')
72
- self.assertEqual(f, 'ech')
73
-
74
- def test_works_with_command(self):
75
- sample = SampleCommandMachine(
76
- config='test/data_config_machine/test-config.yml')
77
- f = sample.config_get('foo')
78
- self.assertEqual(f, 'erg')
79
-
80
- def works_another_way(self):
81
- with patch('pathlib.Path.cwd',
82
- lambda: Path('test/data_config_machine')):
83
- test_machine = SampleOtherMachine()
84
- f = test_machine.config_get('bar-zing')
85
- self.assertEqual(f, 'waa')
86
-
87
- def test_nested_as_attribute(self):
88
- c = SampleMachine()
89
- c.a_b = 'c'
90
- self.assertEqual(c.config_get('a-b'), 'c')
@@ -1,51 +0,0 @@
1
- from unittest import TestCase
2
- from unittest.mock import patch
3
- from io import StringIO
4
-
5
- from wizlib.super_wrapper import SuperWrapper
6
-
7
- correct = """
8
- Parent execute before
9
- IB execute before
10
- Hello Jane
11
- IB execute after
12
- Parent execute after
13
- """
14
-
15
-
16
- class TestSuperWrapper(TestCase):
17
-
18
- def test_super_wrapper(self):
19
-
20
- class Parent(SuperWrapper):
21
- def execute(self, method, *args, **kwargs):
22
- print(f"Parent execute before")
23
- method(self, *args, **kwargs)
24
- print(f"Parent execute after")
25
-
26
- class InBetween(Parent):
27
- @Parent.wrap
28
- def execute(self, method, *args, **kwargs):
29
- print(f"IB execute before")
30
- method(self, *args, **kwargs)
31
- print(f"IB execute after")
32
-
33
- class NewChild(InBetween):
34
- @InBetween.wrap
35
- def execute(self, name):
36
- print(f"Hello {name}")
37
-
38
- with patch('sys.stdout', o := StringIO()):
39
- c = NewChild()
40
- c.execute("Jane")
41
- o.seek(0)
42
- r = o.read()
43
- correct = """
44
- Parent execute before
45
- IB execute before
46
- Hello Jane
47
- IB execute after
48
- Parent execute after
49
- """.lstrip().split('\n')
50
- correct_clean = '\n'.join([i.lstrip() for i in correct])
51
- self.assertEqual(r, correct_clean)
@@ -1,135 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: wizlib
3
- Version: 0.9.3
4
- Summary: A collection of Python modules that are useful across multiple projects
5
- Author-email: Francis Potter <wizlib@steampunkwizard.ca>
6
- License: MIT
7
- Requires-Python: >=3.8
8
- Description-Content-Type: text/markdown
9
- Requires-Dist: gnureadline; platform_system == "Darwin"
10
- Requires-Dist: pyreadline3; platform_system == "Windows"
11
- Requires-Dist: PyYAML>=6.0.1
12
-
13
- # WizLib
14
-
15
- A collection of Python modules that might be useful across multiple projects
16
-
17
- ## ClassFamily
18
-
19
- A class family is a set of class definitions that use single inheritance
20
- (each subclass inherits from only one parent) and often multiple inheritance
21
- (subclasses can inherit from subclasses). So it's a hierarchy of classes,
22
- with one super-parent (termed the "atriarch") at the top.
23
-
24
- We offer a way for members of the family to declare themselves simply by
25
- living in the right package location. Then those classes can be instantiated
26
- using keys or names, without having to be specifically called. The members
27
- act independently of each other.
28
-
29
- What we get, after importing everything and loading it all, is essentially a
30
- little database of classes, where class-level properties become keys for
31
- looking up member classes. So, for example, we can have a family of commands,
32
- and use a command string to look up the right command.
33
-
34
- Ultimately, the atriarch of the family -- the class at the top of the
35
- hierarchy -- holds the database, actually a list, in the property called
36
- "family". So that class can be queried to find appropriate family member
37
- classes or instances thereof.
38
-
39
- This utility provides functions for importing family members, loading the
40
- "families" property of the super-parent, and querying the family.
41
-
42
- In the process of loading and querying the class family, we need to *avoid*
43
- inheritance of attributes. There might be abstract intermediary classes that
44
- don't want to play. So we use `__dict__` to ensure we're only seeing the
45
- atttributes that are defined on that specific class.
46
-
47
- ## SuperWrapper
48
-
49
- Provide a decorator to wrap a method so that it's called within the inherited
50
- version of that method.
51
-
52
- Example of use:
53
-
54
- ```python
55
- class Parent(SuperWrapper):
56
- def execute(self, method, *args, **kwargs):
57
- print(f"Parent execute before")
58
- method(self, *args, **kwargs)
59
- print(f"Parent execute after")
60
-
61
- class InBetween(Parent):
62
- @Parent.wrap
63
- def execute(self, method, *args, **kwargs):
64
- print(f"IB execute before")
65
- method(self, *args, **kwargs)
66
- print(f"IB execute after")
67
-
68
- class NewChild(InBetween):
69
- @InBetween.wrap
70
- def execute(self, name):
71
- print(f"Hello {name}")
72
-
73
- c = NewChild()
74
- c.execute("Jane")
75
- ```
76
-
77
- Note that for a method to be "wrappable" it must take the form shown above, and explicitly call the method that's handed into it. So strictly, this is different from regular inheritance, where the parent class method has the same signature as the child class method.
78
-
79
-
80
- ## CommandHandler
81
-
82
- ## ConfigMachine
83
-
84
- Enables easy configuration across multiple levels. Tries each of the following approaches in order until one finds the required config option
85
-
86
- - First look for specific options (ie. `--gitlab-host`) on the command line, typically hyphenated
87
- - Then look for a specific env variable for that config setting in all caps, e.g. `GITLAB_HOST`
88
- - If those both fail, then look for a YAML configuration file:
89
- - First identified with a `--config` / `-c` option on the command line
90
- - Then with a path in the `APPNAME_CONFIG` environment variable - note all caps
91
- - Then look in the local working directory for `.appname.yml`
92
- - Then look for `~/.appname.yml` in the user's home directory
93
-
94
- Config files are in YAML, and look something like this:
95
-
96
- ```yaml
97
- gitlab:
98
- host: gitlab.com
99
- local:
100
- root: $HOME/git
101
- ```
102
-
103
- Note that nested labels in the config map to hyphenated command line options.
104
-
105
- To use the library:
106
-
107
- ```python
108
- config = ConfigMachine('appname', args)
109
- host = config.get('gitlab-host')
110
- ```
111
-
112
- This assumes that `args` represents the result of `ArgumentParser` - in otherwords, a `Namespace` object.
113
-
114
- ## RLInput
115
-
116
- Python supports the GNU readline approach, which enables tab completion, key mappings, and history with the `input()` function. But the documentation is cryptic, and the implementation differs between Linux and MacOS. RLInput makes it easy.
117
-
118
- ```python
119
- from wizlib.rlinput import rlinput
120
- ```
121
-
122
- It's just a function, with up to three parameters:
123
-
124
- - `intro:str=""` - The intro or prompt, same as in the `input()` function.
125
- - `default:str=""` - If provided, the text will be inserted into the buffer at the start, with the cursor at the end of the buffer. So that becomes the default, that must be overridden by the user if they want different input.
126
- - `options:list=[]` - A list of options for tab completion. This assumes the options are choices for the entire entry; it's not context-dependent within the buffer.
127
-
128
- Emacs keys are enabled by default; I'm able to use the arrow keys on my Mac so you should too. I made one change to the keyboard mappings, which is the Ctrl-A, instead of just moving the cursor to the beginning of the line, wipes the entire buffer. So to wipe out the default value and type or tab something new, just hit Ctrl-A.
129
-
130
-
131
- ---
132
-
133
- Logo by [Freepik](https://www.freepik.com/?_gl=1*1y9rvc9*test_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*test_ga_523JXC6VL7*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..*fp_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*fp_ga_1ZY8468CQB*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..)
134
-
135
-
@@ -1,18 +0,0 @@
1
- .version
2
- README.md
3
- pyproject.toml
4
- test/test_class_family.py
5
- test/test_command_handler.py
6
- test/test_config_machine.py
7
- test/test_super_wrapper.py
8
- wizlib/__init__.py
9
- wizlib/class_family.py
10
- wizlib/command_handler.py
11
- wizlib/config_machine.py
12
- wizlib/rlinput.py
13
- wizlib/super_wrapper.py
14
- wizlib.egg-info/PKG-INFO
15
- wizlib.egg-info/SOURCES.txt
16
- wizlib.egg-info/dependency_links.txt
17
- wizlib.egg-info/requires.txt
18
- wizlib.egg-info/top_level.txt
@@ -1,7 +0,0 @@
1
- PyYAML>=6.0.1
2
-
3
- [:platform_system == "Darwin"]
4
- gnureadline
5
-
6
- [:platform_system == "Windows"]
7
- pyreadline3
@@ -1 +0,0 @@
1
- wizlib
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes