Skip to content

Commit cdaacdb

Browse files
authored
260 remove pyprojecttoml (#261)
* remove pyproject * Makefile and correcting books * Makefile and correcting books
1 parent 20ce2c7 commit cdaacdb

File tree

10 files changed

+151
-912
lines changed

10 files changed

+151
-912
lines changed

.github/workflows/book.yml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,55 @@ jobs:
2121
marimo:
2222
runs-on: ubuntu-latest
2323
steps:
24-
# Set up the Python virtual environment with all required dependencies
25-
# This uses a reusable action from the cradle repository
26-
- name: "Build the virtual environment for ${{ github.repository }}"
27-
uses: tschm/cradle/actions/[email protected]
24+
# Check out the repository code
25+
- name: Checkout [${{ github.repository }}]
26+
uses: actions/checkout@v4
2827

29-
# Find all Experiment*.py files in the book/marimo directory and export them to HTML
30-
# This creates static HTML versions of the interactive notebooks
31-
- name: "Export notebooks"
32-
uses: tschm/cradle/actions/marimo@main
28+
- name: Install the latest version of uv and set the python version
29+
uses: astral-sh/setup-uv@v6
3330
with:
34-
command: 'export html-wasm "$file" -o "artifacts/marimo/${filename}/index.html" --mode edit'
35-
# run: |
36-
# uv run pip install --no-cache-dir marimo
37-
#
38-
# # Find all Python files in book/marimo directory
39-
# for notebook in book/marimo/Experiment*.py; do
40-
# # Extract the filename without extension
41-
# # echo "Detected notebook $notebook"
42-
# filename=$(basename "$notebook" .py)
43-
# echo "Detected filename $filename"
44-
# # Create output
45-
# folder=artifacts/notebooks/$filename
46-
#
47-
# mkdir -p $folder
48-
# echo "Folder $folder"
49-
# # Export as readonly, with code locked
50-
# uv run marimo export html-wasm $notebook -o $folder/index.html
51-
# echo "Exported $notebook to $folder"
52-
# done
53-
# ls -all artifacts/notebooks
54-
#
55-
# # Upload the generated HTML files as a GitHub Actions artifact
56-
# # This makes the files available for the deployment job
57-
# - name: Upload HTML artifacts
58-
# uses: actions/upload-artifact@v4
59-
# with:
60-
# name: notebooks
61-
# path: artifacts/notebooks
62-
# retention-days: 1 # Keep artifacts for 1 day to save storage
31+
python-version: 3.13
32+
33+
# Convert all Marimo notebooks to HTML-WASM format
34+
# The WASM format allows for interactive elements to work in the browser
35+
- name: Convert notebooks to HTML-WASM
36+
run: |
37+
# uv run pip install --no-cache-dir marimo
38+
mkdir -p artifacts/marimo
39+
40+
# Find all Python files in the notebooks directory and export them to HTML-WASM
41+
for notebook in notebooks/*.py; do
42+
# Extract the filename without extension
43+
filename=$(basename "$notebook" .py)
44+
echo "Exporting $notebook to HTML-WASM..."
45+
46+
# Create output directory for this notebook
47+
mkdir -p artifacts/marimo/$filename
48+
49+
# Export in edit mode to allow users to modify the notebook
50+
uvx marimo export html-wasm $notebook -o artifacts/marimo/$filename/index.html --sandbox --mode edit
51+
done
52+
53+
# List all exported notebooks
54+
echo "Exported notebooks:"
55+
ls -la artifacts/marimo/
56+
57+
# Upload the generated HTML-WASM files as a GitHub Actions artifact
58+
# This makes the files available for the deployment job
59+
- name: Upload HTML artifacts
60+
# Note: This conditional is commented out but would skip upload when running locally with act
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: marimo
64+
path: artifacts/marimo
65+
retention-days: 1 # Keep artifacts for 1 day to save storage
6366

6467
# Job to build the Jupyter Book documentation
6568
# This converts Jupyter notebooks to a static website with navigation
6669
jupyter:
6770
runs-on: "ubuntu-latest"
6871
steps:
69-
# Set up the Python virtual environment with all required dependencies
70-
# This uses a reusable action from the cradle repository
71-
- name: "Build the virtual environment for ${{ github.repository }}"
72-
uses: tschm/cradle/actions/[email protected]
72+
7373

7474
# Build the Jupyter Book using a reusable action
7575
# This action handles the book building process including configuration

.github/workflows/marimo.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ jobs:
1717
notebooks: ${{ steps.set-notebooks.outputs.notebooks }}
1818

1919
steps:
20-
- name: "Build the virtual environment for ${{ github.repository }}"
21-
uses: tschm/cradle/actions/[email protected]
20+
# Check out the repository code
21+
- name: Checkout [${{ github.repository }}]
22+
uses: actions/checkout@v4
2223

2324
- name: List notebooks
2425
id: set-notebooks
2526
run: |
26-
cd book/marimo
2727
# Get all .py files, excluding directories
2828
NOTEBOOKS=$(ls -p | grep -v / | grep '\.py$' | jq -R -s -c 'split("\n") | map(select(length > 0))')
2929
echo "notebooks=$NOTEBOOKS" >> $GITHUB_OUTPUT
3030
echo "Found notebooks: $NOTEBOOKS"
31+
working-directory: book/marimo
3132

3233
run-notebook:
3334
name: Run ${{ matrix.notebook }}
@@ -38,14 +39,19 @@ jobs:
3839
matrix:
3940
notebook: ${{ fromJson(needs.list-notebooks.outputs.notebooks) }}
4041

41-
steps:
42-
- name: "Build the virtual environment for ${{ github.repository }}"
43-
uses: tschm/cradle/actions/[email protected]
42+
steps: # Check out the repository code
43+
- name: Checkout [${{ github.repository }}]
44+
uses: actions/checkout@v4
45+
46+
- name: Install the latest version of uv and set the python version
47+
uses: astral-sh/setup-uv@v6
48+
with:
49+
python-version: 3.13
4450

4551
- name: Run notebook
4652
run: |
47-
uv pip install --no-cache-dir marimo
48-
49-
cd book/marimo
50-
echo "Processing ${{ matrix.notebook }}"
51-
uv run python "${{ matrix.notebook }}"
53+
uvx marimo run "${{ matrix.notebook }}" --sandbox --no-browser &
54+
pid=$!
55+
sleep 1
56+
kill $pid
57+
working-directory: book/marimo

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
.DEFAULT_GOAL := help
66

77
# Define all phony targets (targets that don't create files with the same name)
8-
.PHONY: venv install fmt clean help test marimo lint
8+
.PHONY: venv fmt clean help test marimo lint
99

1010
# Create a virtual environment using uv with Python 3.12
1111
venv:
1212
curl -LsSf https://astral.sh/uv/install.sh | sh
1313
uv venv --python='3.12'
1414

15-
install: venv ## Install dependencies and setup environment
16-
uv pip install --upgrade pip
17-
uv sync --dev --frozen --all-extras
15+
#install: venv ## Install dependencies and setup environment
16+
# uv pip install --upgrade pip
17+
# uv sync --dev --frozen --all-extras
1818

1919
fmt: venv lint ## Format and lint code
2020
uvx pre-commit install
@@ -38,5 +38,5 @@ help: ## Show this help message
3838
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
3939

4040
# Run marimo for interactive notebook development
41-
marimo: install ## Start a Marimo server
42-
@uv run marimo edit book/marimo # Start marimo server in edit mode for the book/marimo directory
41+
marimo: venv ## Start a Marimo server
42+
@uvx marimo edit --sandbox book/marimo/$(NOTEBOOK) # Start marimo server in edit mode for the book/marimo directory

book/marimo/Experiment1.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "numpy==2.3.0",
6+
# "pandas==2.3.0",
7+
# "plotly==6.1.2",
8+
# "polars==1.3.0",
9+
# "cvxsimulator==1.4.3"
10+
# ]
11+
# ///
112
import marimo
213

314
__generated_with = "0.13.15"
@@ -21,7 +32,9 @@
2132
dframe = pl.read_csv(str(path), try_parse_dates=True)
2233

2334
dframe = dframe.with_columns(pl.col(date_col).cast(pl.Datetime("ns")))
24-
dframe = dframe.with_columns([pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col])
35+
dframe = dframe.with_columns(
36+
[pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col]
37+
)
2538
prices = dframe.to_pandas().set_index(date_col).apply(interpolate)
2639

2740

@@ -104,10 +117,21 @@ def _():
104117
@app.cell
105118
def _(portfolio):
106119
fig = portfolio.snapshot()
120+
# import urllib
121+
122+
## Convert figure to HTML and encode for URL
123+
# plot_html = fig.to_html()
124+
# urllib.parse.quote(plot_html)
107125
fig
108126
return
109127

110128

129+
@app.cell
130+
def _():
131+
# Create HTML link to open in new tab
132+
return
133+
134+
111135
@app.cell
112136
def _():
113137
pd.set_option("display.precision", 2)

book/marimo/Experiment2.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "numpy==2.3.0",
6+
# "pandas==2.3.0",
7+
# "plotly==6.1.2",
8+
# "polars==1.3.0",
9+
# "cvxsimulator==1.4.3"
10+
# ]
11+
# ///
112
import marimo
213

314
__generated_with = "0.13.15"
@@ -21,7 +32,9 @@
2132
dframe = pl.read_csv(str(path), try_parse_dates=True)
2233

2334
dframe = dframe.with_columns(pl.col(date_col).cast(pl.Datetime("ns")))
24-
dframe = dframe.with_columns([pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col])
35+
dframe = dframe.with_columns(
36+
[pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col]
37+
)
2538
prices = dframe.to_pandas().set_index(date_col).apply(interpolate)
2639

2740

book/marimo/Experiment3.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "numpy==2.3.0",
6+
# "pandas==2.3.0",
7+
# "plotly==6.1.2",
8+
# "polars==1.3.0",
9+
# "cvxsimulator==1.4.3"
10+
# ]
11+
# ///
112
import marimo
213

314
__generated_with = "0.13.15"
@@ -21,7 +32,9 @@
2132
dframe = pl.read_csv(str(path), try_parse_dates=True)
2233

2334
dframe = dframe.with_columns(pl.col(date_col).cast(pl.Datetime("ns")))
24-
dframe = dframe.with_columns([pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col])
35+
dframe = dframe.with_columns(
36+
[pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col]
37+
)
2538
prices = dframe.to_pandas().set_index(date_col).apply(interpolate)
2639

2740

@@ -141,7 +154,9 @@ def _():
141154
def _(f, fast, prices, slow, vola, winsor):
142155
from cvxsimulator import Portfolio
143156

144-
pos = 1e5 * f(prices, fast=fast.value, slow=slow.value, vola=vola.value, clip=winsor.value)
157+
pos = 1e5 * f(
158+
prices, fast=fast.value, slow=slow.value, vola=vola.value, clip=winsor.value
159+
)
145160
portfolio = Portfolio.from_cashpos_prices(prices=prices, cashposition=pos, aum=1e8)
146161
print(portfolio.sharpe())
147162
return (portfolio,)

book/marimo/Experiment4.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "numpy==2.3.0",
6+
# "pandas==2.3.0",
7+
# "plotly==6.1.2",
8+
# "polars==1.3.0",
9+
# "cvxsimulator==1.4.3"
10+
# ]
11+
# ///
112
import marimo
213

314
__generated_with = "0.13.15"
@@ -21,7 +32,9 @@
2132
dframe = pl.read_csv(str(path), try_parse_dates=True)
2233

2334
dframe = dframe.with_columns(pl.col(date_col).cast(pl.Datetime("ns")))
24-
dframe = dframe.with_columns([pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col])
35+
dframe = dframe.with_columns(
36+
[pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col]
37+
)
2538
prices = dframe.to_pandas().set_index(date_col).apply(interpolate)
2639

2740

book/marimo/Experiment5.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "numpy==2.3.0",
6+
# "pandas==2.3.0",
7+
# "plotly==6.1.2",
8+
# "polars==1.3.0",
9+
# "cvxsimulator==1.4.3"
10+
# ]
11+
# ///
112
import marimo
213

314
__generated_with = "0.13.15"
@@ -21,7 +32,9 @@
2132
dframe = pl.read_csv(str(path), try_parse_dates=True)
2233

2334
dframe = dframe.with_columns(pl.col(date_col).cast(pl.Datetime("ns")))
24-
dframe = dframe.with_columns([pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col])
35+
dframe = dframe.with_columns(
36+
[pl.col(col).cast(pl.Float64) for col in dframe.columns if col != date_col]
37+
)
2538
prices = dframe.to_pandas().set_index(date_col).apply(interpolate)
2639

2740

@@ -92,7 +105,9 @@ def _(
92105

93106
for n, (t, state) in enumerate(builder):
94107
mask = state.mask
95-
matrix = shrink2id(cor.loc[t[-1]].values, lamb=shrinkage.value)[mask, :][:, mask]
108+
matrix = shrink2id(cor.loc[t[-1]].values, lamb=shrinkage.value)[mask, :][
109+
:, mask
110+
]
96111
expected_mu = np.nan_to_num(mu[n][mask])
97112
expected_vo = np.nan_to_num(vo[n][mask])
98113
risk_position = solve(matrix, expected_mu) / inv_a_norm(expected_mu, matrix)

0 commit comments

Comments
 (0)