mmeutils 0.0.3__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.
- mmeutils-0.0.3/LICENSE.txt +0 -0
- mmeutils-0.0.3/MANIFEST.in +1 -0
- mmeutils-0.0.3/PKG-INFO +35 -0
- mmeutils-0.0.3/README.md +15 -0
- mmeutils-0.0.3/pyproject.toml +3 -0
- mmeutils-0.0.3/setup.cfg +41 -0
- mmeutils-0.0.3/src/mmeutils/__init__.py +11 -0
- mmeutils-0.0.3/src/mmeutils/fileio/__init__.py +76 -0
- mmeutils-0.0.3/src/mmeutils/textio/__init__.py +30 -0
- mmeutils-0.0.3/src/mmeutils.egg-info/PKG-INFO +35 -0
- mmeutils-0.0.3/src/mmeutils.egg-info/SOURCES.txt +12 -0
- mmeutils-0.0.3/src/mmeutils.egg-info/dependency_links.txt +1 -0
- mmeutils-0.0.3/src/mmeutils.egg-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exclude-recursively = __pycache__ .mypy_cache .pytest_cache *.py[cod]
|
mmeutils-0.0.3/PKG-INFO
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mmeutils
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Some simple personal utility functions.
|
|
5
|
+
Home-page: https://github.com/prof79/py-mmeutils
|
|
6
|
+
Author: Markus M. Egger
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Topic :: Text Processing :: General
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
|
|
21
|
+
# mmeutils
|
|
22
|
+
|
|
23
|
+
A simple collection of personal Python utility functions required in multiple hobbyist projects.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
$ py -m pip install mmeutils
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Version History
|
|
32
|
+
|
|
33
|
+
### 0.0.1-0.0.3
|
|
34
|
+
|
|
35
|
+
Alpha in-progress
|
mmeutils-0.0.3/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# mmeutils
|
|
2
|
+
|
|
3
|
+
A simple collection of personal Python utility functions required in multiple hobbyist projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
$ py -m pip install mmeutils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Version History
|
|
12
|
+
|
|
13
|
+
### 0.0.1-0.0.3
|
|
14
|
+
|
|
15
|
+
Alpha in-progress
|
mmeutils-0.0.3/setup.cfg
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = mmeutils
|
|
3
|
+
version = 0.0.3
|
|
4
|
+
author = Markus M. Egger
|
|
5
|
+
url = https://github.com/prof79/py-mmeutils
|
|
6
|
+
description = Some simple personal utility functions.
|
|
7
|
+
long_description = file: README.md
|
|
8
|
+
long_description_content_type = text/markdown
|
|
9
|
+
license = MIT
|
|
10
|
+
license_files = LICENSE.txt
|
|
11
|
+
classifiers =
|
|
12
|
+
License :: OSI Approved :: MIT License
|
|
13
|
+
Development Status :: 3 - Alpha
|
|
14
|
+
Intended Audience :: Developers
|
|
15
|
+
Operating System :: OS Independent
|
|
16
|
+
Programming Language :: Python :: 3
|
|
17
|
+
Programming Language :: Python :: 3.9
|
|
18
|
+
Topic :: Text Processing :: General
|
|
19
|
+
Topic :: Utilities
|
|
20
|
+
Typing :: Typed
|
|
21
|
+
|
|
22
|
+
[options]
|
|
23
|
+
package_dir =
|
|
24
|
+
=src
|
|
25
|
+
packages = find:
|
|
26
|
+
include_package_data = True
|
|
27
|
+
python_requires = >=3.9
|
|
28
|
+
|
|
29
|
+
[options.packages.find]
|
|
30
|
+
where = src
|
|
31
|
+
exclude =
|
|
32
|
+
test*
|
|
33
|
+
temp*
|
|
34
|
+
|
|
35
|
+
[tool: pytest]
|
|
36
|
+
testpaths = src/test/
|
|
37
|
+
|
|
38
|
+
[egg_info]
|
|
39
|
+
tag_build =
|
|
40
|
+
tag_date = 0
|
|
41
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""File Input/Output Utility Functions"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__all__: List[str] = [
|
|
8
|
+
'read_text_file_to_string',
|
|
9
|
+
'validate_json_file',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
from logging import debug
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def read_text_file_to_string(file_name: Optional[str|Path]) -> str:
|
|
20
|
+
"""Read contents of a text file into a single string.
|
|
21
|
+
|
|
22
|
+
Lines will be normalized ie. stripped and empty lines discarded.
|
|
23
|
+
Lines will then be joined using the line-separation character (\\n).
|
|
24
|
+
|
|
25
|
+
:param file_name: Name/path of the file to process.
|
|
26
|
+
:type file_name: Optional[str|Path]
|
|
27
|
+
|
|
28
|
+
:return: A string of all the non-empty lines joined by \\n.
|
|
29
|
+
:rtype: str
|
|
30
|
+
"""
|
|
31
|
+
with open(str(file_name), 'r', encoding='utf-8') as file:
|
|
32
|
+
from ..textio import strip_discard_empty_lines
|
|
33
|
+
|
|
34
|
+
lines = strip_discard_empty_lines(file.readlines())
|
|
35
|
+
return '\n'.join(lines)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def validate_json_file(file_name: Optional[str|Path]) -> bool:
|
|
39
|
+
"""Validate that a JSON file is neither empty nor invalid.
|
|
40
|
+
|
|
41
|
+
Empty means all whitespace, an empty object or an empty array.
|
|
42
|
+
Invalid means it cannot be parsed as valid JSON.
|
|
43
|
+
And the file must exist in the first place.
|
|
44
|
+
|
|
45
|
+
:param file_name: Name/path of the JSON file to check.
|
|
46
|
+
:type file_name: Optional[str|Path]
|
|
47
|
+
|
|
48
|
+
:return: True if file exists and has valid non-empty JSON content.
|
|
49
|
+
False otherwise.
|
|
50
|
+
:rtype: bool
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
if not Path(str(file_name)).exists():
|
|
54
|
+
debug(f'validate_json_file(): File {str(file_name)} not found')
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
contents = read_text_file_to_string(file_name)
|
|
58
|
+
|
|
59
|
+
if contents == '':
|
|
60
|
+
debug(f'validate_json_file(): {str(file_name)} is empty')
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
obj = json.loads(contents)
|
|
65
|
+
|
|
66
|
+
if len(obj) == 0:
|
|
67
|
+
debug(f'validate_json_file(): {str(file_name)} has empty object/array')
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
else:
|
|
71
|
+
debug(f'validate_json_file(): {str(file_name)} is valid')
|
|
72
|
+
return True
|
|
73
|
+
|
|
74
|
+
except json.JSONDecodeError as jde:
|
|
75
|
+
debug(f'validate_json_file(): {str(file_name)} is invalid: {jde}')
|
|
76
|
+
return False
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Text Input/Output Utility Functions"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from typing import Iterable, List
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__all__: List[str] = [
|
|
8
|
+
'strip_discard_empty_lines',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def strip_discard_empty_lines(lines: Iterable[str]) -> list[str]:
|
|
13
|
+
"""Sanitizes string lines in an iterable such that:
|
|
14
|
+
|
|
15
|
+
* Leading and trailing whitespace is discarded ("strip()")
|
|
16
|
+
* Empty lines (including whitespace-only) are discarded
|
|
17
|
+
|
|
18
|
+
:param lines: An iterable of string lines to process
|
|
19
|
+
:type lines: Iterable[st]
|
|
20
|
+
|
|
21
|
+
:return: The list of normalized (non-empty) strings.
|
|
22
|
+
:rtype: list[str]
|
|
23
|
+
"""
|
|
24
|
+
return list(
|
|
25
|
+
[
|
|
26
|
+
line.strip()
|
|
27
|
+
for line in lines
|
|
28
|
+
if line.strip()
|
|
29
|
+
]
|
|
30
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mmeutils
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Some simple personal utility functions.
|
|
5
|
+
Home-page: https://github.com/prof79/py-mmeutils
|
|
6
|
+
Author: Markus M. Egger
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Topic :: Text Processing :: General
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
|
|
21
|
+
# mmeutils
|
|
22
|
+
|
|
23
|
+
A simple collection of personal Python utility functions required in multiple hobbyist projects.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
$ py -m pip install mmeutils
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Version History
|
|
32
|
+
|
|
33
|
+
### 0.0.1-0.0.3
|
|
34
|
+
|
|
35
|
+
Alpha in-progress
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.cfg
|
|
6
|
+
src/mmeutils/__init__.py
|
|
7
|
+
src/mmeutils.egg-info/PKG-INFO
|
|
8
|
+
src/mmeutils.egg-info/SOURCES.txt
|
|
9
|
+
src/mmeutils.egg-info/dependency_links.txt
|
|
10
|
+
src/mmeutils.egg-info/top_level.txt
|
|
11
|
+
src/mmeutils/fileio/__init__.py
|
|
12
|
+
src/mmeutils/textio/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mmeutils
|