-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Distributive-Network/feature/initial-bifrost2
Draft: Feature/initial bifrost2
- Loading branch information
Showing
37 changed files
with
1,944 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Hello World Workflow | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
hello-world-job: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Print Hi using Python | ||
run: python3 -c 'print("Hi")' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
### Distributive Specific Gitignore rules | ||
*.swp | ||
*node_modules* | ||
node_modules/ | ||
.eslintcache | ||
|
||
### GitHub Standard Python Gitignore below | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control | ||
.pdm.toml | ||
.pdm-python | ||
.pdm-build/ | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
# A playground for experiments | ||
# Bifrost2 - The Python SDK for [DCP](https://www.dcp.dev/) | ||
|
||
## Build | ||
|
||
Install [Poetry](https://python-poetry.org/), then in the root of the project directory run the following: | ||
- `$ poetry install` | ||
- `$ poetry shell` | ||
|
||
Verify your installation is correct by running the test suite: | ||
- `$ poetry run pytest` | ||
|
||
## Tests | ||
|
||
Run tests with: | ||
- `$ poetry run pytest` | ||
|
||
For now, please keep work to your own subdirectory. We may, or may not, organize it later. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .initialization import make_init_fn | ||
import sys | ||
|
||
init = make_init_fn(sys.modules[__name__]) | ||
|
||
# clean up namespace | ||
del sys | ||
del js | ||
del dry | ||
del api | ||
del initialization | ||
del make_init_fn | ||
|
||
__all__ = ['init'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .compute_for import compute_for_maker | ||
from .job import Job | ||
from .result_handle import ResultHandle | ||
|
||
sub_classes = { | ||
'Job': Job, | ||
'ResultHandle': ResultHandle, | ||
} | ||
|
||
__all__ = ['compute_for_maker', 'sub_classes'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pythonmonkey as pm | ||
from .. import dry | ||
from .. import js | ||
|
||
def compute_for_maker(): | ||
def compute_for(*args, **kwargs): | ||
compute_for_js = pm.eval("globalThis.dcp.compute.for") | ||
ret_val = dry.aio.blockify(compute_for_js)(*args, **kwargs) | ||
return dry.class_manager.wrap_obj(ret_val) | ||
return compute_for | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pythonmonkey as pm | ||
|
||
|
||
class Job(): | ||
#def exec(self, *args, **kwargs): | ||
# # TODO change behaviour to match spec | ||
# #print("overidden by Job hook") | ||
|
||
def wait(self, *args, **kwargs): | ||
pass | ||
|
||
def on(self, *args): | ||
if len(args) > 1 and callable(args[1]): | ||
event_name = args[0] | ||
event_cb = args[1] | ||
self.js_ref.on(event_name, event_cb) | ||
else: | ||
event_name = args[0] | ||
def decorator(fn): | ||
self.js_ref.on(event_name, fn) | ||
return decorator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ResultHandle(): | ||
def __str__(self): | ||
return str(self.values()) | ||
|
||
def __repr__(self): | ||
return self.__str__() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import class_manager | ||
from . import aio | ||
|
||
__all__ = ['class_manager', 'aio'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Manage asynchronous functions involving the PythonMonkey event loop. | ||
Functions: | ||
- asyncify(leaky_async_fn): make a leaky PM JS promise not leak. | ||
- blockify(async_fn): make a leaky PM JS promise not leak and block. | ||
Properties: | ||
- loop: the single event loop used for all PythonMonkey ev loop interactions. | ||
Author: Will Pringle <[email protected]> | ||
Date: June 2024 | ||
""" | ||
import asyncio | ||
import inspect | ||
|
||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) | ||
|
||
def asyncify(leaky_async_fn): | ||
# leaky_asyn_fn may not return a corotine but still require an event loop | ||
async def aio_fn(*args, **kwargs): | ||
return_value = leaky_async_fn(*args, **kwargs) | ||
if inspect.isawaitable(return_value): | ||
return await return_value | ||
|
||
return return_value | ||
return aio_fn | ||
|
||
|
||
def blockify(async_fn): | ||
def blocking_fn(*args, **kwargs): | ||
return loop.run_until_complete(asyncify(async_fn)(*args, **kwargs)) | ||
return blocking_fn | ||
|
Oops, something went wrong.