gnarly 0.0.0.dev1__py3-none-any.whl → 0.0.0.dev2__py3-none-any.whl
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 gnarly might be problematic. Click here for more details.
- gnarly/__init__.py +22 -2
- gnarly/constants.py +77 -0
- gnarly/utilities/__init__.py +18 -0
- gnarly/utilities/io.py +114 -0
- gnarly-0.0.0.dev2.dist-info/METADATA +8 -0
- gnarly-0.0.0.dev2.dist-info/RECORD +8 -0
- gnarly-0.0.0.dev1.dist-info/METADATA +0 -5
- gnarly-0.0.0.dev1.dist-info/RECORD +0 -5
- {gnarly-0.0.0.dev1.dist-info → gnarly-0.0.0.dev2.dist-info}/WHEEL +0 -0
- {gnarly-0.0.0.dev1.dist-info → gnarly-0.0.0.dev2.dist-info}/entry_points.txt +0 -0
gnarly/__init__.py
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"""
|
|
2
|
+
Gnarly
|
|
3
|
+
======
|
|
4
|
+
|
|
5
|
+
A general-use abstraction layer for the lazy.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from . import constants, utilities
|
|
10
|
+
from .utilities import io, stream
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
# ─── package-level exports ───────────────────────────────────────────────
|
|
15
|
+
"utilities",
|
|
16
|
+
|
|
17
|
+
# ─── module-level exports ────────────────────────────────────────────────
|
|
18
|
+
"constants", "io",
|
|
19
|
+
|
|
20
|
+
# ─── function-level exports ──────────────────────────────────────────────
|
|
21
|
+
"stream"
|
|
22
|
+
]
|
gnarly/constants.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Constants
|
|
2
|
+
|
|
3
|
+
This module defines the constant values referenced throughout the `gnarly`
|
|
4
|
+
code base.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from dotenv import load_dotenv
|
|
12
|
+
from platformdirs import (
|
|
13
|
+
user_cache_path,
|
|
14
|
+
user_config_path,
|
|
15
|
+
user_data_path,
|
|
16
|
+
user_log_path
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# ─── logger setup ─────────────────────────────────────────────────────── ✦✦ ─
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
logger.setLevel(logging.DEBUG)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# ─── package metadata ─────────────────────────────────────────────────── ✦✦ ─
|
|
25
|
+
__author__ = "K. LeBryce <kosmolebryce@gmail.com>"
|
|
26
|
+
__package__ = "Gnarly"
|
|
27
|
+
__version__ = "0.0.0"
|
|
28
|
+
|
|
29
|
+
# ─── resource references ──────────────────────────────────────────────── ✦✦ ─
|
|
30
|
+
GNARLY_DATA_DIR: Path = user_data_path(
|
|
31
|
+
__package__,
|
|
32
|
+
__author__,
|
|
33
|
+
__version__,
|
|
34
|
+
ensure_exists=True
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
GNARLY_CACHE_DIR: Path = user_cache_path(
|
|
38
|
+
__package__,
|
|
39
|
+
__author__,
|
|
40
|
+
__version__,
|
|
41
|
+
ensure_exists=True
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
GNARLY_CONFIG_DIR: Path = user_config_path(
|
|
45
|
+
__package__,
|
|
46
|
+
__author__,
|
|
47
|
+
__version__,
|
|
48
|
+
ensure_exists=True
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
GNARLY_LOG_DIR: Path = user_log_path(
|
|
52
|
+
__package__,
|
|
53
|
+
__author__,
|
|
54
|
+
__version__,
|
|
55
|
+
ensure_exists=True
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
DOTENV_FILE_PATH: Path = GNARLY_CONFIG_DIR / "gnarly.env"
|
|
59
|
+
DOTENV_FILE_PATH.touch()
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
logger.info(
|
|
63
|
+
f"Loading environment variables from {DOTENV_FILE_PATH.resolve()}"
|
|
64
|
+
)
|
|
65
|
+
load_dotenv(DOTENV_FILE_PATH)
|
|
66
|
+
logging.info("Successfully loaded environment variables.")
|
|
67
|
+
except FileNotFoundError as e:
|
|
68
|
+
logger.error(
|
|
69
|
+
f"Could not find `gnarly.env` in {GNARLY_CONFIG_DIR.resolve()}"
|
|
70
|
+
)
|
|
71
|
+
raise RuntimeError from e
|
|
72
|
+
except IOError as e:
|
|
73
|
+
logger.error(
|
|
74
|
+
f"Encountered an unspecified I/O error while attempting to read from "
|
|
75
|
+
f"{GNARLY_CONFIG_DIR.resolve()}"
|
|
76
|
+
)
|
|
77
|
+
raise RuntimeError from e
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utilities
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
A convenient library comprising a collection of simple Python utilities.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from . import io
|
|
9
|
+
from .io import stream
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
# ─── module-level exports ────────────────────────────────────────────────
|
|
14
|
+
"io",
|
|
15
|
+
|
|
16
|
+
# ─── function-level exports ──────────────────────────────────────────────
|
|
17
|
+
"stream"
|
|
18
|
+
]
|
gnarly/utilities/io.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""
|
|
2
|
+
I/O Utilities
|
|
3
|
+
=============
|
|
4
|
+
|
|
5
|
+
This module defines and implements Gnarly's I/O interface.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
import os
|
|
9
|
+
import string
|
|
10
|
+
import sys
|
|
11
|
+
from logging import (
|
|
12
|
+
DEBUG, ERROR, FileHandler, Formatter, StreamHandler, getLogger
|
|
13
|
+
)
|
|
14
|
+
from time import sleep
|
|
15
|
+
|
|
16
|
+
from ..constants import GNARLY_LOG_DIR
|
|
17
|
+
|
|
18
|
+
# ─── set up logging ───────────────────────────────────────────────────── ✦✦ ─
|
|
19
|
+
formatter: Formatter = Formatter(
|
|
20
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
logger = getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
file_handler = FileHandler(GNARLY_LOG_DIR / "gnarly.log")
|
|
26
|
+
file_handler.setFormatter(formatter)
|
|
27
|
+
file_handler.setLevel(DEBUG)
|
|
28
|
+
|
|
29
|
+
console_handler = StreamHandler(sys.stdout)
|
|
30
|
+
console_handler.setFormatter(formatter)
|
|
31
|
+
console_handler.setLevel(ERROR)
|
|
32
|
+
|
|
33
|
+
logger.addHandler(file_handler)
|
|
34
|
+
logger.addHandler(console_handler)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ─── functions ────────────────────────────────────────────────────────── ✦✦ ─
|
|
38
|
+
def stream(
|
|
39
|
+
s: str,
|
|
40
|
+
cps: int = 700,
|
|
41
|
+
charlim: int | None = None
|
|
42
|
+
) -> Exception | None:
|
|
43
|
+
"""Print `s` to `stdout` at `cps` characters per second.
|
|
44
|
+
|
|
45
|
+
Iterate over a given string-like object, printing it character-by-
|
|
46
|
+
character and sleeping for a duration of 1/`cps` seconds. Optionally
|
|
47
|
+
limit each line to a length of `charlim`.
|
|
48
|
+
|
|
49
|
+
Arguments
|
|
50
|
+
---------
|
|
51
|
+
s: str
|
|
52
|
+
cps: int
|
|
53
|
+
charlim: int, optional
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
Nothing.
|
|
58
|
+
"""
|
|
59
|
+
charlim = charlim or min(72, os.get_terminal_size().columns - 12)
|
|
60
|
+
lines = s.splitlines()
|
|
61
|
+
wsp = string.whitespace
|
|
62
|
+
counter: int = 0
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
delay: int | float = 1 / cps
|
|
66
|
+
except ZeroDivisionError as e:
|
|
67
|
+
logger.error(
|
|
68
|
+
"User attempted to specify a value of zero characters per second, "
|
|
69
|
+
"resulting in a `ZeroDivisionError`, because function `gnarly."
|
|
70
|
+
"utilities.io.stream` calculates the system sleep duration as the "
|
|
71
|
+
"reciprocal of `cps`."
|
|
72
|
+
)
|
|
73
|
+
raise UserWarning from e
|
|
74
|
+
|
|
75
|
+
if not charlim:
|
|
76
|
+
charlim = 73
|
|
77
|
+
|
|
78
|
+
for line in lines:
|
|
79
|
+
chars = enumerate(line)
|
|
80
|
+
for i, c in chars:
|
|
81
|
+
if (i % charlim != 0) or i == 0:
|
|
82
|
+
print(c, end="", flush=True)
|
|
83
|
+
sleep(delay)
|
|
84
|
+
elif (i % charlim) == 0 and (str(c) in wsp or str(c) in ["-", "–", "─"]):
|
|
85
|
+
print(c + "\n", end="", flush=True)
|
|
86
|
+
sleep(delay)
|
|
87
|
+
elif (i % charlim == 0) and (str(c) not in wsp):
|
|
88
|
+
print(c, end="", flush=True)
|
|
89
|
+
try:
|
|
90
|
+
while True:
|
|
91
|
+
_, next_c = next(chars)
|
|
92
|
+
if str(next_c) in wsp or str(next_c) in ["-", "–", "─"]:
|
|
93
|
+
print(next_c + "\n", end="", flush=True)
|
|
94
|
+
break
|
|
95
|
+
else:
|
|
96
|
+
print(next_c, end="", flush=True)
|
|
97
|
+
except StopIteration:
|
|
98
|
+
logger.info(
|
|
99
|
+
f"Reached end of line after {counter} iterations."
|
|
100
|
+
)
|
|
101
|
+
break
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
logger.warning(
|
|
105
|
+
f"Unexpected conditions encountered:\n"
|
|
106
|
+
f"Iterating over: {str(chars)}\n"
|
|
107
|
+
f"Current index: {i} \n"
|
|
108
|
+
f"Character at current index: {c}\n"
|
|
109
|
+
f"Character limit: {charlim}\n"
|
|
110
|
+
|
|
111
|
+
f"\n{i} % {charlim} = {i % charlim}"
|
|
112
|
+
)
|
|
113
|
+
counter +=1
|
|
114
|
+
print("\n", end="", flush=True)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
gnarly/__init__.py,sha256=BY7xgd4fYiYfB9MXYxAIIXVXujCkDYIAKZrA965wM9Y,751
|
|
2
|
+
gnarly/constants.py,sha256=3tfl2wJ3SmbyL6m355YqEZPfGe-fPZONpoOhwkoIF1Q,2144
|
|
3
|
+
gnarly/utilities/__init__.py,sha256=0ElvaTN3irWmzCipE4yJtwFE0EkRGKInff_LUZ8vnl8,543
|
|
4
|
+
gnarly/utilities/io.py,sha256=ACUqdsafnZdS9wwm35nUDZfxKOYn8JQDz-GW6sSxUTo,3725
|
|
5
|
+
gnarly-0.0.0.dev2.dist-info/METADATA,sha256=qMoh-dtBXReq5h6IGHw_kozlWHYGpxNGr7O7hbhArzA,224
|
|
6
|
+
gnarly-0.0.0.dev2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
gnarly-0.0.0.dev2.dist-info/entry_points.txt,sha256=u6QA852MMLgzBBI9pNUz8GUPNSAydvD3m8IXWzFTe50,39
|
|
8
|
+
gnarly-0.0.0.dev2.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
gnarly/__init__.py,sha256=I64ailtt82IXdyEU7FLY4JgH6G26dZJ5onvoBhEmw6I,52
|
|
2
|
-
gnarly-0.0.0.dev1.dist-info/METADATA,sha256=8MkyBTKkuihYVSQwLqt-JE_E5KRJFYNEXDCRUIFL1AU,107
|
|
3
|
-
gnarly-0.0.0.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
-
gnarly-0.0.0.dev1.dist-info/entry_points.txt,sha256=u6QA852MMLgzBBI9pNUz8GUPNSAydvD3m8IXWzFTe50,39
|
|
5
|
-
gnarly-0.0.0.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|