framework-py 0.1.0.dev23__py3-none-any.whl → 0.1.0.dev24__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.
- framework/cloud.py +56 -23
- framework/dotenv.py +51 -10
- framework/skill_pull.py +5 -1
- framework/sync_all.py +3 -1
- {framework_py-0.1.0.dev23.dist-info → framework_py-0.1.0.dev24.dist-info}/METADATA +1 -1
- {framework_py-0.1.0.dev23.dist-info → framework_py-0.1.0.dev24.dist-info}/RECORD +8 -8
- {framework_py-0.1.0.dev23.dist-info → framework_py-0.1.0.dev24.dist-info}/WHEEL +0 -0
- {framework_py-0.1.0.dev23.dist-info → framework_py-0.1.0.dev24.dist-info}/licenses/LICENSE +0 -0
framework/cloud.py
CHANGED
|
@@ -13,8 +13,12 @@ The server is resolved per call, as in R:
|
|
|
13
13
|
- Project calls (publishing, the ledger): the ``url`` argument, then
|
|
14
14
|
``FW_CLOUD_URL`` in the project's ``.env``, then the environment variable,
|
|
15
15
|
then the saved login. A project token is only valid on the server that
|
|
16
|
-
issued it
|
|
17
|
-
|
|
16
|
+
issued it. A project whose ``.env`` has ``FW_PROJECT_TOKEN`` but no
|
|
17
|
+
``FW_CLOUD_URL`` never uses the saved login: these calls raise
|
|
18
|
+
``ProjectServerMissingError``. When saved logins name different servers,
|
|
19
|
+
they stop instead of guessing.
|
|
20
|
+
- Every call that writes a new ``FW_PROJECT_TOKEN`` also writes
|
|
21
|
+
``FW_CLOUD_URL``, the server that issued it.
|
|
18
22
|
- With nothing set, calls raise ``NoServerError``. Only ``cloud_login()``
|
|
19
23
|
falls back to https://framework.pub, which its notice names before
|
|
20
24
|
connecting. Using the public cloud is always the user's choice.
|
|
@@ -81,6 +85,22 @@ class AmbiguousServerError(CloudError):
|
|
|
81
85
|
"""A project call found logins to several servers and nothing naming the project's."""
|
|
82
86
|
|
|
83
87
|
|
|
88
|
+
class ProjectServerMissingError(CloudError):
|
|
89
|
+
"""A project's ``.env`` has ``FW_PROJECT_TOKEN`` but no ``FW_CLOUD_URL``.
|
|
90
|
+
|
|
91
|
+
The token is only valid on the server that issued it, so project calls stop
|
|
92
|
+
instead of using the saved login. Not a ``NoServerError``, so code that
|
|
93
|
+
treats "no server" as "not signed in" still surfaces it.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
PROJECT_SERVER_MISSING = (
|
|
98
|
+
"This project's .env has FW_PROJECT_TOKEN but no FW_CLOUD_URL, so it does not say which "
|
|
99
|
+
"Framework Cloud server issued the token. Add FW_CLOUD_URL=<server> to .env, or pass "
|
|
100
|
+
'url="<server>".'
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
84
104
|
def _version() -> str:
|
|
85
105
|
from framework import __version__
|
|
86
106
|
|
|
@@ -178,7 +198,10 @@ def cloud_server(
|
|
|
178
198
|
|
|
179
199
|
``scope`` is ``"user"``, ``"project"``, or ``"login"``. Raises
|
|
180
200
|
``NoServerError`` when nothing names a server, except for ``"login"``,
|
|
181
|
-
which falls back to https://framework.pub.
|
|
201
|
+
which falls back to https://framework.pub. A project whose ``.env`` has
|
|
202
|
+
``FW_PROJECT_TOKEN`` but no ``FW_CLOUD_URL`` never uses the saved login:
|
|
203
|
+
without the ``url`` argument or the ``FW_CLOUD_URL`` environment variable,
|
|
204
|
+
project calls raise ``ProjectServerMissingError``.
|
|
182
205
|
"""
|
|
183
206
|
candidates: list[tuple[str | None, str]] = [(url, "the url argument")]
|
|
184
207
|
if scope == "project":
|
|
@@ -187,6 +210,8 @@ def cloud_server(
|
|
|
187
210
|
for value, source in candidates:
|
|
188
211
|
if value:
|
|
189
212
|
return Server(normalize_url(str(value)), source)
|
|
213
|
+
if scope == "project" and _project_env("FW_PROJECT_TOKEN", project_dir):
|
|
214
|
+
raise ProjectServerMissingError(PROJECT_SERVER_MISSING)
|
|
190
215
|
|
|
191
216
|
saved = _saved_urls()
|
|
192
217
|
if len(saved) == 1 or (saved and scope != "project"):
|
|
@@ -729,6 +754,9 @@ def cloud_status(url: str | None = None) -> bool:
|
|
|
729
754
|
if project_token() is not None:
|
|
730
755
|
try:
|
|
731
756
|
project: Server | None = cloud_server(scope="project")
|
|
757
|
+
except ProjectServerMissingError as error:
|
|
758
|
+
inform(str(error))
|
|
759
|
+
project = None
|
|
732
760
|
except CloudError:
|
|
733
761
|
project = None
|
|
734
762
|
if project is not None and project.url != server.url:
|
|
@@ -879,15 +907,20 @@ def _ledger_live() -> bool:
|
|
|
879
907
|
def ledger_push_quietly(name: str, digest: str, file_path: Path | None = None) -> Any:
|
|
880
908
|
"""Send one digest to the project's ledger after ``data_save()``, in live mode only.
|
|
881
909
|
|
|
882
|
-
No project token
|
|
883
|
-
failed save. framework.db stays the record
|
|
910
|
+
No project token, a project that doesn't name its server, or an unreachable
|
|
911
|
+
server means "local only", never a failed save. framework.db stays the record
|
|
912
|
+
either way.
|
|
884
913
|
"""
|
|
885
914
|
if not _ledger_live():
|
|
886
915
|
return None
|
|
887
916
|
token = project_token()
|
|
888
917
|
if token is None:
|
|
889
918
|
return None
|
|
890
|
-
|
|
919
|
+
try:
|
|
920
|
+
url = cloud_server(scope="project").url
|
|
921
|
+
except ProjectServerMissingError as error:
|
|
922
|
+
inform(f"Ledger push skipped: {error}")
|
|
923
|
+
return None
|
|
891
924
|
body = {
|
|
892
925
|
"name": name,
|
|
893
926
|
"algo": "sha256",
|
|
@@ -1279,28 +1312,27 @@ def cloud_publish(
|
|
|
1279
1312
|
def write_project_token(project_dir: Path, token: str, url: str) -> list[str]:
|
|
1280
1313
|
"""Add the project's key and server to its ``.env`` (never to the settings).
|
|
1281
1314
|
|
|
1282
|
-
|
|
1315
|
+
``FW_PROJECT_TOKEN`` and ``FW_CLOUD_URL`` are written together, so the project
|
|
1316
|
+
always names the server that issued its token. An empty or different
|
|
1317
|
+
``FW_CLOUD_URL`` is replaced. A project that already has a token keeps it, and
|
|
1318
|
+
its ``.env`` is left as it is. Git is made to ignore ``.env`` first, so the
|
|
1319
|
+
token can't be committed. Returns the keys written.
|
|
1283
1320
|
"""
|
|
1284
1321
|
from framework.create import keep_env_out_of_git
|
|
1285
1322
|
|
|
1286
1323
|
env = project_dir / ".env"
|
|
1287
|
-
|
|
1288
|
-
missing = {
|
|
1289
|
-
k: v for k, v in (("FW_PROJECT_TOKEN", token), ("FW_CLOUD_URL", url)) if k not in present
|
|
1290
|
-
}
|
|
1291
|
-
if not missing:
|
|
1324
|
+
if dotenv.value(env, "FW_PROJECT_TOKEN"):
|
|
1292
1325
|
return []
|
|
1326
|
+
server = normalize_url(url)
|
|
1293
1327
|
keep_env_out_of_git(project_dir)
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
inform(f" Added: {' and '.join(missing)} to .env")
|
|
1303
|
-
return list(missing)
|
|
1328
|
+
written = dotenv.set_values(
|
|
1329
|
+
env,
|
|
1330
|
+
{"FW_PROJECT_TOKEN": token, "FW_CLOUD_URL": server},
|
|
1331
|
+
header="Framework Cloud project key and server (created by framework.new)",
|
|
1332
|
+
)
|
|
1333
|
+
if written:
|
|
1334
|
+
inform(f" Wrote {' and '.join(written)} to .env")
|
|
1335
|
+
return written
|
|
1304
1336
|
|
|
1305
1337
|
|
|
1306
1338
|
def registration_body(
|
|
@@ -1508,7 +1540,8 @@ def cloud_register(
|
|
|
1508
1540
|
tools, and none of your defaults. An adopted project is marked as
|
|
1509
1541
|
adopted.
|
|
1510
1542
|
2. Writes the project token and server to ``.env`` (``FW_PROJECT_TOKEN``,
|
|
1511
|
-
``FW_CLOUD_URL``), making sure git ignores ``.env`` first.
|
|
1543
|
+
``FW_CLOUD_URL``), making sure git ignores ``.env`` first. An empty or
|
|
1544
|
+
different ``FW_CLOUD_URL`` is replaced with the server that issued the token.
|
|
1512
1545
|
|
|
1513
1546
|
A project that already has a token in ``.env`` is left as it is. When you
|
|
1514
1547
|
already have a project with the slug, an interactive session offers to
|
framework/dotenv.py
CHANGED
|
@@ -112,19 +112,60 @@ def value(path: str | Path, key: str) -> str | None:
|
|
|
112
112
|
return found or None
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
def
|
|
116
|
-
""
|
|
115
|
+
def _defines(line: str, key: str) -> bool:
|
|
116
|
+
if line.startswith("#") or not line.strip():
|
|
117
|
+
return False
|
|
118
|
+
match = _LINE.match(line)
|
|
119
|
+
return match is not None and match["key"] == key
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
|
|
122
|
+
def _placeholder(line: str, key: str) -> bool:
|
|
123
|
+
"""A commented ``# KEY=`` line, as in a starter ``.env``."""
|
|
124
|
+
return re.match(rf"^#\s*(?:export\s+)?{re.escape(key)}=", line) is not None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def set_values(path: str | Path, values: Mapping[str, str], header: str | None = None) -> list[str]:
|
|
128
|
+
"""Set ``KEY=value`` lines, keeping every other line as it is.
|
|
129
|
+
|
|
130
|
+
A key the file defines has its line replaced in place. Otherwise a commented
|
|
131
|
+
``# KEY=`` placeholder is filled, or the line goes after the key set just
|
|
132
|
+
before it. Keys with no place go at the end, under ``header`` when given.
|
|
133
|
+
Returns the keys whose value changed.
|
|
119
134
|
"""
|
|
120
135
|
file = Path(path)
|
|
121
136
|
text = file.read_text(encoding="utf-8") if file.exists() else ""
|
|
122
137
|
present = parse(text)
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
lines = text.splitlines()
|
|
139
|
+
changed: list[str] = []
|
|
140
|
+
appended: list[str] = []
|
|
141
|
+
previous: int | None = None
|
|
142
|
+
for key, new in values.items():
|
|
143
|
+
line = f"{key}={new}"
|
|
144
|
+
if key in present and present[key] == new:
|
|
145
|
+
previous = max(i for i, old in enumerate(lines) if _defines(old, key))
|
|
146
|
+
continue
|
|
147
|
+
changed.append(key)
|
|
148
|
+
defining = [i for i, old in enumerate(lines) if _defines(old, key)]
|
|
149
|
+
filled = next((i for i, old in enumerate(lines) if _placeholder(old, key)), None)
|
|
150
|
+
if defining:
|
|
151
|
+
for i in defining:
|
|
152
|
+
lines[i] = line
|
|
153
|
+
previous = defining[-1]
|
|
154
|
+
elif filled is not None:
|
|
155
|
+
lines[filled] = line
|
|
156
|
+
previous = filled
|
|
157
|
+
elif previous is not None:
|
|
158
|
+
lines.insert(previous + 1, line)
|
|
159
|
+
previous += 1
|
|
160
|
+
else:
|
|
161
|
+
appended.append(line)
|
|
162
|
+
if not changed:
|
|
125
163
|
return []
|
|
126
|
-
if
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
164
|
+
if appended:
|
|
165
|
+
if lines and lines[-1].strip():
|
|
166
|
+
lines.append("")
|
|
167
|
+
if header:
|
|
168
|
+
lines.append(f"# {header}")
|
|
169
|
+
lines += appended
|
|
170
|
+
file.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
171
|
+
return changed
|
framework/skill_pull.py
CHANGED
|
@@ -258,11 +258,13 @@ def pull_skills(
|
|
|
258
258
|
|
|
259
259
|
Raises:
|
|
260
260
|
ProjectNotFoundError: When the folder is not a Framework project.
|
|
261
|
+
ProjectServerMissingError: When ``.env`` has ``FW_PROJECT_TOKEN`` but no
|
|
262
|
+
``FW_CLOUD_URL``.
|
|
261
263
|
"""
|
|
262
264
|
from framework._agents_md import refresh_skills
|
|
263
265
|
from framework._log import inform, show_messages
|
|
264
266
|
from framework.ai import _installed_spec
|
|
265
|
-
from framework.cloud import CloudError
|
|
267
|
+
from framework.cloud import CloudError, ProjectServerMissingError
|
|
266
268
|
from framework.skill_sync import _lock
|
|
267
269
|
from framework.spec.merge import SpecError
|
|
268
270
|
|
|
@@ -274,6 +276,8 @@ def pull_skills(
|
|
|
274
276
|
try:
|
|
275
277
|
wanted = _cloud_skills(root, notes)
|
|
276
278
|
source = "cloud"
|
|
279
|
+
except ProjectServerMissingError:
|
|
280
|
+
raise
|
|
277
281
|
except (CloudError, SpecError) as error:
|
|
278
282
|
reason = str(error).rstrip(".") or type(error).__name__
|
|
279
283
|
inform(
|
framework/sync_all.py
CHANGED
|
@@ -313,11 +313,13 @@ def _partial(function: str, done: str, outcome: dict[str, Any]) -> str:
|
|
|
313
313
|
|
|
314
314
|
def _setup(root: Path) -> tuple[str, str, dict[str, Any]]:
|
|
315
315
|
"""The project's server, token, and package list; errors change nothing."""
|
|
316
|
-
from framework.cloud import CloudError, _request
|
|
316
|
+
from framework.cloud import CloudError, ProjectServerMissingError, _request
|
|
317
317
|
|
|
318
318
|
try:
|
|
319
319
|
server, token = _connection(root)
|
|
320
320
|
setup = _request("/api/v1/projects/setup", token, server).json()
|
|
321
|
+
except ProjectServerMissingError:
|
|
322
|
+
raise
|
|
321
323
|
except CloudError as error:
|
|
322
324
|
raise _unreachable(error) from error
|
|
323
325
|
return server, token, setup if isinstance(setup, dict) else {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: framework-py
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev24
|
|
4
4
|
Summary: Structured data science projects: a data catalog, integrity tracking, caching, outputs, and AI guardrails
|
|
5
5
|
Project-URL: Homepage, https://framework.pub
|
|
6
6
|
Project-URL: Source, https://github.com/frameworktools/framework-py
|
|
@@ -25,7 +25,7 @@ framework/ai.py,sha256=hqBNXngw7VyQBcSt7kB20Zpa6N_5WS1hNhDi2zWJw0U,9218
|
|
|
25
25
|
framework/bootstrap.py,sha256=mYlD1BG9KaG9PAIHlw3l6677fJYwQdtih95W9Rqmnho,9687
|
|
26
26
|
framework/cache.py,sha256=z8Zaem5Q7dsAghuX9CgK_j0vhX5dDlRw7fl9f-CF3eA,17440
|
|
27
27
|
framework/catalog.py,sha256=sl4V1judSCVoa2LYLXeQdDhWdsONTC_5s2_fpyPylto,13202
|
|
28
|
-
framework/cloud.py,sha256=
|
|
28
|
+
framework/cloud.py,sha256=6w1oIfgGPPLLC2ILUvAqPXhIMlU08XJXd-KsP85QDbY,67608
|
|
29
29
|
framework/config_home.py,sha256=iSb0VuENgNOSnsZ_v53xFqjRiGgrB7OzZbHbyDOqKzs,8265
|
|
30
30
|
framework/connections.py,sha256=99JqrNAi2zBpNYyxLV6SYj-NAJjh56pYh9jaMSYOHCU,32742
|
|
31
31
|
framework/console.py,sha256=zQ0LuFDcxe1W1kuc5E1bJ03h8d3cvwFoqDT8dAJQyN0,1267
|
|
@@ -34,7 +34,7 @@ framework/data.py,sha256=cAOxwmF_nowXIZPl6vW5-ZUyI_z16H1bRJM60gJgeoo,36522
|
|
|
34
34
|
framework/data_registry.py,sha256=2hbXsoY9IF5Zj6lkiTE2RO2c5j2Z2vXKm2iTN7FdsQk,22499
|
|
35
35
|
framework/db.py,sha256=UYEUCvk4vGytBkmdNTUxRpYPtoFSDHwTpgpfWFw31aE,8522
|
|
36
36
|
framework/display.py,sha256=0FuKUt67uf5h1WjD4bwzoruc2XAN4y_j3mz_f5FskhE,5334
|
|
37
|
-
framework/dotenv.py,sha256=
|
|
37
|
+
framework/dotenv.py,sha256=BYSF6YE92jXO7dqnaR-857XtZNYOx7FTuxCcCeIZ_yw,6172
|
|
38
38
|
framework/errors.py,sha256=kOXK0D-7xpcal8XsVnGAV9Nga-3xXxUFq-gdMn--El4,1177
|
|
39
39
|
framework/features.py,sha256=NlR-0Xa4_d_nEBX9MicVyWqE_5L1-sA-zF_pJeNWznw,7729
|
|
40
40
|
framework/global_config.py,sha256=fYLaxN_6Wc2xrIASn77dWkvGR3uuX-111bvfFPB82A4,11036
|
|
@@ -51,10 +51,10 @@ framework/scaffold.py,sha256=ku_rFPcOcV77ZxCJSG1tdxAqJhriuTuA6j2jOmjBaIs,15958
|
|
|
51
51
|
framework/scratch.py,sha256=idxthUR5BIMX7FIGS7KzIuhOrO3-HKLbBsV8It3EEE4,3890
|
|
52
52
|
framework/security.py,sha256=-x66bSIIE_xOzkTf5Ojt7xIECKuAIpKVJZ5TtIGrwys,51147
|
|
53
53
|
framework/settings.py,sha256=Sb2YyE53aYLWPj423P-pQVCvRpLsiHydgZh2K0luTQQ,23893
|
|
54
|
-
framework/skill_pull.py,sha256=
|
|
54
|
+
framework/skill_pull.py,sha256=vr_yxe446JhHbtI0hps19AnLN6S7BacSt2oxn7BIlos,21859
|
|
55
55
|
framework/skill_sync.py,sha256=0gqaeVkiNaqGJxmrVrKrYaX8wI3DNFZUsJEgG63xcKc,23060
|
|
56
56
|
framework/storage.py,sha256=UnTL9buYwawFFGll4D0FRDqsVXjj_B2uYMELXntfq_M,55486
|
|
57
|
-
framework/sync_all.py,sha256=
|
|
57
|
+
framework/sync_all.py,sha256=tmSnapf-JfaL1_8rMpnr3wqHvSGJamn7c8ja4GQFKHA,34610
|
|
58
58
|
framework/upgrade.py,sha256=WtghpLR65YFH_JQFmo1JlH9lHdwsXQd-ZzzOTmyOL28,65593
|
|
59
59
|
framework/_assets/init.sql,sha256=-aIiuIcCmBniGKq-CHdRtUiV9e_CLXoqxxd05snmgOE,1156
|
|
60
60
|
framework/_assets/adopt/rules.json,sha256=Ao_8reCfxohbF27hzVBjXJeMUP2E9MzlLMqrLutv41o,7603
|
|
@@ -139,7 +139,7 @@ framework/templates/stubs/notebook-default.qmd,sha256=8Js1S2BcHYeQWmJS-kt31gBvIj
|
|
|
139
139
|
framework/templates/stubs/notebook-minimal.qmd,sha256=2U2k8judffhrh_6m6r6OAbQBCYEtViAjeKRBqBYCJTM,178
|
|
140
140
|
framework/templates/stubs/notebook-revealjs.qmd,sha256=_ztT_gHoudpB5DIjlbvtB5zQ8163DeV8xbWcT-HgJrI,409
|
|
141
141
|
framework/templates/stubs/script-default.py,sha256=vbWqgW0_rHot17mQC3tYb92g_9L-cbTOeL3y99BRrSk,216
|
|
142
|
-
framework_py-0.1.0.
|
|
143
|
-
framework_py-0.1.0.
|
|
144
|
-
framework_py-0.1.0.
|
|
145
|
-
framework_py-0.1.0.
|
|
142
|
+
framework_py-0.1.0.dev24.dist-info/METADATA,sha256=AO0jqjl_730e6cN5rB6qlmGY77wCb7wqn6ZOEK6jaEE,4682
|
|
143
|
+
framework_py-0.1.0.dev24.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
144
|
+
framework_py-0.1.0.dev24.dist-info/licenses/LICENSE,sha256=giOOgSwALkZimC7uhLZQK8Untez641bLW1-2-Cjvmq0,1072
|
|
145
|
+
framework_py-0.1.0.dev24.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|