gnarly 0.0.0.dev3__py3-none-any.whl → 0.0.0.dev6__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 +27 -5
- gnarly/constants.py +8 -3
- gnarly/errors.py +29 -0
- gnarly/types.py +103 -0
- gnarly/utils/__init__.py +44 -0
- gnarly/utils/code/__init__.py +33 -0
- gnarly/utils/code/projects.py +205 -0
- gnarly/utils/io.py +176 -0
- gnarly/utils/llm/__init__.py +22 -0
- gnarly/utils/llm/chatgpt.py +93 -0
- gnarly/utils/llm/claude.py +98 -0
- gnarly/utils/llm/interfaces.py +293 -0
- gnarly/utils/llm/models.py +202 -0
- {gnarly-0.0.0.dev3.dist-info → gnarly-0.0.0.dev6.dist-info}/METADATA +1 -2
- gnarly-0.0.0.dev6.dist-info/RECORD +17 -0
- gnarly/utilities/__init__.py +0 -18
- gnarly/utilities/io.py +0 -114
- gnarly-0.0.0.dev3.dist-info/RECORD +0 -8
- {gnarly-0.0.0.dev3.dist-info → gnarly-0.0.0.dev6.dist-info}/WHEEL +0 -0
- {gnarly-0.0.0.dev3.dist-info → gnarly-0.0.0.dev6.dist-info}/entry_points.txt +0 -0
gnarly/__init__.py
CHANGED
|
@@ -7,8 +7,23 @@ A general-use abstraction layer for the lazy.
|
|
|
7
7
|
"""
|
|
8
8
|
import logging
|
|
9
9
|
|
|
10
|
-
from . import constants,
|
|
11
|
-
from .
|
|
10
|
+
from . import errors, constants, utils
|
|
11
|
+
from .errors import NamespaceError
|
|
12
|
+
from .utils import code, io, llm
|
|
13
|
+
from .utils.code.projects import (
|
|
14
|
+
GnarlyProject,
|
|
15
|
+
GnarlyCppProject,
|
|
16
|
+
GnarlyHaskellProject,
|
|
17
|
+
GnarlyJavaScriptProject,
|
|
18
|
+
GnarlyPythonProject,
|
|
19
|
+
GnarlyRProject,
|
|
20
|
+
GnarlyRustProject,
|
|
21
|
+
GnarlySwiftProject,
|
|
22
|
+
GnarlyProjectType,
|
|
23
|
+
Project
|
|
24
|
+
)
|
|
25
|
+
from .utils.io import stream
|
|
26
|
+
from .utils.llm import claude, chatgpt, ChatGPT, Claude
|
|
12
27
|
|
|
13
28
|
logging.basicConfig(level=logging.DEBUG)
|
|
14
29
|
logger = logging.getLogger(__name__)
|
|
@@ -21,11 +36,18 @@ except ImportError as e:
|
|
|
21
36
|
|
|
22
37
|
__all__ = [
|
|
23
38
|
# ─── package-level exports ───────────────────────────────────────────────
|
|
24
|
-
"
|
|
39
|
+
"code", "llm", "utils",
|
|
25
40
|
|
|
26
41
|
# ─── module-level exports ────────────────────────────────────────────────
|
|
27
|
-
"constants", "io",
|
|
42
|
+
"chatgpt", "claude", "errors", "constants", "io",
|
|
28
43
|
|
|
29
44
|
# ─── function-level exports ──────────────────────────────────────────────
|
|
30
|
-
"stream"
|
|
45
|
+
"stream",
|
|
46
|
+
|
|
47
|
+
# ─── class-level exports ─────────────────────────────────────────────────
|
|
48
|
+
"ChatGPT", "Claude",
|
|
49
|
+
"GnarlyProject", "GnarlyCppProject", "GnarlyHaskellProject",
|
|
50
|
+
"GnarlyJavaScriptProject", "GnarlyPythonProject", "GnarlyRustProject",
|
|
51
|
+
"GnarlyRProject", "GnarlyRustProject", "GnarlySwiftProject",
|
|
52
|
+
"GnarlyProjectType", "NamespaceError", "Project"
|
|
31
53
|
]
|
gnarly/constants.py
CHANGED
|
@@ -22,9 +22,10 @@ logger.setLevel(logging.DEBUG)
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
# ─── package metadata ─────────────────────────────────────────────────── ✦✦ ─
|
|
25
|
-
__author__ = "K. LeBryce <kosmolebryce@gmail.com>"
|
|
26
|
-
__package__ = "Gnarly"
|
|
27
|
-
__version__ = "0.0.0"
|
|
25
|
+
__author__: str = "K. LeBryce <kosmolebryce@gmail.com>"
|
|
26
|
+
__package__: str = "Gnarly"
|
|
27
|
+
__version__: str = "0.0.0"
|
|
28
|
+
__description__: str = "A sophisticated abstraction layer for lazy developers."
|
|
28
29
|
|
|
29
30
|
# ─── resource references ──────────────────────────────────────────────── ✦✦ ─
|
|
30
31
|
GNARLY_DATA_DIR: Path = user_data_path(
|
|
@@ -55,6 +56,9 @@ GNARLY_LOG_DIR: Path = user_log_path(
|
|
|
55
56
|
ensure_exists=True
|
|
56
57
|
)
|
|
57
58
|
|
|
59
|
+
GNARLY_PROJECT_ROOT_PATH: Path = Path.home() / "gnarly/"
|
|
60
|
+
GNARLY_PROJECT_ROOT_PATH.mkdir(exist_ok=True)
|
|
61
|
+
|
|
58
62
|
DOTENV_FILE_PATH: Path = GNARLY_CONFIG_DIR / "gnarly.env"
|
|
59
63
|
DOTENV_FILE_PATH.touch()
|
|
60
64
|
|
|
@@ -75,3 +79,4 @@ except IOError as e:
|
|
|
75
79
|
f"{GNARLY_CONFIG_DIR.resolve()}"
|
|
76
80
|
)
|
|
77
81
|
raise RuntimeError from e
|
|
82
|
+
|
gnarly/errors.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Errors
|
|
3
|
+
======
|
|
4
|
+
|
|
5
|
+
This module defines the custom exception types used throughout the
|
|
6
|
+
code base. This is a Gnarly implementation detail.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
from .constants import GNARLY_LOG_DIR
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
logging.basicConfig(
|
|
15
|
+
level=logging.DEBUG,
|
|
16
|
+
filename=(GNARLY_LOG_DIR / "gnarly.log").resolve()
|
|
17
|
+
)
|
|
18
|
+
logger.info("Logger setup complete.")
|
|
19
|
+
|
|
20
|
+
class GnarlyError(Exception):
|
|
21
|
+
"""Gnarly's base error class."""
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class NamespaceError(GnarlyError):
|
|
26
|
+
"""
|
|
27
|
+
An error type that arises from an improper namespace access attempt.
|
|
28
|
+
"""
|
|
29
|
+
pass
|
gnarly/types.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Types
|
|
3
|
+
=====
|
|
4
|
+
|
|
5
|
+
Gnarly's custom typing framework. This is an implementation detail.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
from abc import ABC
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from enum import Flag, auto
|
|
13
|
+
from os import PathLike
|
|
14
|
+
|
|
15
|
+
from gnarly.errors import NamespaceError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
logger: logging.Logger = logging.getLogger()
|
|
19
|
+
logger.setLevel(logging.INFO)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class GnarlyProjectType(Flag):
|
|
23
|
+
"""
|
|
24
|
+
An enumeration of the languages that Gnarly currenetly supports
|
|
25
|
+
|
|
26
|
+
Reference members of this class directly whenever you want to specify
|
|
27
|
+
a language constraint. Avoid hard-coding comparisons to their `values`,
|
|
28
|
+
since their integer data types are semantically insignificant.
|
|
29
|
+
"""
|
|
30
|
+
CPP: int = auto()
|
|
31
|
+
HASKELL: int = auto()
|
|
32
|
+
JAVASCRIPT: int = auto()
|
|
33
|
+
PYTHON: int = auto()
|
|
34
|
+
R: int = auto()
|
|
35
|
+
RUST: int = auto()
|
|
36
|
+
SWIFT: int = auto()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# ─── Interfaces ────────────────────────────────────────────────────────── ✦ ─
|
|
40
|
+
@dataclass
|
|
41
|
+
class GnarlyProject:
|
|
42
|
+
name: str
|
|
43
|
+
project_type: GnarlyProjectType
|
|
44
|
+
logger: logging.Logger
|
|
45
|
+
is_persistent: bool
|
|
46
|
+
root_path: PathLike
|
|
47
|
+
dependencies: dict[str, list]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class GnarlyPythonProject(GnarlyProject):
|
|
52
|
+
project_type = GnarlyProjectType.PYTHON
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class GnarlyCppProject(GnarlyProject):
|
|
57
|
+
project_Type = GnarlyProjectType.CPP
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass
|
|
61
|
+
class GnarlyHaskellProject(GnarlyProject):
|
|
62
|
+
project_type = GnarlyProjectType.HASKELL
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class GnarlyJavaScriptProject(GnarlyProject):
|
|
67
|
+
project_type = GnarlyProjectType.JAVASCRIPT
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass
|
|
71
|
+
class GnarlyRProject(GnarlyProject):
|
|
72
|
+
project_type = GnarlyProjectType.R
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass
|
|
76
|
+
class GnarlyRustProject(GnarlyProject):
|
|
77
|
+
project_type = GnarlyProjectType.RUST
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass
|
|
81
|
+
class GnarlySwiftProject(GnarlyProject):
|
|
82
|
+
project_type = GnarlyProjectType.SWIFT
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class GnarlyNamespace(ABC):
|
|
86
|
+
"""
|
|
87
|
+
Base class for non-instantiable types that serve to encapsulate.
|
|
88
|
+
|
|
89
|
+
Subclasses of this ABC provide no constructors. Instead, attempts
|
|
90
|
+
to instantiate raise `NamespaceError`.
|
|
91
|
+
"""
|
|
92
|
+
context_key: str
|
|
93
|
+
|
|
94
|
+
def __new__(cls) -> NamespaceError:
|
|
95
|
+
logger.error("`Project` is not intended for direct instantiation.")
|
|
96
|
+
raise NamespaceError(
|
|
97
|
+
f"`{cls.__name__}` is a namespace, which means that it "
|
|
98
|
+
"has no constructors. Instead, you should call one of the "
|
|
99
|
+
"static factory methods provided in one of its inner classes, "
|
|
100
|
+
"all of which return instances of the `GnarlyProject` base "
|
|
101
|
+
"class's concrete implementations."
|
|
102
|
+
)
|
|
103
|
+
|
gnarly/utils/__init__.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utilities
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
A convenient library comprising a collection of simple Python utilities.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from . import code, io, llm
|
|
9
|
+
from .code import (
|
|
10
|
+
GnarlyProject,
|
|
11
|
+
GnarlyCppProject,
|
|
12
|
+
GnarlyHaskellProject,
|
|
13
|
+
GnarlyJavaScriptProject,
|
|
14
|
+
GnarlyPythonProject,
|
|
15
|
+
GnarlyRProject,
|
|
16
|
+
GnarlyRustProject,
|
|
17
|
+
GnarlySwiftProject,
|
|
18
|
+
GnarlyProjectType,
|
|
19
|
+
Project
|
|
20
|
+
)
|
|
21
|
+
from .llm.interfaces import ChatGPT, Claude
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
# ─── package-level exports ───────────────────────────────────────────────
|
|
26
|
+
"code", "llm",
|
|
27
|
+
|
|
28
|
+
# ─── module-level exports ────────────────────────────────────────────────
|
|
29
|
+
"io",
|
|
30
|
+
|
|
31
|
+
# ─── class-level exports ─────────────────────────────────────────────────
|
|
32
|
+
"ChatGPT",
|
|
33
|
+
"Claude",
|
|
34
|
+
"GnarlyProject",
|
|
35
|
+
"GnarlyCppProject",
|
|
36
|
+
"GnarlyHaskellProject",
|
|
37
|
+
"GnarlyJavaScriptProject",
|
|
38
|
+
"GnarlyPythonProject",
|
|
39
|
+
"GnarlyRProject",
|
|
40
|
+
"GnarlyRustProject",
|
|
41
|
+
"GnarlySwiftProject",
|
|
42
|
+
"GnarlyProjectType",
|
|
43
|
+
"Project"
|
|
44
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Gnarly Code
|
|
3
|
+
|
|
4
|
+
Developer utilities.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from . projects import (
|
|
9
|
+
GnarlyProject,
|
|
10
|
+
GnarlyCppProject,
|
|
11
|
+
GnarlyHaskellProject,
|
|
12
|
+
GnarlyJavaScriptProject,
|
|
13
|
+
GnarlyPythonProject,
|
|
14
|
+
GnarlyRProject,
|
|
15
|
+
GnarlyRustProject,
|
|
16
|
+
GnarlySwiftProject,
|
|
17
|
+
GnarlyProjectType,
|
|
18
|
+
Project
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"GnarlyProject",
|
|
24
|
+
"GnarlyCppProject",
|
|
25
|
+
"GnarlyHaskellProject",
|
|
26
|
+
"GnarlyJavaScriptProject",
|
|
27
|
+
"GnarlyPythonProject",
|
|
28
|
+
"GnarlyRProject",
|
|
29
|
+
"GnarlyRustProject",
|
|
30
|
+
"GnarlySwiftProject",
|
|
31
|
+
"GnarlyProjectType",
|
|
32
|
+
"Project"
|
|
33
|
+
]
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Projects
|
|
3
|
+
========
|
|
4
|
+
|
|
5
|
+
This module defines and implements various facilities useful for
|
|
6
|
+
project management.
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
import logging
|
|
10
|
+
from os import PathLike
|
|
11
|
+
|
|
12
|
+
from ...constants import GNARLY_PROJECT_ROOT_PATH
|
|
13
|
+
# from ...errors import NamespaceError
|
|
14
|
+
from ...types import (
|
|
15
|
+
GnarlyCppProject,
|
|
16
|
+
GnarlyHaskellProject,
|
|
17
|
+
GnarlyJavaScriptProject,
|
|
18
|
+
GnarlyNamespace,
|
|
19
|
+
GnarlyProject,
|
|
20
|
+
GnarlyProjectType,
|
|
21
|
+
GnarlyPythonProject,
|
|
22
|
+
GnarlyRProject,
|
|
23
|
+
GnarlyRustProject,
|
|
24
|
+
GnarlySwiftProject
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
logger: logging.Logger = logging.getLogger()
|
|
28
|
+
logging.basicConfig(level=logging.DEBUG, format=logging.BASIC_FORMAT)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Project(GnarlyNamespace):
|
|
32
|
+
"""
|
|
33
|
+
A namespace for Gnarly Code's project management utility suite.
|
|
34
|
+
|
|
35
|
+
This is a Gnarly implementation detail. It is not intended for direct
|
|
36
|
+
instantiation. Attempts to instantiate this class will raise a
|
|
37
|
+
``NamespaceError``.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Python:
|
|
43
|
+
"""
|
|
44
|
+
A namespace for Gnarly's Python project management utilities.
|
|
45
|
+
|
|
46
|
+
Use the static functions defined in the ``Project.Python`` namespace
|
|
47
|
+
to manage your Python project's code base.
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
Basic usage:
|
|
52
|
+
|
|
53
|
+
>>> from pprint import pprint
|
|
54
|
+
>>> from gnarly import Project
|
|
55
|
+
>>>
|
|
56
|
+
>>> mgr = Project.Python()
|
|
57
|
+
>>>
|
|
58
|
+
>>> pr: GnarlyPythonProject = mgr.create("my_python_project")
|
|
59
|
+
>>> pprint(pr)
|
|
60
|
+
GnarlyPythonProject(name='my_python_project',
|
|
61
|
+
project_type=<GnarlyProjectType.PYTHON: 8>,
|
|
62
|
+
logger=<RootLogger root (INFO)>,
|
|
63
|
+
is_persistent=True,
|
|
64
|
+
root_path=PosixPath('/Users/u/gnarly/gnarly_project'),
|
|
65
|
+
dependencies={'dev': [], 'optional': [], 'required': []})
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
context_key: str = "python_project_namespace"
|
|
71
|
+
) -> None:
|
|
72
|
+
self._context_key = context_key
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def context_key(self) -> str:
|
|
77
|
+
return self._context_key
|
|
78
|
+
|
|
79
|
+
@context_key.setter
|
|
80
|
+
def context_key(self, value: str) -> None:
|
|
81
|
+
self._context_key = value
|
|
82
|
+
|
|
83
|
+
@context_key.deleter
|
|
84
|
+
def context_key(self) -> None:
|
|
85
|
+
del self._context_key
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def create(
|
|
90
|
+
name: str = "gnarly_python_project",
|
|
91
|
+
project_type = GnarlyProjectType.PYTHON,
|
|
92
|
+
is_persistent: bool = True,
|
|
93
|
+
root_path: PathLike = GNARLY_PROJECT_ROOT_PATH / "gnarly_project",
|
|
94
|
+
dependencies: dict[str, list[str]] = {
|
|
95
|
+
"dev": [],
|
|
96
|
+
"optional": [],
|
|
97
|
+
"required": []
|
|
98
|
+
}
|
|
99
|
+
) -> "GnarlyPythonProject":
|
|
100
|
+
"""
|
|
101
|
+
Create a Python project.
|
|
102
|
+
|
|
103
|
+
Rather than instantiating ``GnarlyPythonProject`` directly, you
|
|
104
|
+
call this static method on your ``Project.Python`` manager.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
name : str
|
|
109
|
+
The Python project's name.
|
|
110
|
+
project_type : GnarlyProjectType
|
|
111
|
+
The project's type, as characterized by its target
|
|
112
|
+
language configuration.
|
|
113
|
+
is_persistent : bool
|
|
114
|
+
The project's persistence state. Defaults to ``True``.
|
|
115
|
+
root_path : PathLike
|
|
116
|
+
The project's root path.
|
|
117
|
+
dependencies : dict[str, list[str]]
|
|
118
|
+
A dictionary that represents the project's dependencies.
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
A new instance of ``GnarlyPythonProject``.
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
return Project.create(
|
|
127
|
+
name=name,
|
|
128
|
+
project_type=project_type,
|
|
129
|
+
is_persistent=is_persistent,
|
|
130
|
+
root_path=root_path,
|
|
131
|
+
dependencies=dependencies
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@staticmethod
|
|
136
|
+
def create(
|
|
137
|
+
name: str,
|
|
138
|
+
project_type: GnarlyProjectType,
|
|
139
|
+
is_persistent: bool = True,
|
|
140
|
+
root_path: PathLike = GNARLY_PROJECT_ROOT_PATH,
|
|
141
|
+
dependencies: dict[str, list] = {
|
|
142
|
+
"dev": [],
|
|
143
|
+
"optional": [],
|
|
144
|
+
"required": []
|
|
145
|
+
}
|
|
146
|
+
) -> "GnarlyProject":
|
|
147
|
+
match project_type:
|
|
148
|
+
case project_type.CPP:
|
|
149
|
+
return GnarlyCppProject(
|
|
150
|
+
name=name,
|
|
151
|
+
project_type=project_type,
|
|
152
|
+
is_persistent=is_persistent,
|
|
153
|
+
root_path=root_path,
|
|
154
|
+
dependencies=dependencies
|
|
155
|
+
)
|
|
156
|
+
case project_type.HASKELL:
|
|
157
|
+
return GnarlyHaskellProject(
|
|
158
|
+
name=name,
|
|
159
|
+
project_type=project_type,
|
|
160
|
+
is_persistent=is_persistent,
|
|
161
|
+
root_path=root_path,
|
|
162
|
+
dependencies=dependencies
|
|
163
|
+
)
|
|
164
|
+
case project_type.JAVASCRIPT:
|
|
165
|
+
return GnarlyJavaScriptProject(
|
|
166
|
+
name=name,
|
|
167
|
+
project_type=project_type,
|
|
168
|
+
is_persistent=is_persistent,
|
|
169
|
+
root_path=root_path,
|
|
170
|
+
dependencies=dependencies
|
|
171
|
+
)
|
|
172
|
+
case project_type.PYTHON:
|
|
173
|
+
return GnarlyPythonProject(
|
|
174
|
+
name=name,
|
|
175
|
+
project_type=project_type,
|
|
176
|
+
is_persistent=is_persistent,
|
|
177
|
+
root_path=root_path,
|
|
178
|
+
dependencies=dependencies
|
|
179
|
+
)
|
|
180
|
+
case project_type.R:
|
|
181
|
+
return GnarlyRProject(
|
|
182
|
+
name=name,
|
|
183
|
+
project_type=project_type,
|
|
184
|
+
is_persistent=is_persistent,
|
|
185
|
+
root_path=root_path,
|
|
186
|
+
dependencies=dependencies
|
|
187
|
+
)
|
|
188
|
+
case project_type.RUST:
|
|
189
|
+
return GnarlyRustProject(
|
|
190
|
+
name=name,
|
|
191
|
+
project_type=project_type,
|
|
192
|
+
is_persistent=is_persistent,
|
|
193
|
+
root_path=root_path,
|
|
194
|
+
dependencies=dependencies
|
|
195
|
+
)
|
|
196
|
+
case project_type.SWIFT:
|
|
197
|
+
return GnarlySwiftProject(
|
|
198
|
+
name=name,
|
|
199
|
+
project_type=project_type,
|
|
200
|
+
is_persistent=is_persistent,
|
|
201
|
+
root_path=root_path,
|
|
202
|
+
dependencies=dependencies
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
gnarly/utils/io.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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, INFO, 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(level=INFO)
|
|
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
|
+
# Input validation
|
|
60
|
+
if not isinstance(s, str):
|
|
61
|
+
raise TypeError("Input 's' must be a string")
|
|
62
|
+
|
|
63
|
+
if not isinstance(cps, int) or cps <= 0:
|
|
64
|
+
raise ValueError("cps must be a positive integer")
|
|
65
|
+
|
|
66
|
+
if charlim is not None and (not isinstance(charlim, int) or charlim <= 0):
|
|
67
|
+
raise ValueError("charlim must be a positive integer or None")
|
|
68
|
+
|
|
69
|
+
# Handle empty string
|
|
70
|
+
if not s:
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
# Get terminal width with silent fallback
|
|
74
|
+
try:
|
|
75
|
+
term_width: int = os.get_terminal_size().columns
|
|
76
|
+
charlim: int = charlim or max(20, term_width - 12) # Ensure minimum width
|
|
77
|
+
except (OSError, AttributeError):
|
|
78
|
+
# Log to file only (DEBUG level), not console
|
|
79
|
+
logger.debug("Failed to get terminal width, using default charlim")
|
|
80
|
+
charlim: int = charlim or 80 # Standard terminal width fallback
|
|
81
|
+
|
|
82
|
+
# Ensure charlim is reasonable
|
|
83
|
+
if charlim < 10:
|
|
84
|
+
charlim = 10
|
|
85
|
+
elif charlim > 200:
|
|
86
|
+
charlim = 200
|
|
87
|
+
|
|
88
|
+
lines = s.splitlines()
|
|
89
|
+
wsp = string.whitespace
|
|
90
|
+
break_chars = ["-", "–", "—", "─"] # Extended dash characters
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
delay: float = 1.0 / cps
|
|
94
|
+
except ZeroDivisionError as e:
|
|
95
|
+
logger.error(
|
|
96
|
+
"User attempted to specify a value of zero characters per second, "
|
|
97
|
+
"resulting in a `ZeroDivisionError`, because function `gnarly."
|
|
98
|
+
"utilities.io.stream` calculates the system sleep duration as the "
|
|
99
|
+
"reciprocal of `cps`."
|
|
100
|
+
)
|
|
101
|
+
raise ValueError("cps cannot be zero") from e
|
|
102
|
+
|
|
103
|
+
# Handle case where charlim is not set or is very large
|
|
104
|
+
if not charlim or charlim >= max(len(line) for line in lines) if lines else True:
|
|
105
|
+
for line in lines:
|
|
106
|
+
for c in line:
|
|
107
|
+
print(c, end="", flush=True)
|
|
108
|
+
sleep(delay)
|
|
109
|
+
print() # Simplified newline
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
# Process with character limit
|
|
113
|
+
for line in lines:
|
|
114
|
+
if not line: # Handle empty lines
|
|
115
|
+
print()
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
chars = list(enumerate(line)) # Convert to list to avoid iterator issues
|
|
119
|
+
i = 0
|
|
120
|
+
|
|
121
|
+
while i < len(chars):
|
|
122
|
+
char_index, c = chars[i]
|
|
123
|
+
|
|
124
|
+
# Normal character printing (not at line limit)
|
|
125
|
+
if (char_index % charlim != 0) or char_index == 0:
|
|
126
|
+
print(c, end="", flush=True)
|
|
127
|
+
sleep(delay)
|
|
128
|
+
i += 1
|
|
129
|
+
|
|
130
|
+
# At character limit - check for good break point
|
|
131
|
+
elif char_index % charlim == 0:
|
|
132
|
+
# If current character is a good break point
|
|
133
|
+
if c in wsp or c in break_chars:
|
|
134
|
+
print(c + "\n", end="", flush=True)
|
|
135
|
+
sleep(delay)
|
|
136
|
+
i += 1
|
|
137
|
+
|
|
138
|
+
# Look ahead for a good break point
|
|
139
|
+
else:
|
|
140
|
+
print(c, end="", flush=True)
|
|
141
|
+
sleep(delay)
|
|
142
|
+
i += 1
|
|
143
|
+
|
|
144
|
+
# Look for next whitespace or break character
|
|
145
|
+
lookahead_limit = min(20, len(chars) - i) # Don't look too far ahead
|
|
146
|
+
found_break = False
|
|
147
|
+
|
|
148
|
+
for j in range(lookahead_limit):
|
|
149
|
+
if i + j >= len(chars):
|
|
150
|
+
break
|
|
151
|
+
|
|
152
|
+
_, next_c = chars[i + j]
|
|
153
|
+
print(next_c, end="", flush=True)
|
|
154
|
+
sleep(delay)
|
|
155
|
+
|
|
156
|
+
if next_c in wsp or next_c in break_chars:
|
|
157
|
+
print("\n", end="", flush=True)
|
|
158
|
+
found_break = True
|
|
159
|
+
i += j + 1
|
|
160
|
+
break
|
|
161
|
+
|
|
162
|
+
# If no break found within lookahead, force break
|
|
163
|
+
if not found_break:
|
|
164
|
+
print("\n", end="", flush=True)
|
|
165
|
+
i += lookahead_limit
|
|
166
|
+
|
|
167
|
+
else:
|
|
168
|
+
# This shouldn't happen, but handle it gracefully
|
|
169
|
+
logger.debug(f"Unexpected condition at index {char_index}, character '{c}'")
|
|
170
|
+
print(c, end="", flush=True)
|
|
171
|
+
sleep(delay)
|
|
172
|
+
i += 1
|
|
173
|
+
|
|
174
|
+
print() # End of line
|
|
175
|
+
|
|
176
|
+
return None
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Gnarly LLM Utilities
|
|
3
|
+
====================
|
|
4
|
+
|
|
5
|
+
Interfaces for LLM interaction.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from . import chatgpt, claude, interfaces, models
|
|
9
|
+
from .interfaces import Claude, ChatGPT
|
|
10
|
+
from .models import ChatGPTModel, ClaudeModel
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"Claude",
|
|
15
|
+
"ClaudeModel",
|
|
16
|
+
"ChatGPT",
|
|
17
|
+
"ChatGPTModel",
|
|
18
|
+
"chatgpt",
|
|
19
|
+
"claude",
|
|
20
|
+
"interfaces",
|
|
21
|
+
"models"
|
|
22
|
+
]
|