framework-py 0.1.0.dev14__py3-none-any.whl → 0.1.0.dev16__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/__init__.py +6 -0
- framework/__main__.py +14 -2
- framework/_agents_md.py +48 -3
- framework/ai.py +7 -45
- framework/cloud.py +35 -2
- framework/create.py +208 -14
- framework/setup_sync.py +534 -0
- framework/skill_pull.py +506 -0
- framework/skill_sync.py +38 -14
- {framework_py-0.1.0.dev14.dist-info → framework_py-0.1.0.dev16.dist-info}/METADATA +1 -1
- {framework_py-0.1.0.dev14.dist-info → framework_py-0.1.0.dev16.dist-info}/RECORD +13 -11
- {framework_py-0.1.0.dev14.dist-info → framework_py-0.1.0.dev16.dist-info}/WHEEL +0 -0
- {framework_py-0.1.0.dev14.dist-info → framework_py-0.1.0.dev16.dist-info}/licenses/LICENSE +0 -0
framework/__init__.py
CHANGED
|
@@ -128,6 +128,8 @@ from framework.scaffold import project_info, scaffold, status
|
|
|
128
128
|
from framework.scratch import scratch_capture, scratch_clean
|
|
129
129
|
from framework.security import AuditResult, git_security_audit
|
|
130
130
|
from framework.settings import settings, settings_read, settings_write
|
|
131
|
+
from framework.setup_sync import pull_setup, push_setup
|
|
132
|
+
from framework.skill_pull import pull_skills, push_skills
|
|
131
133
|
from framework.skill_sync import skills_sync
|
|
132
134
|
from framework.spec.check import spec_check
|
|
133
135
|
from framework.spec.merge import SpecError
|
|
@@ -247,6 +249,10 @@ __all__ = [
|
|
|
247
249
|
"publish_dir",
|
|
248
250
|
"publish_list",
|
|
249
251
|
"publish_notebook",
|
|
252
|
+
"pull_setup",
|
|
253
|
+
"pull_skills",
|
|
254
|
+
"push_setup",
|
|
255
|
+
"push_skills",
|
|
250
256
|
"quarto_generate_all",
|
|
251
257
|
"quarto_regenerate",
|
|
252
258
|
"read_framework_template",
|
framework/__main__.py
CHANGED
|
@@ -37,8 +37,20 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
37
37
|
create.add_argument("--path", required=True, help="the project folder to create")
|
|
38
38
|
create.add_argument(
|
|
39
39
|
"--type",
|
|
40
|
-
choices=[
|
|
41
|
-
|
|
40
|
+
choices=[
|
|
41
|
+
"project",
|
|
42
|
+
"project_sensitive",
|
|
43
|
+
"course",
|
|
44
|
+
"presentation",
|
|
45
|
+
"bare",
|
|
46
|
+
"shiny",
|
|
47
|
+
"shiny_python",
|
|
48
|
+
"fastapi",
|
|
49
|
+
],
|
|
50
|
+
help=(
|
|
51
|
+
"project type, with --name (default: project, or asked with --interactive); "
|
|
52
|
+
"shiny and fastapi need a Framework Cloud login"
|
|
53
|
+
),
|
|
42
54
|
)
|
|
43
55
|
create.add_argument(
|
|
44
56
|
"--workflow",
|
framework/_agents_md.py
CHANGED
|
@@ -55,10 +55,35 @@ def _header(name: str) -> str:
|
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def
|
|
58
|
+
def skill_description(folder: Path) -> str:
|
|
59
|
+
"""A skill's own description, from its SKILL.md front matter, on one line with pipes
|
|
60
|
+
escaped, for skills Framework has no line for. R: ``.skill_description()``."""
|
|
61
|
+
from framework import _yaml
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
text = (folder / "SKILL.md").read_text(encoding="utf-8")
|
|
65
|
+
except OSError:
|
|
66
|
+
return ""
|
|
67
|
+
found = re.match(r"---\r?\n(.*?)\r?\n---", text, re.DOTALL)
|
|
68
|
+
try:
|
|
69
|
+
meta = _yaml.load(found.group(1)) if found else None
|
|
70
|
+
except Exception:
|
|
71
|
+
meta = None
|
|
72
|
+
value = meta.get("description") if isinstance(meta, dict) else None
|
|
73
|
+
if not isinstance(value, str):
|
|
74
|
+
return ""
|
|
75
|
+
return " ".join(value.split()).replace("|", "\\|")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _skills(skills: list[str], skills_dir: str, root: Path | None = None) -> str:
|
|
79
|
+
def covers(skill: str) -> str:
|
|
80
|
+
known = SKILL_DESCRIPTIONS.get(skill)
|
|
81
|
+
if known is not None or root is None:
|
|
82
|
+
return known or ""
|
|
83
|
+
return skill_description(root / skills_dir / skill)
|
|
84
|
+
|
|
59
85
|
rows = [
|
|
60
|
-
f"| `{skill}` | {
|
|
61
|
-
for skill in skills
|
|
86
|
+
f"| `{skill}` | {covers(skill)} | `{skills_dir}/{skill}/SKILL.md` |" for skill in skills
|
|
62
87
|
]
|
|
63
88
|
return "\n".join(
|
|
64
89
|
[
|
|
@@ -170,6 +195,26 @@ def refresh_packages(root: Path, names: list[str]) -> Path | None:
|
|
|
170
195
|
return path
|
|
171
196
|
|
|
172
197
|
|
|
198
|
+
def refresh_skills(root: Path, skills: list[str], skills_dir: str) -> Path | None:
|
|
199
|
+
"""Rewrite the context file's Skills section to list ``skills`` in ``skills_dir``.
|
|
200
|
+
|
|
201
|
+
Only a file with a ``## Skills`` heading changes; the rest of it is kept. Returns the
|
|
202
|
+
file when it changed.
|
|
203
|
+
"""
|
|
204
|
+
path = context_file(root)
|
|
205
|
+
if path is None:
|
|
206
|
+
return None
|
|
207
|
+
text = path.read_text(encoding="utf-8")
|
|
208
|
+
found = re.search(r"^## Skills[^\n]*\n.*?(?=\n+## |\n*\Z)", text, re.DOTALL | re.MULTILINE)
|
|
209
|
+
if found is None:
|
|
210
|
+
return None
|
|
211
|
+
updated = text[: found.start()] + _skills(skills, skills_dir, root) + text[found.end() :]
|
|
212
|
+
if updated == text:
|
|
213
|
+
return None
|
|
214
|
+
path.write_text(updated, encoding="utf-8")
|
|
215
|
+
return path
|
|
216
|
+
|
|
217
|
+
|
|
173
218
|
def _data(spec: dict[str, Any]) -> str:
|
|
174
219
|
directories = spec.get("directories") or {}
|
|
175
220
|
rows = [
|
framework/ai.py
CHANGED
|
@@ -210,59 +210,21 @@ def _installed_spec(root: Path) -> dict[str, Any]:
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def ai_skills_update(project_path: str | Path = ".") ->
|
|
214
|
-
"""
|
|
213
|
+
def ai_skills_update(project_path: str | Path = ".") -> dict[str, Any]:
|
|
214
|
+
"""Bring the project's skills up to date. The same as ``pull_skills(project_path)``.
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
``.framework/skills.lock.json`` existed counts as clean when it matches a
|
|
219
|
-
SKILL.md framework-py has shipped (``templates/skill-history.json``), and
|
|
220
|
-
is updated, backed up first to ``.framework/skills-backups/``. The skills and assistants
|
|
221
|
-
come from ``.framework/spec.json``, or from the settings for projects
|
|
222
|
-
without one.
|
|
216
|
+
Kept for scripts written before ``pull_skills()``. See ``pull_skills()`` for what is
|
|
217
|
+
added, updated, kept, and listed.
|
|
223
218
|
|
|
224
219
|
Args:
|
|
225
220
|
project_path: The project's root directory. Default: the current directory.
|
|
226
221
|
|
|
227
222
|
Returns:
|
|
228
|
-
|
|
229
|
-
out.
|
|
223
|
+
What ``pull_skills()`` returns.
|
|
230
224
|
|
|
231
225
|
Raises:
|
|
232
226
|
ProjectNotFoundError: When the folder has no ``.framework/spec.json`` or settings file.
|
|
233
227
|
"""
|
|
234
|
-
from framework.
|
|
228
|
+
from framework.skill_pull import pull_skills
|
|
235
229
|
|
|
236
|
-
|
|
237
|
-
root = Path(project_path).expanduser()
|
|
238
|
-
from framework.project import _settings_in
|
|
239
|
-
|
|
240
|
-
if not (root / ".framework/spec.json").is_file() and _settings_in(root) is None:
|
|
241
|
-
from framework.errors import ProjectNotFoundError
|
|
242
|
-
|
|
243
|
-
raise ProjectNotFoundError(
|
|
244
|
-
f"{root} is not a Framework project: it has no .framework/spec.json or settings file."
|
|
245
|
-
)
|
|
246
|
-
spec = _installed_spec(root)
|
|
247
|
-
folders, _ = assistant_targets(spec)
|
|
248
|
-
updated = []
|
|
249
|
-
for name, entry in (spec.get("skills") or {}).items():
|
|
250
|
-
if not (isinstance(entry, dict) and entry.get("package") is True):
|
|
251
|
-
continue
|
|
252
|
-
if not _shipped(name).is_dir():
|
|
253
|
-
continue
|
|
254
|
-
for folder in folders:
|
|
255
|
-
from framework.skill_sync import bundle_hash, install_package, scan
|
|
256
|
-
|
|
257
|
-
target = root / folder / name
|
|
258
|
-
# Only a skill whose files changed counts as updated
|
|
259
|
-
before = bundle_hash(scan(target)) if target.is_dir() else None
|
|
260
|
-
if install_package(_shipped(name), root, f"{folder}/{name}", name) and (
|
|
261
|
-
(bundle_hash(scan(target)) if target.is_dir() else None) != before
|
|
262
|
-
):
|
|
263
|
-
updated.append(f"{folder}/{name}")
|
|
264
|
-
if updated:
|
|
265
|
-
inform(f"✓ Updated {len(updated)} Framework skill(s)")
|
|
266
|
-
else:
|
|
267
|
-
inform("No Framework skills to update")
|
|
268
|
-
return updated
|
|
230
|
+
return pull_skills(project_path)
|
framework/cloud.py
CHANGED
|
@@ -40,6 +40,7 @@ from dataclasses import dataclass
|
|
|
40
40
|
from datetime import UTC, datetime
|
|
41
41
|
from pathlib import Path
|
|
42
42
|
from typing import Any
|
|
43
|
+
from urllib.parse import unquote
|
|
43
44
|
|
|
44
45
|
import httpx
|
|
45
46
|
import pandas as pd
|
|
@@ -342,6 +343,17 @@ class _MissingEndpointError(CloudError):
|
|
|
342
343
|
"""HTTP 404 or 405: an older server without this endpoint."""
|
|
343
344
|
|
|
344
345
|
|
|
346
|
+
class CloudConflictError(CloudError):
|
|
347
|
+
"""HTTP 409: what was sent was based on a version the server has moved past.
|
|
348
|
+
|
|
349
|
+
``body`` is the reply, such as ``{"message": ..., "revision": ...}``.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
def __init__(self, message: str, body: dict[str, Any]) -> None:
|
|
353
|
+
super().__init__(message)
|
|
354
|
+
self.body = body
|
|
355
|
+
|
|
356
|
+
|
|
345
357
|
def _error(response: httpx.Response, what: str) -> CloudError:
|
|
346
358
|
try:
|
|
347
359
|
body = response.json()
|
|
@@ -362,6 +374,8 @@ def _error(response: httpx.Response, what: str) -> CloudError:
|
|
|
362
374
|
message = "\n".join([str(message), *details])
|
|
363
375
|
if response.status_code in (404, 405):
|
|
364
376
|
return _MissingEndpointError(str(message))
|
|
377
|
+
if response.status_code == 409:
|
|
378
|
+
return CloudConflictError(str(message), body)
|
|
365
379
|
if response.status_code >= 500:
|
|
366
380
|
return CloudOfflineError(str(message))
|
|
367
381
|
return CloudError(str(message))
|
|
@@ -1617,9 +1631,28 @@ def cloud_register(
|
|
|
1617
1631
|
|
|
1618
1632
|
def fetch_layers(key: str, url: str | None = None) -> tuple[dict[str, Any], str]:
|
|
1619
1633
|
"""A project's layers file from the cloud, by its project token."""
|
|
1634
|
+
envelope, server, _ = pull_project(key, url)
|
|
1635
|
+
return envelope, server
|
|
1636
|
+
|
|
1637
|
+
|
|
1638
|
+
def pull_project(key: str, url: str | None = None) -> tuple[dict[str, Any], str, str | None]:
|
|
1639
|
+
"""A project's layers file, its server, and the owner's Projects folder, by project token.
|
|
1640
|
+
|
|
1641
|
+
The Projects folder is the ``Framework-Projects-Dir`` header, percent-encoded
|
|
1642
|
+
UTF-8, or None when the server doesn't send it.
|
|
1643
|
+
"""
|
|
1620
1644
|
server = cloud_server(url).url
|
|
1621
1645
|
inform(f"Fetching this project's definition from {server} (what is shared: {server}/privacy)")
|
|
1622
|
-
|
|
1646
|
+
response = _request("/api/v1/projects/pull", key, server)
|
|
1647
|
+
envelope = response.json()
|
|
1623
1648
|
if not isinstance(envelope, dict):
|
|
1624
1649
|
raise CloudError("The server returned an unexpected project definition.")
|
|
1625
|
-
return envelope, server
|
|
1650
|
+
return envelope, server, header_projects_dir(response.headers.get("Framework-Projects-Dir"))
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
def header_projects_dir(value: str | None) -> str | None:
|
|
1654
|
+
"""A Framework-Projects-Dir header value, decoded, or None when absent or blank."""
|
|
1655
|
+
if not value:
|
|
1656
|
+
return None
|
|
1657
|
+
decoded = unquote(value, encoding="utf-8", errors="replace").strip()
|
|
1658
|
+
return decoded or None
|
framework/create.py
CHANGED
|
@@ -648,6 +648,38 @@ def catalog_layer(type: str) -> dict[str, Any]:
|
|
|
648
648
|
return _defaults_layer(catalog, type) if isinstance(catalog, dict) else {}
|
|
649
649
|
|
|
650
650
|
|
|
651
|
+
# App project types: Framework Cloud blueprints, so they need a login. In Python,
|
|
652
|
+
# shiny is Shiny for Python.
|
|
653
|
+
APP_TYPES = {
|
|
654
|
+
"shiny": "framework/shiny_python",
|
|
655
|
+
"shiny_python": "framework/shiny_python",
|
|
656
|
+
"fastapi": "framework/fastapi",
|
|
657
|
+
}
|
|
658
|
+
# R's app types, with the Python type to use instead.
|
|
659
|
+
R_APP_TYPES = {"plumber": ("Plumber", "fastapi")}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
def _invalid_type() -> FrameworkError:
|
|
663
|
+
return FrameworkError(
|
|
664
|
+
f"Invalid project type. Must be one of: {', '.join(TYPES)}, "
|
|
665
|
+
f"or, with Framework Cloud, {', '.join(APP_TYPES)}"
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
def _app_blueprint(type: str) -> str:
|
|
670
|
+
"""The blueprint for an app type. It needs a Framework Cloud login, checked first."""
|
|
671
|
+
from framework.cloud import CloudError, cloud_server, cloud_token, host, login_hint
|
|
672
|
+
|
|
673
|
+
blueprint = APP_TYPES[type]
|
|
674
|
+
server = cloud_server().url
|
|
675
|
+
if cloud_token(server) is None:
|
|
676
|
+
raise CloudError(
|
|
677
|
+
f'type="{type}" builds the Framework Cloud blueprint {blueprint}. '
|
|
678
|
+
f"No cloud token found for {host(server)}. {login_hint(server)}"
|
|
679
|
+
)
|
|
680
|
+
return blueprint
|
|
681
|
+
|
|
682
|
+
|
|
651
683
|
def new_project(
|
|
652
684
|
name: str | None = None,
|
|
653
685
|
location: str | Path | None = None,
|
|
@@ -672,8 +704,20 @@ def new_project(
|
|
|
672
704
|
|
|
673
705
|
Args:
|
|
674
706
|
name: Project name. Asked for when interactive.
|
|
675
|
-
location: The project folder to create.
|
|
676
|
-
|
|
707
|
+
location: The project folder to create. ``~`` is expanded and a relative path is
|
|
708
|
+
taken from the current directory. With no location, an interactive session
|
|
709
|
+
shows ``<current directory>/<project-name>`` and asks
|
|
710
|
+
``Create the project here (<path>)? [y/n]``. With a Projects folder set in
|
|
711
|
+
Framework Cloud Settings, it offers ``<Projects folder>/<project-name>``
|
|
712
|
+
instead and asks ``Create the project in <path>? [y/n]``, creating the
|
|
713
|
+
Projects folder if needed. Answering n asks for the folder to put the
|
|
714
|
+
project in; leaving it blank uses the current directory. A
|
|
715
|
+
non-interactive session raises an error asking for ``location``.
|
|
716
|
+
type: project, project_sensitive, course, presentation, or bare. App types
|
|
717
|
+
``"shiny"`` (Shiny for Python; ``"shiny_python"`` is the same) and
|
|
718
|
+
``"fastapi"`` are Framework Cloud blueprints: ``type="fastapi"`` is
|
|
719
|
+
``blueprint="framework/fastapi"``, and needs
|
|
720
|
+
[`cloud_login()`](ref:cloud_login). ``"plumber"`` is R only. When
|
|
677
721
|
you are logged in to Framework Cloud, every choice is resolved there:
|
|
678
722
|
a type is its system blueprint (``framework/<type>``), and with no
|
|
679
723
|
choices at all the project starts from your defaults. When not logged
|
|
@@ -734,6 +778,14 @@ def new_project(
|
|
|
734
778
|
cloud_choices = blueprint is not None or structure is not None
|
|
735
779
|
if cloud_choices and type is not None:
|
|
736
780
|
raise FrameworkError("Pass type, or blueprint and structure, not both")
|
|
781
|
+
if type in R_APP_TYPES:
|
|
782
|
+
label, instead = R_APP_TYPES[type]
|
|
783
|
+
raise FrameworkError(
|
|
784
|
+
f'{label} is an R project type. For a Python API, use type="{instead}".'
|
|
785
|
+
)
|
|
786
|
+
if type in APP_TYPES:
|
|
787
|
+
# Exactly blueprint="framework/<app>"
|
|
788
|
+
blueprint, type, cloud_choices = _app_blueprint(type), None, True
|
|
737
789
|
if not cloud_choices:
|
|
738
790
|
needs_cloud = [
|
|
739
791
|
name
|
|
@@ -756,11 +808,144 @@ def new_project(
|
|
|
756
808
|
name = input("Project name: ").strip()
|
|
757
809
|
if not name:
|
|
758
810
|
raise FrameworkError("Project name cannot be empty")
|
|
811
|
+
location = _project_location(location, kebab_case(name), interactive)
|
|
812
|
+
root = _new_build(
|
|
813
|
+
name,
|
|
814
|
+
location,
|
|
815
|
+
type,
|
|
816
|
+
workflow,
|
|
817
|
+
tools,
|
|
818
|
+
package_sets,
|
|
819
|
+
skill_sets,
|
|
820
|
+
blueprint,
|
|
821
|
+
structure,
|
|
822
|
+
skills,
|
|
823
|
+
sensitive,
|
|
824
|
+
ai,
|
|
825
|
+
git,
|
|
826
|
+
interactive,
|
|
827
|
+
offline,
|
|
828
|
+
cloud_choices,
|
|
829
|
+
)
|
|
830
|
+
inform(f"Project ready at {root}")
|
|
831
|
+
return root
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def _readline(prompt: str) -> str:
|
|
835
|
+
"""Read an answer from the user. A seam for tests."""
|
|
836
|
+
return input(prompt)
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
def _abs_location(location: str | Path) -> Path:
|
|
840
|
+
"""A location as an absolute path: ``~`` expanded, a relative path taken from here."""
|
|
841
|
+
path = Path(str(location).strip()).expanduser()
|
|
842
|
+
return path if path.is_absolute() else Path.cwd() / path
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
def _projects_dir() -> str | None:
|
|
846
|
+
"""The Projects folder set in Framework Cloud Settings, or None when unset.
|
|
847
|
+
|
|
848
|
+
It is ``defaults.projects_dir`` in the person's settings document. Signed in,
|
|
849
|
+
it comes from the cloud, or from the mirror ``cloud_sync()`` keeps when the
|
|
850
|
+
cloud can't be reached. Signed out, it comes from the mirror alone.
|
|
851
|
+
"""
|
|
852
|
+
from framework.cloud import _sync_paths, api, cloud_server, cloud_token
|
|
853
|
+
|
|
854
|
+
def from_document(document: Any) -> str | None:
|
|
855
|
+
defaults = document.get("defaults") if isinstance(document, dict) else None
|
|
856
|
+
value = defaults.get("projects_dir") if isinstance(defaults, dict) else None
|
|
857
|
+
return value.strip() if isinstance(value, str) and value.strip() else None
|
|
858
|
+
|
|
859
|
+
try:
|
|
860
|
+
server = cloud_server().url
|
|
861
|
+
token = cloud_token(server)
|
|
862
|
+
except FrameworkError:
|
|
863
|
+
token = None
|
|
864
|
+
if token:
|
|
865
|
+
try:
|
|
866
|
+
response = api("/api/v1/settings", token, server)
|
|
867
|
+
except FrameworkError:
|
|
868
|
+
response = None
|
|
869
|
+
if isinstance(response, dict) and "document" in response:
|
|
870
|
+
return from_document(response["document"])
|
|
871
|
+
|
|
872
|
+
mirror = _sync_paths()[0]
|
|
873
|
+
if not mirror.is_file():
|
|
874
|
+
return None
|
|
875
|
+
try:
|
|
876
|
+
return from_document(_yaml.read(mirror))
|
|
877
|
+
except Exception: # an unreadable mirror counts as unset
|
|
878
|
+
return None
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def _ask_location(slug: str, interactive: bool, projects_dir: str | None = None) -> Path:
|
|
882
|
+
"""Where a new project goes when no location was given, as in R.
|
|
883
|
+
|
|
884
|
+
An interactive session confirms a folder named for the project in the
|
|
885
|
+
Projects folder (``projects_dir``, else the one in Framework Cloud Settings),
|
|
886
|
+
or in the current directory when neither is set, or takes the folder to put
|
|
887
|
+
it in. There is never a
|
|
888
|
+
default elsewhere: the location is always explicit.
|
|
889
|
+
"""
|
|
890
|
+
here = Path.cwd()
|
|
891
|
+
suggested = here / slug
|
|
892
|
+
if not interactive:
|
|
893
|
+
raise FrameworkError(
|
|
894
|
+
"No project location given. Pass `location=`, the folder to create, "
|
|
895
|
+
f'such as location="{suggested}".'
|
|
896
|
+
)
|
|
897
|
+
projects_dir = projects_dir or _projects_dir()
|
|
898
|
+
if projects_dir is None:
|
|
899
|
+
question = f"Create the project here ({suggested})? [y/n] "
|
|
900
|
+
else:
|
|
901
|
+
suggested = _abs_location(projects_dir) / slug
|
|
902
|
+
question = f"Create the project in {suggested}? [y/n] "
|
|
903
|
+
while True:
|
|
904
|
+
answer = _readline(question).strip().lower()
|
|
905
|
+
if answer in ("", "y", "yes"):
|
|
906
|
+
return suggested
|
|
907
|
+
if answer in ("n", "no"):
|
|
908
|
+
break
|
|
909
|
+
inform("Answer y or n.")
|
|
910
|
+
typed = _readline(
|
|
911
|
+
f"Where should the project go? Leave blank to use the current directory ({here}): "
|
|
912
|
+
).strip()
|
|
913
|
+
parent = _abs_location(typed) if typed else here
|
|
914
|
+
# A typed path that already names the project folder is used as is
|
|
915
|
+
return parent if parent.name == slug else parent / slug
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
def _project_location(
|
|
919
|
+
location: str | Path | None, slug: str, interactive: bool, projects_dir: str | None = None
|
|
920
|
+
) -> Path:
|
|
921
|
+
"""The absolute project folder, asked for when not given, announced before creation."""
|
|
759
922
|
if location is None:
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
923
|
+
root = _ask_location(slug, interactive, projects_dir)
|
|
924
|
+
else:
|
|
925
|
+
root = _abs_location(location)
|
|
926
|
+
inform(f"Creating the project at {root}")
|
|
927
|
+
return root
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
def _new_build(
|
|
931
|
+
name: str,
|
|
932
|
+
location: Path,
|
|
933
|
+
type: str | None,
|
|
934
|
+
workflow: str | None,
|
|
935
|
+
tools: Mapping[str, bool] | Sequence[str] | None,
|
|
936
|
+
package_sets: Sequence[str],
|
|
937
|
+
skill_sets: Sequence[str],
|
|
938
|
+
blueprint: str | None,
|
|
939
|
+
structure: str | None,
|
|
940
|
+
skills: Sequence[str],
|
|
941
|
+
sensitive: bool | None,
|
|
942
|
+
ai: bool | Mapping[str, Any] | None,
|
|
943
|
+
git: bool | None,
|
|
944
|
+
interactive: bool,
|
|
945
|
+
offline: bool,
|
|
946
|
+
cloud_choices: bool,
|
|
947
|
+
) -> Path:
|
|
948
|
+
"""Build the project at its resolved location: from the cloud, or locally."""
|
|
764
949
|
|
|
765
950
|
def local(register: bool = True) -> Path:
|
|
766
951
|
return _new_local(
|
|
@@ -789,7 +974,7 @@ def new_project(
|
|
|
789
974
|
return local()
|
|
790
975
|
# Logged in: the cloud resolves every choice. A Framework type is its system blueprint.
|
|
791
976
|
if type is not None and type not in TYPES:
|
|
792
|
-
raise
|
|
977
|
+
raise _invalid_type()
|
|
793
978
|
body = _choices_body(
|
|
794
979
|
name,
|
|
795
980
|
f"framework/{type}" if type else None,
|
|
@@ -825,7 +1010,7 @@ def _new_local(
|
|
|
825
1010
|
else:
|
|
826
1011
|
type = "project"
|
|
827
1012
|
if type not in TYPES:
|
|
828
|
-
raise
|
|
1013
|
+
raise _invalid_type()
|
|
829
1014
|
|
|
830
1015
|
from framework.features import definition_layers, workflow_layers
|
|
831
1016
|
|
|
@@ -1045,16 +1230,15 @@ def _replace_default_skills(spec: dict[str, Any], type: str, layers: Sequence[An
|
|
|
1045
1230
|
def _new_from_cloud(
|
|
1046
1231
|
key: str, location: str | Path | None, interactive: bool, url: str | None = None
|
|
1047
1232
|
) -> Path:
|
|
1048
|
-
from framework.cloud import
|
|
1233
|
+
from framework.cloud import pull_project, write_project_token
|
|
1049
1234
|
|
|
1050
|
-
envelope, server =
|
|
1235
|
+
envelope, server, owner_projects_dir = pull_project(key, url)
|
|
1051
1236
|
name = envelope.get("name")
|
|
1052
1237
|
if not name:
|
|
1053
1238
|
raise FrameworkError("The cloud project has no name")
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
location = answer or suggested
|
|
1239
|
+
location = _project_location(
|
|
1240
|
+
location, _envelope_slug(envelope, str(name)), interactive, owner_projects_dir
|
|
1241
|
+
)
|
|
1058
1242
|
resolved = spec_resolve(envelope.get("layers") or [], str(name), envelope.get("author"))
|
|
1059
1243
|
spec = resolved.spec
|
|
1060
1244
|
spec["source"] = envelope.get("source") or {"origin": "cloud"}
|
|
@@ -1065,6 +1249,16 @@ def _new_from_cloud(
|
|
|
1065
1249
|
return root
|
|
1066
1250
|
|
|
1067
1251
|
|
|
1252
|
+
def _envelope_slug(envelope: Mapping[str, Any], name: str) -> str:
|
|
1253
|
+
"""The cloud project's slug, the key of its project layer, or one made from its name."""
|
|
1254
|
+
for entry in reversed(envelope.get("layers") or []):
|
|
1255
|
+
if isinstance(entry, dict) and entry.get("kind") == "project":
|
|
1256
|
+
key = entry.get("key")
|
|
1257
|
+
if isinstance(key, str) and key:
|
|
1258
|
+
return key
|
|
1259
|
+
return kebab_case(name)
|
|
1260
|
+
|
|
1261
|
+
|
|
1068
1262
|
def project_add_directory(project_path: str | Path, key: str, label: str, path: str) -> Path:
|
|
1069
1263
|
"""Create a folder in a project and record it under ``extra_directories``.
|
|
1070
1264
|
|