kernel 0.1.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.
- kernel-0.1.0/.gitignore +187 -0
- kernel-0.1.0/.python-version +1 -0
- kernel-0.1.0/PKG-INFO +6 -0
- kernel-0.1.0/README.md +0 -0
- kernel-0.1.0/pyproject.toml +14 -0
- kernel-0.1.0/src/kernel/__init__.py +100 -0
- kernel-0.1.0/src/kernel/py.typed +0 -0
kernel-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
|
2
|
+
|
|
3
|
+
# Logs
|
|
4
|
+
|
|
5
|
+
logs
|
|
6
|
+
_.log
|
|
7
|
+
npm-debug.log_
|
|
8
|
+
yarn-debug.log*
|
|
9
|
+
yarn-error.log*
|
|
10
|
+
lerna-debug.log*
|
|
11
|
+
.pnpm-debug.log*
|
|
12
|
+
|
|
13
|
+
# Caches
|
|
14
|
+
|
|
15
|
+
.cache
|
|
16
|
+
|
|
17
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
18
|
+
|
|
19
|
+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|
20
|
+
|
|
21
|
+
# Runtime data
|
|
22
|
+
|
|
23
|
+
pids
|
|
24
|
+
_.pid
|
|
25
|
+
_.seed
|
|
26
|
+
*.pid.lock
|
|
27
|
+
|
|
28
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
29
|
+
|
|
30
|
+
lib-cov
|
|
31
|
+
|
|
32
|
+
# Coverage directory used by tools like istanbul
|
|
33
|
+
|
|
34
|
+
coverage
|
|
35
|
+
*.lcov
|
|
36
|
+
|
|
37
|
+
# nyc test coverage
|
|
38
|
+
|
|
39
|
+
.nyc_output
|
|
40
|
+
|
|
41
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
42
|
+
|
|
43
|
+
.grunt
|
|
44
|
+
|
|
45
|
+
# Bower dependency directory (https://bower.io/)
|
|
46
|
+
|
|
47
|
+
bower_components
|
|
48
|
+
|
|
49
|
+
# node-waf configuration
|
|
50
|
+
|
|
51
|
+
.lock-wscript
|
|
52
|
+
|
|
53
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
54
|
+
|
|
55
|
+
build/Release
|
|
56
|
+
|
|
57
|
+
# Dependency directories
|
|
58
|
+
|
|
59
|
+
node_modules/
|
|
60
|
+
jspm_packages/
|
|
61
|
+
|
|
62
|
+
# Snowpack dependency directory (https://snowpack.dev/)
|
|
63
|
+
|
|
64
|
+
web_modules/
|
|
65
|
+
|
|
66
|
+
# TypeScript cache
|
|
67
|
+
|
|
68
|
+
*.tsbuildinfo
|
|
69
|
+
|
|
70
|
+
# Optional npm cache directory
|
|
71
|
+
|
|
72
|
+
.npm
|
|
73
|
+
|
|
74
|
+
# Optional eslint cache
|
|
75
|
+
|
|
76
|
+
.eslintcache
|
|
77
|
+
|
|
78
|
+
# Optional stylelint cache
|
|
79
|
+
|
|
80
|
+
.stylelintcache
|
|
81
|
+
|
|
82
|
+
# Microbundle cache
|
|
83
|
+
|
|
84
|
+
.rpt2_cache/
|
|
85
|
+
.rts2_cache_cjs/
|
|
86
|
+
.rts2_cache_es/
|
|
87
|
+
.rts2_cache_umd/
|
|
88
|
+
|
|
89
|
+
# Optional REPL history
|
|
90
|
+
|
|
91
|
+
.node_repl_history
|
|
92
|
+
|
|
93
|
+
# Output of 'npm pack'
|
|
94
|
+
|
|
95
|
+
*.tgz
|
|
96
|
+
|
|
97
|
+
# Yarn Integrity file
|
|
98
|
+
|
|
99
|
+
.yarn-integrity
|
|
100
|
+
|
|
101
|
+
# dotenv environment variable files
|
|
102
|
+
|
|
103
|
+
.env
|
|
104
|
+
.env.development.local
|
|
105
|
+
.env.test.local
|
|
106
|
+
.env.production.local
|
|
107
|
+
.env.local
|
|
108
|
+
|
|
109
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
110
|
+
|
|
111
|
+
.parcel-cache
|
|
112
|
+
|
|
113
|
+
# Next.js build output
|
|
114
|
+
|
|
115
|
+
.next
|
|
116
|
+
out
|
|
117
|
+
|
|
118
|
+
# Nuxt.js build / generate output
|
|
119
|
+
|
|
120
|
+
.nuxt
|
|
121
|
+
dist
|
|
122
|
+
|
|
123
|
+
# Gatsby files
|
|
124
|
+
|
|
125
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
126
|
+
|
|
127
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
128
|
+
|
|
129
|
+
# public
|
|
130
|
+
|
|
131
|
+
# vuepress build output
|
|
132
|
+
|
|
133
|
+
.vuepress/dist
|
|
134
|
+
|
|
135
|
+
# vuepress v2.x temp and cache directory
|
|
136
|
+
|
|
137
|
+
.temp
|
|
138
|
+
|
|
139
|
+
# Docusaurus cache and generated files
|
|
140
|
+
|
|
141
|
+
.docusaurus
|
|
142
|
+
|
|
143
|
+
# Serverless directories
|
|
144
|
+
|
|
145
|
+
.serverless/
|
|
146
|
+
|
|
147
|
+
# FuseBox cache
|
|
148
|
+
|
|
149
|
+
.fusebox/
|
|
150
|
+
|
|
151
|
+
# DynamoDB Local files
|
|
152
|
+
|
|
153
|
+
.dynamodb/
|
|
154
|
+
|
|
155
|
+
# TernJS port file
|
|
156
|
+
|
|
157
|
+
.tern-port
|
|
158
|
+
|
|
159
|
+
# Stores VSCode versions used for testing VSCode extensions
|
|
160
|
+
|
|
161
|
+
.vscode-test
|
|
162
|
+
|
|
163
|
+
# yarn v2
|
|
164
|
+
|
|
165
|
+
.yarn/cache
|
|
166
|
+
.yarn/unplugged
|
|
167
|
+
.yarn/build-state.yml
|
|
168
|
+
.yarn/install-state.gz
|
|
169
|
+
.pnp.*
|
|
170
|
+
|
|
171
|
+
# IntelliJ based IDEs
|
|
172
|
+
.idea
|
|
173
|
+
|
|
174
|
+
# Finder (MacOS) folder config
|
|
175
|
+
.DS_Store
|
|
176
|
+
|
|
177
|
+
# sst
|
|
178
|
+
.sst
|
|
179
|
+
sst-env.d.ts
|
|
180
|
+
TODO
|
|
181
|
+
.env.sst
|
|
182
|
+
|
|
183
|
+
# tmp
|
|
184
|
+
infra/tests/*
|
|
185
|
+
|
|
186
|
+
.env.test
|
|
187
|
+
.npmrc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
kernel-0.1.0/PKG-INFO
ADDED
kernel-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kernel"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Rafael Garcia", email = "rgarcia2009@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from typing import Callable, Dict, Any, TypeVar, Optional, List
|
|
2
|
+
import functools
|
|
3
|
+
|
|
4
|
+
class Request:
|
|
5
|
+
def __init__(self, query: Optional[Dict[str, str]] = None, body: Any = None):
|
|
6
|
+
self.query = query or {}
|
|
7
|
+
self.body = body
|
|
8
|
+
|
|
9
|
+
T = TypeVar('T')
|
|
10
|
+
BrowserFunc = Callable[..., T]
|
|
11
|
+
|
|
12
|
+
# Registry for storing Kernel functions
|
|
13
|
+
class KernelRegistryItem:
|
|
14
|
+
def __init__(self, name: str, type: str, handler: Callable, uses_browser: bool = False, **kwargs):
|
|
15
|
+
self.name = name
|
|
16
|
+
self.type = type
|
|
17
|
+
self.handler = handler
|
|
18
|
+
for key, value in kwargs.items():
|
|
19
|
+
setattr(self, key, value)
|
|
20
|
+
|
|
21
|
+
class KernelRegistry:
|
|
22
|
+
def __init__(self):
|
|
23
|
+
self.registry: Dict[str, KernelRegistryItem] = {}
|
|
24
|
+
|
|
25
|
+
def register(self, item: KernelRegistryItem) -> None:
|
|
26
|
+
self.registry[item.name] = item
|
|
27
|
+
|
|
28
|
+
def get_all(self) -> List[KernelRegistryItem]:
|
|
29
|
+
return list(self.registry.values())
|
|
30
|
+
|
|
31
|
+
def get_by_name(self, name: str) -> Optional[KernelRegistryItem]:
|
|
32
|
+
return self.registry.get(name)
|
|
33
|
+
|
|
34
|
+
def get_by_type(self, type: str) -> List[KernelRegistryItem]:
|
|
35
|
+
return [item for item in self.get_all() if item.type == type]
|
|
36
|
+
|
|
37
|
+
# Create a singleton registry
|
|
38
|
+
registry = KernelRegistry()
|
|
39
|
+
|
|
40
|
+
def func(f: Callable) -> Callable:
|
|
41
|
+
"""Decorator to mark a function as deployable"""
|
|
42
|
+
@functools.wraps(f)
|
|
43
|
+
def wrapper(*args, **kwargs):
|
|
44
|
+
return f(*args, **kwargs)
|
|
45
|
+
registry.register(KernelRegistryItem(
|
|
46
|
+
name=f.__name__,
|
|
47
|
+
type='function',
|
|
48
|
+
handler=f,
|
|
49
|
+
))
|
|
50
|
+
|
|
51
|
+
return wrapper
|
|
52
|
+
|
|
53
|
+
def endpoint(method: str, path: str) -> Callable[[Callable], Callable]:
|
|
54
|
+
"""Decorator to mark a function as an HTTP endpoint"""
|
|
55
|
+
def decorator(f: Callable) -> Callable:
|
|
56
|
+
@functools.wraps(f)
|
|
57
|
+
def wrapper(*args, **kwargs):
|
|
58
|
+
return f(*args, **kwargs)
|
|
59
|
+
registry.register(KernelRegistryItem(
|
|
60
|
+
name=f.__name__,
|
|
61
|
+
type='http',
|
|
62
|
+
handler=f,
|
|
63
|
+
path=path,
|
|
64
|
+
method=method
|
|
65
|
+
))
|
|
66
|
+
|
|
67
|
+
return wrapper
|
|
68
|
+
return decorator
|
|
69
|
+
|
|
70
|
+
def schedule(cron_expression: str) -> Callable[[Callable], Callable]:
|
|
71
|
+
"""Decorator to mark a function as a scheduled task"""
|
|
72
|
+
def decorator(f: Callable) -> Callable:
|
|
73
|
+
@functools.wraps(f)
|
|
74
|
+
def wrapper(*args, **kwargs):
|
|
75
|
+
return f(*args, **kwargs)
|
|
76
|
+
registry.register(KernelRegistryItem(
|
|
77
|
+
name=f.__name__,
|
|
78
|
+
type='schedule',
|
|
79
|
+
handler=f,
|
|
80
|
+
cron=cron_expression
|
|
81
|
+
))
|
|
82
|
+
|
|
83
|
+
return wrapper
|
|
84
|
+
return decorator
|
|
85
|
+
|
|
86
|
+
class Browser:
|
|
87
|
+
def __init__(self):
|
|
88
|
+
self.cdp_ws_url = "ws://localhost:9222"
|
|
89
|
+
|
|
90
|
+
def use_browser(browser_fn: BrowserFunc) -> Any:
|
|
91
|
+
"""Run a function with a browser instance
|
|
92
|
+
|
|
93
|
+
The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
94
|
+
from playwright.sync_api import sync_playwright
|
|
95
|
+
|
|
96
|
+
with sync_playwright() as p:
|
|
97
|
+
browser = p.chromium.connect_over_cdp(browser.cdp_ws_url)
|
|
98
|
+
"""
|
|
99
|
+
browser = Browser()
|
|
100
|
+
return browser_fn(browser)
|
|
File without changes
|