Skip to content

Commit

Permalink
Merge branch 'dev' into feature-chat
Browse files Browse the repository at this point in the history
  • Loading branch information
ramedina86 committed Feb 15, 2024
2 parents 3e8c9bc + 1126aad commit 11c326d
Show file tree
Hide file tree
Showing 57 changed files with 3,100 additions and 202 deletions.
13 changes: 13 additions & 0 deletions .alfred.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[alfred]
# name = "" # name of a subproject, use the name of the directory if not set
# description = "" # inline documentation for a sub project
# subprojects = []

# [alfred.project]
# command = [ "alfred/*.py" ]
# python_path_project_root = true
# python_path_extends = []
# venv = "src/.."

# more info about project manifest
# into https://alfred-cli.readthedocs.io/en/latest/project.html#setting-up-a-project-with-alfred-toml
37 changes: 37 additions & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci-macos

on: [ push, pull_request ]

jobs:
build:
runs-on: macos-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: update package manager & install python3 environment
run: |
sudo pip install poetry
poetry install --with build
- name: install npm environment
run: |
cd ui
npm install
- name: run continuous integration pipeline
run: |
poetry run alfred ci
37 changes: 37 additions & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci-windows

on: [ push, pull_request ]

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: update package manager & install python3 environment
run: |
pip install poetry
poetry install --with build
- name: install npm environment
run: |
cd ui
npm install
- name: run continuous integration pipeline
run: |
poetry run alfred ci
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ci

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: update package manager & install python3 environment
run: |
sudo pip install poetry
poetry install --with build
- name: install npm environment
run: |
cd ui
npm install
- name: run continuous integration pipeline
run: |
poetry run alfred ci
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Pull requests should be done on the `dev` branch. When the release is finalised,
## Setting up a development environment

Whether you're interested in contributing to the repository, creating a fork, or just improving your understanding of Streamsync, these are the suggested steps for setting up a development environment.
- Install streamsync[test] or streamsync[build].
- You can install the package in editable mode using `pip install -e .`, which will make it more convenient if you intend to tweak the backend.
- You can install the package in editable mode using `poetry install --with build`, which will make it more convenient if you intend to tweak the backend.
- Enable the virtual environment with `poetry shell`
- Run streamsync in port 5000. For example, `streamsync edit hello --port 5000`.
- Install dependencies and run `npm run dev` in `/ui`. This runs the frontend for Streamsync in development mode while proxying requests to port 5000.
- A breakdown of the steps required for packaging can be found in `./build.sh`. Notably, it includes compiling the frontend and taking it from `/ui` and into the Python package.
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## What is Streamsync?

