fmtr.tools 1.2.6__tar.gz → 1.3.0__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 fmtr.tools might be problematic. Click here for more details.
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/PKG-INFO +42 -42
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/dns_tools/server.py +1 -1
- fmtr_tools-1.3.0/fmtr/tools/pattern_tools.py +232 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/setup_tools/setup_tools.py +147 -47
- fmtr_tools-1.3.0/fmtr/tools/version +1 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/PKG-INFO +42 -42
- fmtr_tools-1.2.6/fmtr/tools/pattern_tools.py +0 -175
- fmtr_tools-1.2.6/fmtr/tools/version +0 -1
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/LICENSE +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/README.md +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/ai_tools/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/ai_tools/agentic_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/ai_tools/inference_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/api_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/async_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/augmentation_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/caching_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/constants.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/data_modelling_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/dataclass_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/datatype_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/debugging_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/dns_tools/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/dns_tools/client.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/dns_tools/dm.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/docker_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/entrypoints/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/entrypoints/cache_hfh.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/entrypoints/ep_test.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/entrypoints/remote_debug_test.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/entrypoints/shell_debug.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/environment_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/function_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/google_api_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/hash_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/hfh_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/html_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/http_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/import_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/inspection_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/interface_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/iterator_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/json_fix_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/json_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/logging_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/merging_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/metric_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/name_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/netrc_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/openai_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/packaging_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/parallel_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/path_tools/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/path_tools/app_path_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/path_tools/path_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/path_tools/type_path_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/pdf_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/platform_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/process_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/profiling_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/random_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/semantic_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/settings_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/setup_tools/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/spaces_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/string_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tabular_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/__init__.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/conftest.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/helpers.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/test_datatype.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/test_environment.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/test_json.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/test_path.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tests/test_yaml.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tokenization_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/unicode_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/version_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr/tools/yaml_tools.py +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/SOURCES.txt +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/dependency_links.txt +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/entry_points.txt +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/requires.txt +41 -41
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/fmtr.tools.egg-info/top_level.txt +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/pyproject.toml +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/setup.cfg +0 -0
- {fmtr_tools-1.2.6 → fmtr_tools-1.3.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fmtr.tools
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Collection of high-level tools to simplify everyday development tasks, with a focus on AI/ML
|
|
5
5
|
Home-page: https://github.com/fmtr/tools
|
|
6
6
|
Author: Frontmatter
|
|
@@ -130,60 +130,60 @@ Requires-Dist: logfire[httpx]; extra == "http"
|
|
|
130
130
|
Provides-Extra: setup
|
|
131
131
|
Requires-Dist: setuptools; extra == "setup"
|
|
132
132
|
Provides-Extra: all
|
|
133
|
-
Requires-Dist:
|
|
133
|
+
Requires-Dist: torchaudio; extra == "all"
|
|
134
|
+
Requires-Dist: httpx; extra == "all"
|
|
135
|
+
Requires-Dist: dask[bag]; extra == "all"
|
|
136
|
+
Requires-Dist: docker; extra == "all"
|
|
137
|
+
Requires-Dist: diskcache; extra == "all"
|
|
138
|
+
Requires-Dist: ollama; extra == "all"
|
|
139
|
+
Requires-Dist: pyyaml; extra == "all"
|
|
140
|
+
Requires-Dist: pydantic; extra == "all"
|
|
141
|
+
Requires-Dist: google-auth-httplib2; extra == "all"
|
|
142
|
+
Requires-Dist: semver; extra == "all"
|
|
143
|
+
Requires-Dist: pymupdf4llm; extra == "all"
|
|
144
|
+
Requires-Dist: flet-video; extra == "all"
|
|
145
|
+
Requires-Dist: appdirs; extra == "all"
|
|
146
|
+
Requires-Dist: logfire; extra == "all"
|
|
147
|
+
Requires-Dist: json_repair; extra == "all"
|
|
148
|
+
Requires-Dist: pydevd-pycharm; extra == "all"
|
|
149
|
+
Requires-Dist: torchvision; extra == "all"
|
|
134
150
|
Requires-Dist: Unidecode; extra == "all"
|
|
151
|
+
Requires-Dist: contexttimer; extra == "all"
|
|
152
|
+
Requires-Dist: faker; extra == "all"
|
|
153
|
+
Requires-Dist: regex; extra == "all"
|
|
154
|
+
Requires-Dist: setuptools; extra == "all"
|
|
155
|
+
Requires-Dist: flet-webview; extra == "all"
|
|
156
|
+
Requires-Dist: tinynetrc; extra == "all"
|
|
135
157
|
Requires-Dist: uvicorn[standard]; extra == "all"
|
|
136
|
-
Requires-Dist: huggingface_hub; extra == "all"
|
|
137
158
|
Requires-Dist: logfire[fastapi]; extra == "all"
|
|
138
|
-
Requires-Dist: pymupdf4llm; extra == "all"
|
|
139
|
-
Requires-Dist: semver; extra == "all"
|
|
140
159
|
Requires-Dist: pymupdf; extra == "all"
|
|
141
|
-
Requires-Dist:
|
|
142
|
-
Requires-Dist:
|
|
143
|
-
Requires-Dist:
|
|
144
|
-
Requires-Dist:
|
|
145
|
-
Requires-Dist:
|
|
146
|
-
Requires-Dist:
|
|
147
|
-
Requires-Dist:
|
|
148
|
-
Requires-Dist: regex; extra == "all"
|
|
149
|
-
Requires-Dist: json_repair; extra == "all"
|
|
150
|
-
Requires-Dist: html2text; extra == "all"
|
|
151
|
-
Requires-Dist: faker; extra == "all"
|
|
152
|
-
Requires-Dist: openpyxl; extra == "all"
|
|
153
|
-
Requires-Dist: appdirs; extra == "all"
|
|
160
|
+
Requires-Dist: tokenizers; extra == "all"
|
|
161
|
+
Requires-Dist: distributed; extra == "all"
|
|
162
|
+
Requires-Dist: filetype; extra == "all"
|
|
163
|
+
Requires-Dist: yamlscript; extra == "all"
|
|
164
|
+
Requires-Dist: dnspython[doh]; extra == "all"
|
|
165
|
+
Requires-Dist: google-api-python-client; extra == "all"
|
|
166
|
+
Requires-Dist: pandas; extra == "all"
|
|
154
167
|
Requires-Dist: logfire[httpx]; extra == "all"
|
|
168
|
+
Requires-Dist: httpx_retries; extra == "all"
|
|
155
169
|
Requires-Dist: openai; extra == "all"
|
|
170
|
+
Requires-Dist: bokeh; extra == "all"
|
|
171
|
+
Requires-Dist: flet[all]; extra == "all"
|
|
156
172
|
Requires-Dist: sentence_transformers; extra == "all"
|
|
173
|
+
Requires-Dist: google-auth; extra == "all"
|
|
174
|
+
Requires-Dist: transformers[sentencepiece]; extra == "all"
|
|
175
|
+
Requires-Dist: peft; extra == "all"
|
|
157
176
|
Requires-Dist: pydantic-ai[logfire,openai]; extra == "all"
|
|
177
|
+
Requires-Dist: google-auth-oauthlib; extra == "all"
|
|
178
|
+
Requires-Dist: pytest-cov; extra == "all"
|
|
158
179
|
Requires-Dist: fastapi; extra == "all"
|
|
159
|
-
Requires-Dist:
|
|
160
|
-
Requires-Dist: ollama; extra == "all"
|
|
161
|
-
Requires-Dist: tokenizers; extra == "all"
|
|
162
|
-
Requires-Dist: dnspython[doh]; extra == "all"
|
|
163
|
-
Requires-Dist: flet-video; extra == "all"
|
|
164
|
-
Requires-Dist: pandas; extra == "all"
|
|
165
|
-
Requires-Dist: yamlscript; extra == "all"
|
|
166
|
-
Requires-Dist: filetype; extra == "all"
|
|
167
|
-
Requires-Dist: logfire; extra == "all"
|
|
180
|
+
Requires-Dist: huggingface_hub; extra == "all"
|
|
168
181
|
Requires-Dist: tabulate; extra == "all"
|
|
169
|
-
Requires-Dist: google-auth-oauthlib; extra == "all"
|
|
170
|
-
Requires-Dist: flet[all]; extra == "all"
|
|
171
182
|
Requires-Dist: pydantic-settings; extra == "all"
|
|
172
|
-
Requires-Dist:
|
|
183
|
+
Requires-Dist: openpyxl; extra == "all"
|
|
173
184
|
Requires-Dist: deepmerge; extra == "all"
|
|
174
|
-
Requires-Dist: distributed; extra == "all"
|
|
175
|
-
Requires-Dist: flet-webview; extra == "all"
|
|
176
|
-
Requires-Dist: setuptools; extra == "all"
|
|
177
|
-
Requires-Dist: pyyaml; extra == "all"
|
|
178
185
|
Requires-Dist: sre_yield; extra == "all"
|
|
179
|
-
Requires-Dist:
|
|
180
|
-
Requires-Dist: torchaudio; extra == "all"
|
|
181
|
-
Requires-Dist: pydantic; extra == "all"
|
|
182
|
-
Requires-Dist: google-auth-httplib2; extra == "all"
|
|
183
|
-
Requires-Dist: docker; extra == "all"
|
|
184
|
-
Requires-Dist: httpx; extra == "all"
|
|
185
|
-
Requires-Dist: pytest-cov; extra == "all"
|
|
186
|
-
Requires-Dist: httpx_retries; extra == "all"
|
|
186
|
+
Requires-Dist: html2text; extra == "all"
|
|
187
187
|
Dynamic: author
|
|
188
188
|
Dynamic: author-email
|
|
189
189
|
Dynamic: description
|
|
@@ -66,7 +66,7 @@ class ServerBaseDoHProxy(ServerBasePlain):
|
|
|
66
66
|
|
|
67
67
|
request = exchange.request
|
|
68
68
|
|
|
69
|
-
with logger.span(f'Handling request for {request.name_text} from {exchange.client}...'):
|
|
69
|
+
with logger.span(f'Handling request ID {request.message.id} for {request.name_text} from {exchange.client}...'):
|
|
70
70
|
|
|
71
71
|
if not request.is_valid:
|
|
72
72
|
raise ValueError(f'Only one question per request is supported. Got {len(request.question)} questions.')
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import regex as re
|
|
2
|
+
from dataclasses import dataclass, asdict
|
|
3
|
+
from functools import cached_property
|
|
4
|
+
from typing import List, Any
|
|
5
|
+
|
|
6
|
+
from fmtr.tools.logging_tools import logger
|
|
7
|
+
from fmtr.tools.string_tools import join
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RewriteCircularLoopError(Exception):
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
Circular loop error
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
MASK_GROUP = '(?:{pattern})'
|
|
19
|
+
MASK_NAMED = r"(?P<{key}>{pattern})"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def alt(*patterns):
|
|
23
|
+
patterns = sorted(patterns, key=len, reverse=True)
|
|
24
|
+
pattern = '|'.join(patterns)
|
|
25
|
+
pattern = MASK_GROUP.format(pattern=pattern)
|
|
26
|
+
return pattern
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class Key:
|
|
35
|
+
RECORD_SEP = '␞'
|
|
36
|
+
|
|
37
|
+
def flatten(self, data):
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
Flatten/serialise dictionary data
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
pairs = [f'{value}' for key, value in data.items()]
|
|
44
|
+
string = self.RECORD_SEP.join(pairs)
|
|
45
|
+
return string
|
|
46
|
+
|
|
47
|
+
@cached_property
|
|
48
|
+
def pattern(self):
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
Serialise to pattern
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
data = {key: MASK_NAMED.format(key=key, pattern=value) for key, value in asdict(self).items()}
|
|
55
|
+
pattern = self.flatten(data)
|
|
56
|
+
return pattern
|
|
57
|
+
|
|
58
|
+
@cached_property
|
|
59
|
+
def rx(self):
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
Compile to Regular Expression
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
return re.compile(self.pattern)
|
|
66
|
+
|
|
67
|
+
@cached_property
|
|
68
|
+
def string(self):
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
Serialise to string
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
string = self.flatten(asdict(self))
|
|
75
|
+
return string
|
|
76
|
+
|
|
77
|
+
def transform(self, match: re.Match):
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
Transform match object into a new object of the same type.
|
|
81
|
+
|
|
82
|
+
"""
|
|
83
|
+
groupdict = match.groupdict()
|
|
84
|
+
data = {key: value.format(**groupdict) for key, value in asdict(self).items()}
|
|
85
|
+
obj = self.__class__(**data)
|
|
86
|
+
return obj
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass
|
|
90
|
+
class Item:
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
Key-value pair
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
key: Key
|
|
97
|
+
value: Key
|
|
98
|
+
|
|
99
|
+
@dataclass
|
|
100
|
+
class Mapper:
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
Pattern-based, dictionary-like mapper.
|
|
104
|
+
Compiles a single regex pattern from a list of rules, and determines which rule matched.
|
|
105
|
+
It supports initialization from structured rule data, execution of a single lookup pass, and
|
|
106
|
+
recursive lookups until a stable state is reached.
|
|
107
|
+
|
|
108
|
+
"""
|
|
109
|
+
PREFIX_GROUP = '__'
|
|
110
|
+
items: List[Item]
|
|
111
|
+
default: Any = None
|
|
112
|
+
is_recursive: bool = False
|
|
113
|
+
|
|
114
|
+
@cached_property
|
|
115
|
+
def pattern(self):
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
Provides a dynamically generated regex pattern based on the rules provided.
|
|
119
|
+
|
|
120
|
+
"""
|
|
121
|
+
patterns = [
|
|
122
|
+
MASK_NAMED.format(key=f'{self.PREFIX_GROUP}{i}', pattern=item.key.pattern)
|
|
123
|
+
for i, item in enumerate(self.items)
|
|
124
|
+
]
|
|
125
|
+
pattern = alt(*patterns)
|
|
126
|
+
return pattern
|
|
127
|
+
|
|
128
|
+
@cached_property
|
|
129
|
+
def rx(self):
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
Regex object.
|
|
133
|
+
|
|
134
|
+
"""
|
|
135
|
+
return re.compile(self.pattern)
|
|
136
|
+
|
|
137
|
+
def get_default(self, key: Key):
|
|
138
|
+
if self.is_recursive:
|
|
139
|
+
return key
|
|
140
|
+
else:
|
|
141
|
+
return self.default
|
|
142
|
+
|
|
143
|
+
def get(self, key: Key) -> Key:
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
Use recursive or single lookup pass, depending on whether recursive lookups have been specified.
|
|
147
|
+
|
|
148
|
+
"""
|
|
149
|
+
if self.is_recursive:
|
|
150
|
+
return self.get_recursive(key)
|
|
151
|
+
else:
|
|
152
|
+
return self.get_one(key)
|
|
153
|
+
|
|
154
|
+
def get_one(self, key: Key):
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
Single lookup pass.
|
|
158
|
+
Lookup the source string based on the matching rule.
|
|
159
|
+
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
match = self.rx.fullmatch(key.string)
|
|
163
|
+
|
|
164
|
+
if not match:
|
|
165
|
+
value = self.get_default(key)
|
|
166
|
+
logger.debug(f'No match for {key=}.')
|
|
167
|
+
else:
|
|
168
|
+
|
|
169
|
+
match_ids = {name: v for name, v in match.groupdict().items() if v}
|
|
170
|
+
rule_ids = {
|
|
171
|
+
int(id.removeprefix(self.PREFIX_GROUP))
|
|
172
|
+
for id in match_ids.keys() if id.startswith(self.PREFIX_GROUP)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if len(rule_ids) != 1:
|
|
176
|
+
msg = f'Multiple group matches: {rule_ids}'
|
|
177
|
+
raise ValueError(msg)
|
|
178
|
+
|
|
179
|
+
rule_id = next(iter(rule_ids))
|
|
180
|
+
rule = self.items[rule_id]
|
|
181
|
+
|
|
182
|
+
if isinstance(rule.value, Key):
|
|
183
|
+
value = rule.value.transform(match)
|
|
184
|
+
else:
|
|
185
|
+
value = rule.value
|
|
186
|
+
|
|
187
|
+
logger.debug(f'Matched using {rule_id=}: {key=} → {value=}')
|
|
188
|
+
|
|
189
|
+
return value
|
|
190
|
+
|
|
191
|
+
def get_recursive(self, key: Key) -> Key:
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
Lookup the provided text by continuously applying lookup rules until no changes are made
|
|
195
|
+
or a circular loop is detected.
|
|
196
|
+
|
|
197
|
+
"""
|
|
198
|
+
history = []
|
|
199
|
+
previous = key
|
|
200
|
+
|
|
201
|
+
def get_history_str():
|
|
202
|
+
return join(history, sep=' → ')
|
|
203
|
+
|
|
204
|
+
with logger.span(f'Matching {key=}...'):
|
|
205
|
+
while True:
|
|
206
|
+
if previous in history:
|
|
207
|
+
history.append(previous)
|
|
208
|
+
msg = f'Loop detected on node "{previous}": {get_history_str()}'
|
|
209
|
+
raise RewriteCircularLoopError(msg)
|
|
210
|
+
|
|
211
|
+
history.append(previous)
|
|
212
|
+
|
|
213
|
+
new = previous
|
|
214
|
+
|
|
215
|
+
new = self.get_one(new)
|
|
216
|
+
|
|
217
|
+
if new == previous:
|
|
218
|
+
break
|
|
219
|
+
|
|
220
|
+
previous = new
|
|
221
|
+
|
|
222
|
+
if len(history) == 1:
|
|
223
|
+
history_str = 'No matching performed.'
|
|
224
|
+
else:
|
|
225
|
+
history_str = get_history_str()
|
|
226
|
+
logger.debug(f'Finished matching: {history_str}')
|
|
227
|
+
|
|
228
|
+
return previous
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
if __name__ == '__main__':
|
|
232
|
+
...
|
|
@@ -3,7 +3,7 @@ from datetime import datetime
|
|
|
3
3
|
from fnmatch import fnmatch
|
|
4
4
|
from functools import cached_property
|
|
5
5
|
from itertools import chain
|
|
6
|
-
from typing import List, Dict
|
|
6
|
+
from typing import List, Dict, Any, Callable, Optional
|
|
7
7
|
|
|
8
8
|
from fmtr.tools.constants import Constants
|
|
9
9
|
from fmtr.tools.path_tools import Path
|
|
@@ -18,7 +18,6 @@ class SetupPaths(FromCallerMixin):
|
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
20
|
def __init__(self, path=None, org=Constants.ORG_NAME):
|
|
21
|
-
|
|
22
21
|
"""
|
|
23
22
|
|
|
24
23
|
Use calling module path as default path, if not otherwise specified.
|
|
@@ -31,15 +30,30 @@ class SetupPaths(FromCallerMixin):
|
|
|
31
30
|
self.repo = Path(path)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def readme(self):
|
|
33
|
+
def readme(self) -> Path:
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
Path of the README file.
|
|
37
|
+
|
|
38
|
+
"""
|
|
35
39
|
return self.repo / 'README.md'
|
|
36
40
|
|
|
37
41
|
@property
|
|
38
|
-
def version(self):
|
|
42
|
+
def version(self) -> Path:
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
Path of the version file
|
|
46
|
+
|
|
47
|
+
"""
|
|
39
48
|
return self.path / Constants.FILENAME_VERSION
|
|
40
49
|
|
|
41
50
|
@cached_property
|
|
42
|
-
def path(self):
|
|
51
|
+
def path(self) -> Path:
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
Infer the package path. It should be the only non-excluded package in the repo/org Path.
|
|
55
|
+
|
|
56
|
+
"""
|
|
43
57
|
|
|
44
58
|
if self.is_namespace:
|
|
45
59
|
base = self.org
|
|
@@ -61,7 +75,12 @@ class SetupPaths(FromCallerMixin):
|
|
|
61
75
|
return package
|
|
62
76
|
|
|
63
77
|
@property
|
|
64
|
-
def org(self):
|
|
78
|
+
def org(self) -> bool | Path:
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
Get the org path, i.e. the namespace parent directory.
|
|
82
|
+
|
|
83
|
+
"""
|
|
65
84
|
if not self.org_name:
|
|
66
85
|
return False
|
|
67
86
|
org = self.repo / self.org_name
|
|
@@ -70,7 +89,12 @@ class SetupPaths(FromCallerMixin):
|
|
|
70
89
|
return org
|
|
71
90
|
|
|
72
91
|
@property
|
|
73
|
-
def entrypoints(self):
|
|
92
|
+
def entrypoints(self) -> Path:
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
Path of entrypoints sub-package.
|
|
96
|
+
|
|
97
|
+
"""
|
|
74
98
|
return self.path / Constants.ENTRYPOINTS_DIR
|
|
75
99
|
|
|
76
100
|
@property
|
|
@@ -83,6 +107,11 @@ class SetupPaths(FromCallerMixin):
|
|
|
83
107
|
|
|
84
108
|
|
|
85
109
|
class Setup(FromCallerMixin):
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
Abstract canonical pacakge setup for setuptools.
|
|
113
|
+
|
|
114
|
+
"""
|
|
86
115
|
AUTHOR = 'Frontmatter'
|
|
87
116
|
AUTHOR_EMAIL = 'innovative.fowler@mask.pro.fmtr.dev'
|
|
88
117
|
|
|
@@ -93,8 +122,12 @@ class Setup(FromCallerMixin):
|
|
|
93
122
|
ENTRYPOINT_FUNC_NAME = 'main'
|
|
94
123
|
|
|
95
124
|
def __init__(self, dependencies, paths=None, org=Constants.ORG_NAME, client=None, do_setup=True, **kwargs):
|
|
125
|
+
"""
|
|
96
126
|
|
|
127
|
+
First check if commandline arguments for requirements output exist. If so, print them and return early.
|
|
128
|
+
Otherwise, continue generating data to pass to setuptools.
|
|
97
129
|
|
|
130
|
+
"""
|
|
98
131
|
self.kwargs = kwargs
|
|
99
132
|
|
|
100
133
|
if type(dependencies) is not Dependencies:
|
|
@@ -115,11 +148,15 @@ class Setup(FromCallerMixin):
|
|
|
115
148
|
|
|
116
149
|
self.client = client
|
|
117
150
|
|
|
118
|
-
|
|
119
151
|
if do_setup:
|
|
120
152
|
self.setup()
|
|
121
153
|
|
|
122
|
-
def get_requirements_extras(self):
|
|
154
|
+
def get_requirements_extras(self) -> Optional[List[str]]:
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
Get list of extras from command line arguments.
|
|
158
|
+
|
|
159
|
+
"""
|
|
123
160
|
if self.REQUIREMENTS_ARG not in sys.argv:
|
|
124
161
|
return None
|
|
125
162
|
|
|
@@ -128,6 +165,11 @@ class Setup(FromCallerMixin):
|
|
|
128
165
|
return extras
|
|
129
166
|
|
|
130
167
|
def print_requirements(self):
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
Output flat list of requirements for specified extras
|
|
171
|
+
|
|
172
|
+
"""
|
|
131
173
|
reqs = []
|
|
132
174
|
reqs += self.dependencies.install
|
|
133
175
|
|
|
@@ -137,12 +179,17 @@ class Setup(FromCallerMixin):
|
|
|
137
179
|
print(reqs)
|
|
138
180
|
|
|
139
181
|
@property
|
|
140
|
-
def console_scripts(self):
|
|
182
|
+
def console_scripts(self) -> List[str]:
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
Generate console scripts for any modules in the `entrypoints` sub-package.
|
|
186
|
+
|
|
187
|
+
"""
|
|
141
188
|
|
|
142
189
|
if not self.paths.entrypoints.exists():
|
|
143
|
-
return
|
|
190
|
+
return []
|
|
144
191
|
|
|
145
|
-
names_mods = [path.stem for path in self.paths.entrypoints.iterdir() if path.is_file() and
|
|
192
|
+
names_mods = [path.stem for path in self.paths.entrypoints.iterdir() if path.is_file() and path.name != Constants.INIT_FILENAME]
|
|
146
193
|
command_prefix = self.name.replace('.', self.ENTRYPOINT_COMMAND_SEP)
|
|
147
194
|
command_suffixes = [name_mod.replace(self.ENTRYPOINT_FUNCTION_SEP, self.ENTRYPOINT_COMMAND_SEP) for name_mod in names_mods]
|
|
148
195
|
commands = [f'{command_prefix}-{command_suffix}' for command_suffix in command_suffixes]
|
|
@@ -153,35 +200,63 @@ class Setup(FromCallerMixin):
|
|
|
153
200
|
return console_scripts
|
|
154
201
|
|
|
155
202
|
@property
|
|
156
|
-
def name(self):
|
|
203
|
+
def name(self) -> str:
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
Full library name
|
|
207
|
+
|
|
208
|
+
"""
|
|
157
209
|
if self.paths.is_namespace:
|
|
158
210
|
return f'{self.paths.org_name}.{self.paths.name}'
|
|
159
211
|
return self.paths.name
|
|
160
212
|
|
|
161
213
|
@property
|
|
162
|
-
def author(self):
|
|
214
|
+
def author(self) -> str:
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
Create appropriate author string
|
|
218
|
+
|
|
219
|
+
"""
|
|
163
220
|
if self.client:
|
|
164
221
|
return f'{self.AUTHOR} on behalf of {self.client}'
|
|
165
222
|
return self.AUTHOR
|
|
166
223
|
|
|
167
224
|
@property
|
|
168
|
-
def copyright(self):
|
|
225
|
+
def copyright(self) -> str:
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
Create appropriate copyright string
|
|
229
|
+
|
|
230
|
+
"""
|
|
169
231
|
if self.client:
|
|
170
232
|
return self.client
|
|
171
233
|
return self.AUTHOR
|
|
172
234
|
|
|
173
235
|
@property
|
|
174
|
-
def long_description(self):
|
|
236
|
+
def long_description(self) -> str:
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
Read in README.md
|
|
175
240
|
|
|
241
|
+
"""
|
|
176
242
|
return self.paths.readme.read_text()
|
|
177
243
|
|
|
178
244
|
@property
|
|
179
|
-
def version(self):
|
|
245
|
+
def version(self) -> str:
|
|
246
|
+
"""
|
|
247
|
+
|
|
248
|
+
Read in the version string from file
|
|
249
|
+
|
|
250
|
+
"""
|
|
180
251
|
return self.paths.version.read_text().strip()
|
|
181
252
|
|
|
182
253
|
@property
|
|
183
|
-
def find(self):
|
|
254
|
+
def find(self) -> Callable:
|
|
255
|
+
"""
|
|
256
|
+
|
|
257
|
+
Use the appropriate package finding function from setuptools
|
|
184
258
|
|
|
259
|
+
"""
|
|
185
260
|
from fmtr.tools import setup
|
|
186
261
|
|
|
187
262
|
if self.paths.is_namespace:
|
|
@@ -190,13 +265,23 @@ class Setup(FromCallerMixin):
|
|
|
190
265
|
return setup.find_packages
|
|
191
266
|
|
|
192
267
|
@property
|
|
193
|
-
def packages(self):
|
|
268
|
+
def packages(self) -> List[str]:
|
|
269
|
+
"""
|
|
270
|
+
|
|
271
|
+
Fetch list of packages excluding canonical paths
|
|
272
|
+
|
|
273
|
+
"""
|
|
194
274
|
excludes = list(Constants.PACKAGE_EXCLUDE_DIRS) + [f'{name}.*' for name in Constants.PACKAGE_EXCLUDE_DIRS if '*' not in name]
|
|
195
275
|
packages = self.find(where=str(self.paths.repo), exclude=excludes)
|
|
196
276
|
return packages
|
|
197
277
|
|
|
198
278
|
@property
|
|
199
279
|
def package_dir(self):
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
Needs to be relative apparently as absolute paths break during packaging
|
|
283
|
+
|
|
284
|
+
"""
|
|
200
285
|
if self.paths.is_namespace:
|
|
201
286
|
return {'': '.'}
|
|
202
287
|
else:
|
|
@@ -204,14 +289,29 @@ class Setup(FromCallerMixin):
|
|
|
204
289
|
|
|
205
290
|
@property
|
|
206
291
|
def package_data(self):
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
Default package data is just the version file
|
|
295
|
+
|
|
296
|
+
"""
|
|
207
297
|
return {self.name: [Constants.FILENAME_VERSION]}
|
|
208
298
|
|
|
209
299
|
@property
|
|
210
|
-
def url(self):
|
|
211
|
-
|
|
300
|
+
def url(self) -> str:
|
|
301
|
+
"""
|
|
302
|
+
|
|
303
|
+
Default to GitHub URL
|
|
304
|
+
|
|
305
|
+
"""
|
|
306
|
+
return f'https://github.com/{self.org}/{self.name}'
|
|
212
307
|
|
|
213
308
|
@property
|
|
214
|
-
def data(self):
|
|
309
|
+
def data(self) -> Dict[str, Any]:
|
|
310
|
+
"""
|
|
311
|
+
|
|
312
|
+
Generate data for use by setuptools
|
|
313
|
+
|
|
314
|
+
"""
|
|
215
315
|
data = dict(
|
|
216
316
|
name=self.name,
|
|
217
317
|
version=self.version,
|
|
@@ -233,13 +333,30 @@ class Setup(FromCallerMixin):
|
|
|
233
333
|
return data
|
|
234
334
|
|
|
235
335
|
def setup(self):
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
Call setuptools.setup using generated data
|
|
339
|
+
|
|
340
|
+
"""
|
|
236
341
|
|
|
237
342
|
from fmtr.tools import setup
|
|
238
343
|
|
|
239
344
|
return setup.setup_setuptools(**self.data)
|
|
240
345
|
|
|
346
|
+
def __repr__(self) -> str:
|
|
347
|
+
"""
|
|
348
|
+
|
|
349
|
+
Show library name
|
|
350
|
+
|
|
351
|
+
"""
|
|
352
|
+
return f'{self.__class__.__name__}("{self.name}")'
|
|
241
353
|
|
|
242
354
|
class Tools:
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
Helper for downstream libraries to specify lists of `fmtr.tools` extras
|
|
358
|
+
|
|
359
|
+
"""
|
|
243
360
|
MASK = f'{Constants.LIBRARY_NAME}[{{extras}}]'
|
|
244
361
|
|
|
245
362
|
def __init__(self, *extras):
|
|
@@ -261,7 +378,7 @@ class Dependencies:
|
|
|
261
378
|
def resolve_values(self, key) -> List[str]:
|
|
262
379
|
"""
|
|
263
380
|
|
|
264
|
-
Flatten a list of
|
|
381
|
+
Flatten a list of dependencies.
|
|
265
382
|
|
|
266
383
|
"""
|
|
267
384
|
values_resolved = []
|
|
@@ -290,7 +407,12 @@ class Dependencies:
|
|
|
290
407
|
return resolved
|
|
291
408
|
|
|
292
409
|
@cached_property
|
|
293
|
-
def install(self):
|
|
410
|
+
def install(self) -> List[str]:
|
|
411
|
+
"""
|
|
412
|
+
|
|
413
|
+
Get install_requires
|
|
414
|
+
|
|
415
|
+
"""
|
|
294
416
|
if self.INSTALL in self.dependencies:
|
|
295
417
|
return self.resolve_values(self.INSTALL)
|
|
296
418
|
else:
|
|
@@ -298,26 +420,4 @@ class Dependencies:
|
|
|
298
420
|
|
|
299
421
|
|
|
300
422
|
if __name__ == '__main__':
|
|
301
|
-
|
|
302
|
-
install=['version', 'yaml'],
|
|
303
|
-
|
|
304
|
-
yaml=['yamlscript', 'pyyaml'],
|
|
305
|
-
logging=['logfire', 'version'],
|
|
306
|
-
version=['semver', 'av'],
|
|
307
|
-
av=['av']
|
|
308
|
-
# Add the rest of your dependencies...
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
ds
|
|
312
|
-
|
|
313
|
-
setup = Setup(
|
|
314
|
-
# client='Acme',
|
|
315
|
-
dependencies=ds,
|
|
316
|
-
description='some tools test',
|
|
317
|
-
console_scripts=dict(
|
|
318
|
-
cache_hfh='console_script_tools',
|
|
319
|
-
test=None,
|
|
320
|
-
)
|
|
321
|
-
)
|
|
322
|
-
data = setup.get_data_setup()
|
|
323
|
-
data
|
|
423
|
+
...
|