wizlib 0.9.2__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,10 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 0.9.2
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
16
 
10
17
  # WizLib
@@ -130,3 +137,4 @@ Emacs keys are enabled by default; I'm able to use the arrow keys on my Mac so y
130
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..)
131
138
 
132
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
+
@@ -2,6 +2,7 @@ from argparse import Namespace
2
2
  from pathlib import Path
3
3
  import os
4
4
  from dataclasses import dataclass
5
+ from unittest.mock import patch
5
6
 
6
7
  from yaml import load
7
8
  from yaml import Loader
@@ -67,3 +68,16 @@ class ConfigMachine:
67
68
  """Allows a Command class to also inherit from ConfigMachine. List
68
69
  ConfigMachine first."""
69
70
  parser.add_argument('--config', action='store')
71
+
72
+
73
+ def nohome_test(): # pragma: nocover
74
+ """Fake out a ConfigMachine so that it thinks test/files is the home
75
+ directory. This way it's not tempted to pull real configuration."""
76
+ return patch('pathlib.Path.home', lambda: Path('test/files'))
77
+
78
+
79
+ def patchconfig_test(**kwargs): # pragma: nocover
80
+ """Hand testable config data to a test method. First pass: always return
81
+ None."""
82
+ methodpath = 'wizlib.config_machine.ConfigMachine.config_get'
83
+ return patch(methodpath, lambda s, t: True)
wizlib-0.9.2/.version DELETED
@@ -1 +0,0 @@
1
- 0.9.2
@@ -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.2/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,132 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: wizlib
3
- Version: 0.9.2
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
-
10
- # WizLib
11
-
12
- A collection of Python modules that might be useful across multiple projects
13
-
14
- ## ClassFamily
15
-
16
- A class family is a set of class definitions that use single inheritance
17
- (each subclass inherits from only one parent) and often multiple inheritance
18
- (subclasses can inherit from subclasses). So it's a hierarchy of classes,
19
- with one super-parent (termed the "atriarch") at the top.
20
-
21
- We offer a way for members of the family to declare themselves simply by
22
- living in the right package location. Then those classes can be instantiated
23
- using keys or names, without having to be specifically called. The members
24
- act independently of each other.
25
-
26
- What we get, after importing everything and loading it all, is essentially a
27
- little database of classes, where class-level properties become keys for
28
- looking up member classes. So, for example, we can have a family of commands,
29
- and use a command string to look up the right command.
30
-
31
- Ultimately, the atriarch of the family -- the class at the top of the
32
- hierarchy -- holds the database, actually a list, in the property called
33
- "family". So that class can be queried to find appropriate family member
34
- classes or instances thereof.
35
-
36
- This utility provides functions for importing family members, loading the
37
- "families" property of the super-parent, and querying the family.
38
-
39
- In the process of loading and querying the class family, we need to *avoid*
40
- inheritance of attributes. There might be abstract intermediary classes that
41
- don't want to play. So we use `__dict__` to ensure we're only seeing the
42
- atttributes that are defined on that specific class.
43
-
44
- ## SuperWrapper
45
-
46
- Provide a decorator to wrap a method so that it's called within the inherited
47
- version of that method.
48
-
49
- Example of use:
50
-
51
- ```python
52
- class Parent(SuperWrapper):
53
- def execute(self, method, *args, **kwargs):
54
- print(f"Parent execute before")
55
- method(self, *args, **kwargs)
56
- print(f"Parent execute after")
57
-
58
- class InBetween(Parent):
59
- @Parent.wrap
60
- def execute(self, method, *args, **kwargs):
61
- print(f"IB execute before")
62
- method(self, *args, **kwargs)
63
- print(f"IB execute after")
64
-
65
- class NewChild(InBetween):
66
- @InBetween.wrap
67
- def execute(self, name):
68
- print(f"Hello {name}")
69
-
70
- c = NewChild()
71
- c.execute("Jane")
72
- ```
73
-
74
- 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.
75
-
76
-
77
- ## CommandHandler
78
-
79
- ## ConfigMachine
80
-
81
- Enables easy configuration across multiple levels. Tries each of the following approaches in order until one finds the required config option
82
-
83
- - First look for specific options (ie. `--gitlab-host`) on the command line, typically hyphenated
84
- - Then look for a specific env variable for that config setting in all caps, e.g. `GITLAB_HOST`
85
- - If those both fail, then look for a YAML configuration file:
86
- - First identified with a `--config` / `-c` option on the command line
87
- - Then with a path in the `APPNAME_CONFIG` environment variable - note all caps
88
- - Then look in the local working directory for `.appname.yml`
89
- - Then look for `~/.appname.yml` in the user's home directory
90
-
91
- Config files are in YAML, and look something like this:
92
-
93
- ```yaml
94
- gitlab:
95
- host: gitlab.com
96
- local:
97
- root: $HOME/git
98
- ```
99
-
100
- Note that nested labels in the config map to hyphenated command line options.
101
-
102
- To use the library:
103
-
104
- ```python
105
- config = ConfigMachine('appname', args)
106
- host = config.get('gitlab-host')
107
- ```
108
-
109
- This assumes that `args` represents the result of `ArgumentParser` - in otherwords, a `Namespace` object.
110
-
111
- ## RLInput
112
-
113
- 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.
114
-
115
- ```python
116
- from wizlib.rlinput import rlinput
117
- ```
118
-
119
- It's just a function, with up to three parameters:
120
-
121
- - `intro:str=""` - The intro or prompt, same as in the `input()` function.
122
- - `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.
123
- - `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.
124
-
125
- 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.
126
-
127
-
128
- ---
129
-
130
- Logo by [Freepik](https://www.freepik.com/?_gl=1*1y9rvc9*test_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*test_ga_523JXC6VL7*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..*fp_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*fp_ga_1ZY8468CQB*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..)
131
-
132
-
@@ -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