cycls 0.0.2.95__py3-none-any.whl → 0.0.2.97__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.
- cycls/__init__.py +3 -11
- cycls/app.py +4 -3
- cycls/function.py +18 -5
- cycls/themes/default/assets/{index-CTZe1T7l.js → index-CfWQV7zw.js} +21 -21
- cycls/themes/default/index.html +1 -1
- {cycls-0.0.2.95.dist-info → cycls-0.0.2.97.dist-info}/METADATA +1 -1
- cycls-0.0.2.97.dist-info/RECORD +15 -0
- cycls-0.0.2.95.dist-info/RECORD +0 -15
- {cycls-0.0.2.95.dist-info → cycls-0.0.2.97.dist-info}/WHEEL +0 -0
- {cycls-0.0.2.95.dist-info → cycls-0.0.2.97.dist-info}/entry_points.txt +0 -0
cycls/__init__.py
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
from . import function as _function_module
|
|
2
1
|
from .function import function, Function
|
|
3
2
|
from .app import app, App
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
raise AttributeError(f"module 'cycls' has no attribute '{name}'")
|
|
9
|
-
|
|
10
|
-
def __setattr__(name, value):
|
|
11
|
-
if name in ("api_key", "base_url"):
|
|
12
|
-
setattr(_function_module, name, value)
|
|
13
|
-
else:
|
|
14
|
-
raise AttributeError(f"module 'cycls' has no attribute '{name}'")
|
|
4
|
+
# Module-level config
|
|
5
|
+
api_key = None
|
|
6
|
+
base_url = None
|
cycls/app.py
CHANGED
|
@@ -15,13 +15,14 @@ class App(Function):
|
|
|
15
15
|
|
|
16
16
|
def __init__(self, func, name, theme="default", pip=None, apt=None, copy=None, copy_public=None,
|
|
17
17
|
auth=False, org=None, header=None, intro=None, title=None, plan="free", analytics=False,
|
|
18
|
-
state=False):
|
|
18
|
+
state=False, memory="1Gi"):
|
|
19
19
|
if theme not in THEMES:
|
|
20
20
|
raise ValueError(f"Unknown theme: {theme}. Available: {THEMES}")
|
|
21
21
|
self.user_func = func
|
|
22
22
|
self.theme = theme
|
|
23
23
|
self.copy_public = copy_public or []
|
|
24
24
|
self.state = state
|
|
25
|
+
self.memory = memory
|
|
25
26
|
|
|
26
27
|
self.config = Config(
|
|
27
28
|
header=header,
|
|
@@ -79,12 +80,12 @@ class App(Function):
|
|
|
79
80
|
self._prepare_func(prod=True)
|
|
80
81
|
return super().deploy(port=port)
|
|
81
82
|
|
|
82
|
-
def _deploy(self, port=8080):
|
|
83
|
+
def _deploy(self, port=8080, memory=None):
|
|
83
84
|
"""Deploy to testing infrastructure."""
|
|
84
85
|
if self.api_key is None:
|
|
85
86
|
raise RuntimeError("Missing API key. Set cycls.api_key or CYCLS_API_KEY environment variable.")
|
|
86
87
|
self._prepare_func(prod=True)
|
|
87
|
-
return super()._deploy(port=port)
|
|
88
|
+
return super()._deploy(port=port, memory=memory or self.memory)
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
def app(name=None, **kwargs):
|
cycls/function.py
CHANGED
|
@@ -46,10 +46,14 @@ api_key = None
|
|
|
46
46
|
base_url = None
|
|
47
47
|
|
|
48
48
|
def _get_api_key():
|
|
49
|
-
|
|
49
|
+
import sys
|
|
50
|
+
cycls_pkg = sys.modules.get('cycls')
|
|
51
|
+
return api_key or (cycls_pkg and cycls_pkg.__dict__.get('api_key')) or os.getenv("CYCLS_API_KEY")
|
|
50
52
|
|
|
51
53
|
def _get_base_url():
|
|
52
|
-
|
|
54
|
+
import sys
|
|
55
|
+
cycls_pkg = sys.modules.get('cycls')
|
|
56
|
+
return base_url or (cycls_pkg and cycls_pkg.__dict__.get('base_url')) or os.getenv("CYCLS_BASE_URL")
|
|
53
57
|
|
|
54
58
|
def _hash_path(path_str: str) -> str:
|
|
55
59
|
h = hashlib.sha256()
|
|
@@ -91,8 +95,8 @@ class Function:
|
|
|
91
95
|
self.apt = sorted(apt or [])
|
|
92
96
|
self.run_commands = sorted(run_commands or [])
|
|
93
97
|
self.copy = {f: f for f in copy} if isinstance(copy, list) else (copy or {})
|
|
94
|
-
self.
|
|
95
|
-
self.
|
|
98
|
+
self._base_url = base_url
|
|
99
|
+
self._api_key = api_key
|
|
96
100
|
self.pip = sorted(set(pip or []) | {"cloudpickle"})
|
|
97
101
|
|
|
98
102
|
self.image_prefix = f"cycls/{self.name}"
|
|
@@ -100,6 +104,14 @@ class Function:
|
|
|
100
104
|
self._docker_client = None
|
|
101
105
|
self._container = None
|
|
102
106
|
|
|
107
|
+
@property
|
|
108
|
+
def api_key(self):
|
|
109
|
+
return self._api_key or _get_api_key()
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def base_url(self):
|
|
113
|
+
return self._base_url or _get_base_url() or "https://service-core-280879789566.me-central1.run.app"
|
|
114
|
+
|
|
103
115
|
@property
|
|
104
116
|
def docker_client(self):
|
|
105
117
|
if self._docker_client is None:
|
|
@@ -401,6 +413,7 @@ CMD ["python", "entrypoint.py"]
|
|
|
401
413
|
|
|
402
414
|
base_url = self.base_url
|
|
403
415
|
port = kwargs.pop('port', 8080)
|
|
416
|
+
memory = kwargs.pop('memory', '1Gi')
|
|
404
417
|
|
|
405
418
|
# Check name availability before uploading
|
|
406
419
|
print(f"Checking '{self.name}'...")
|
|
@@ -442,7 +455,7 @@ CMD ["python", "entrypoint.py"]
|
|
|
442
455
|
with open(archive_path, 'rb') as f:
|
|
443
456
|
response = requests.post(
|
|
444
457
|
f"{base_url}/v1/deploy",
|
|
445
|
-
data={"function_name": self.name, "port": port},
|
|
458
|
+
data={"function_name": self.name, "port": port, "memory": memory},
|
|
446
459
|
files={'source_archive': (archive_name, f, 'application/gzip')},
|
|
447
460
|
headers={"X-API-Key": self.api_key},
|
|
448
461
|
timeout=9000,
|