Skip to content

Commit d4d84c3

Browse files
committed
With file persistence in docker.
1 parent bcaf3d2 commit d4d84c3

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,5 @@ marimo/_static/
206206
marimo/_lsp/
207207
__marimo__/
208208

209-
.idea/
209+
.idea/
210+
/code/08-reproducibility/math_research/data/run-count.txt

code/08-reproducibility/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
container_name: math_research
1616
image: math_research
1717
working_dir: /app
18+
volumes:
19+
- ./math_research/data:/data
1820
ports:
1921
- "9000:9000"
2022
platform: linux/amd64

code/08-reproducibility/math_research/src/math-research.ipynb

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 7,
1615
"id": "f7f8b7ff-2950-4c93-b874-2f99d53bb669",
1716
"metadata": {
1817
"ExecuteTime": {
19-
"end_time": "2025-07-23T16:35:41.612096Z",
20-
"start_time": "2025-07-23T16:35:41.608392Z"
18+
"end_time": "2025-08-02T01:13:40.632240Z",
19+
"start_time": "2025-08-02T01:13:40.628063Z"
2120
}
2221
},
23-
"outputs": [],
2422
"source": [
2523
"# Import our math utility functions.\n",
2624
"import mathf\n",
2725
"from pathlib import Path"
28-
]
26+
],
27+
"outputs": [],
28+
"execution_count": 2
2929
},
3030
{
3131
"cell_type": "markdown",
@@ -111,23 +111,19 @@
111111
},
112112
{
113113
"cell_type": "code",
114-
"execution_count": 19,
115114
"id": "5deaf5a6",
116-
"metadata": {},
117-
"outputs": [
118-
{
119-
"name": "stdout",
120-
"output_type": "stream",
121-
"text": [
122-
"This is run 10\n"
123-
]
115+
"metadata": {
116+
"ExecuteTime": {
117+
"end_time": "2025-08-02T01:14:53.816909Z",
118+
"start_time": "2025-08-02T01:14:53.792645Z"
124119
}
125-
],
120+
},
126121
"source": [
127122
"# Let's just show that we can read/write data persistently.\n",
128123
"file = Path('/data/run-count.txt')\n",
129124
"if not file.parent.exists():\n",
130125
" file = Path('../data/run-count.txt')\n",
126+
" file.parent.mkdir(parents=True, exist_ok=True)\n",
131127
"\n",
132128
"if file.exists():\n",
133129
" with open(file, 'r', encoding='utf-8') as f:\n",
@@ -141,7 +137,30 @@
141137
" f.write(str(run_count))\n",
142138
"\n",
143139
"print(f'This is run {run_count}')"
144-
]
140+
],
141+
"outputs": [
142+
{
143+
"ename": "IsADirectoryError",
144+
"evalue": "[Errno 21] Is a directory: '../data/run-count.txt'",
145+
"output_type": "error",
146+
"traceback": [
147+
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
148+
"\u001B[31mIsADirectoryError\u001B[39m Traceback (most recent call last)",
149+
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[6]\u001B[39m\u001B[32m, line 8\u001B[39m\n\u001B[32m 5\u001B[39m file.parent.mkdir(parents=\u001B[38;5;28;01mTrue\u001B[39;00m, exist_ok=\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[32m 7\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m file.exists():\n\u001B[32m----> \u001B[39m\u001B[32m8\u001B[39m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28;43mopen\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mfile\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mr\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mencoding\u001B[49m\u001B[43m=\u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mutf-8\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m)\u001B[49m \u001B[38;5;28;01mas\u001B[39;00m f:\n\u001B[32m 9\u001B[39m run_count = \u001B[38;5;28mint\u001B[39m(f.read())\n\u001B[32m 10\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n",
150+
"\u001B[36mFile \u001B[39m\u001B[32m~/github/courses/just-enough-python-datasci/just-enough-data-sci-course/venv/lib/python3.13/site-packages/IPython/core/interactiveshell.py:343\u001B[39m, in \u001B[36m_modified_open\u001B[39m\u001B[34m(file, *args, **kwargs)\u001B[39m\n\u001B[32m 336\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m file \u001B[38;5;129;01min\u001B[39;00m {\u001B[32m0\u001B[39m, \u001B[32m1\u001B[39m, \u001B[32m2\u001B[39m}:\n\u001B[32m 337\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[32m 338\u001B[39m \u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[33mIPython won\u001B[39m\u001B[33m'\u001B[39m\u001B[33mt let you open fd=\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mfile\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m by default \u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 339\u001B[39m \u001B[33m\"\u001B[39m\u001B[33mas it is likely to crash IPython. If you know what you are doing, \u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 340\u001B[39m \u001B[33m\"\u001B[39m\u001B[33myou can use builtins\u001B[39m\u001B[33m'\u001B[39m\u001B[33m open.\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 341\u001B[39m )\n\u001B[32m--> \u001B[39m\u001B[32m343\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mio_open\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfile\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43m*\u001B[49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n",
151+
"\u001B[31mIsADirectoryError\u001B[39m: [Errno 21] Is a directory: '../data/run-count.txt'"
152+
]
153+
}
154+
],
155+
"execution_count": 6
156+
},
157+
{
158+
"metadata": {},
159+
"cell_type": "code",
160+
"outputs": [],
161+
"execution_count": null,
162+
"source": "",
163+
"id": "2e12bad509461386"
145164
}
146165
],
147166
"metadata": {

0 commit comments

Comments
 (0)