[![PyPi](https://img.shields.io/pypi/v/streamsync.svg?label=Version)](https://pypi.org/project/streamsync/)
[![CI](https://github.com/streamsync-cloud/streamsync/actions/workflows/ci.yml/badge.svg)](https://github.com/streamsync-cloud/streamsync/actions/workflows/ci.yml)
[![Discord](https://img.shields.io/badge/discord-streamsync-sn677E3Pd3?logo=discord&logoColor=white)](https://discord.gg/sn677E3Pd3)
[![License](https://img.shields.io/pypi/l/streamsync)](LICENSE)

Streamsync is an open-source framework for creating data apps. Build user interfaces using a visual editor; write the backend code in Python.

![Streamsync Builder screenshot](https://raw.githubusercontent.com/streamsync-cloud/streamsync/master/docs/docs/public/sc1.png "Streamsync Builder screenshot")
Expand Down
33 changes: 33 additions & 0 deletions alfred/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os.path
import shutil

import alfred


@alfred.command("build", help="build apps package for pypi")
@alfred.option("--ignore-ci", is_flag=True, help="ignore continuous integration pipeline")
def build(ignore_ci: bool = False):
if not ignore_ci:
alfred.invoke_command("ci")
else:
alfred.invoke_command("npm.build")

alfred.invoke_command("build.app_provisionning")
alfred.invoke_command("build.poetry")

@alfred.command("build.app_provisionning", help="update app templates using ./apps", hidden=True)
def build_app_provisionning():
if os.path.isdir('src/streamsync/app_templates'):
shutil.rmtree('src/streamsync/app_templates')

shutil.copytree( 'apps/default', 'src/streamsync/app_templates/default')
shutil.copytree( 'apps/hello', 'src/streamsync/app_templates/hello')

@alfred.command("build.poetry", help="build python packages with poetry", hidden=True)
def build_poetry():
removed_directories = ['dist', 'build']
for directory in removed_directories:
if os.path.isdir(directory):
shutil.rmtree(directory)

alfred.run("poetry build")
21 changes: 21 additions & 0 deletions alfred/ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

import alfred


@alfred.command("ci", help="continuous integration pipeline")
def ci():
alfred.invoke_command("ci.mypy")
alfred.invoke_command("ci.pytest")
alfred.invoke_command("npm.build")


@alfred.command("ci.mypy", help="typing checking with mypy on ./src/streamsync")
def ci_mypy():
alfred.run("mypy ./src/streamsync --exclude app_templates/*")


@alfred.command("ci.pytest", help="run pytest on ./tests")
def ci_test():
os.chdir("tests")
alfred.run("pytest")
12 changes: 12 additions & 0 deletions alfred/npm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import alfred
import os

@alfred.command("npm.build", help="build ui code")
def npm_build():
os.chdir("ui")
alfred.run("npm run build")

@alfred.command("npm.build_custom_components", help="build custom components")
def ui_build_custom():
os.chdir("ui")
alfred.run("npm run custom.build")
113 changes: 113 additions & 0 deletions apps/quickstart/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import streamsync as ss
import plotly.graph_objects as go
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_blobs

COLOR = {
0: '#3c64fa',
1: '#00eba8',
2: '#5a677c',
3: '#ff8866',
4: '#d4b2f7',
5: '#c3e6ff',
6: '#045758',
7: '#001435',
8: '#ec3d10',
9: '#38006a'
}

def _line(x0, coef, intercept, c):
return (-(x0 * coef[c, 0]) - intercept[c]) / coef[c, 1]

def update(state):
cluster_std = state['cluster_std']
multi_class = state['multi_class']
number_of_points = int(state['number_of_points'])
number_of_groups = int(state['number_of_groups'])
X, y = make_blobs(
n_samples=number_of_points,
n_features=2,
cluster_std=cluster_std,
centers=number_of_groups
)

clf = LogisticRegression(
solver="sag",
max_iter=1000,
random_state=42,
multi_class=multi_class
).fit(X, y)

coef = clf.coef_
intercept = clf.intercept_
score = clf.score(X, y)

state["message"] = "training score : %.3f (%s)" % (score, multi_class)

data = []
for i in range(number_of_groups):
data.append(
go.Scatter(
x=X[y == i][:, 0],
y=X[y==i][:, 1],
mode='markers',
name='Group '+str(i),
hoverinfo='none',
marker=dict(
color=COLOR[i],
symbol='circle',
size=10
)
)
)

for i in range(1 if number_of_groups < 3 else number_of_groups):
data.append(go.Scatter(
x=[-20, 20],
y=[
_line(-20, coef, intercept, i),
_line(20, coef, intercept, i)
],
mode='lines',
line=dict(color=COLOR[i], width=2),
name='Logistic Regression'
))

layout = go.Layout(
width=700,height=700,
hovermode='closest', hoverdistance=1,
xaxis=dict(
title='Feature 1',
range=[-20,20],
fixedrange=True,
constrain="domain",
scaleanchor="y",
scaleratio=1
),
yaxis=dict(
title='Feature 2',
range=[-20,20],
fixedrange=True,
constrain="domain"
),
paper_bgcolor='#FFFFFF',
margin=dict(l=30, r=30, t=30, b=30),
)

fig = go.Figure(data=data, layout=layout)
state['figure'] = fig


initial_state = ss.init_state({
"my_app": {
"title": "Logistic regression visualizer"
},
"message": None,
"figure": None,
"multi_class": "ovr",
"number_of_groups": 2,
"number_of_points": 50,
"cluster_std": 2,
})

update(initial_state)
1 change: 1 addition & 0 deletions apps/quickstart/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scikit-learn==1.4.0
13 changes: 13 additions & 0 deletions apps/quickstart/static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Serving static files

You can use this folder to store files which will be served statically in the "/static" route.

This is useful to store images and other files which will be served directly to the user of your application.

For example, if you store an image named "myimage.jpg" in this folder, it'll be accessible as "static/myimage.jpg".
You can use this relative route as the source in an Image component.

# Favicon

The favicon is served from this folder. Feel free to change it. Keep in mind that web browsers cache favicons differently
than other resources. Hence, the favicon change might not reflect immediately.
Binary file added apps/quickstart/static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 11c326d

Please sign in to comment.