Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 47 additions & 75 deletions .github/workflows/python-examples.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,69 @@
# .github/workflows/verify_examples.yml
#
# CI for python/examples/01-03 select_values scripts.
# Strategy: download the daily HallD SQLite snapshot so the examples
# run against real data with a proper schema.

name: Python examples verification

on:
push:
branches:
- '*'
branches: ['*']
pull_request:
branches:
- main
branches: [main]

env:
# Single source of truth for the connection string
RCDB_CONNECTION: "sqlite:///${{ github.workspace }}/tmp/rcdb2.sqlite"

jobs:
run-examples:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
# Don't fail the entire job if one example fails
fail-fast: false

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
python-version: "3.9"

- name: Install dependencies
- name: Install rcdb
run: |
python -m pip install --upgrade pip
# Install rcdb and dependencies from pyproject.toml
cd $GITHUB_WORKSPACE/python
pip install --editable .
# Install additional dependencies for examples
pip install jsonpickle
pip install jsonpickle # for writing object example

- name: Setup SQLite for testing
run: |
mkdir -p $GITHUB_WORKSPACE/tmp
touch $GITHUB_WORKSPACE/tmp/test.sqlite.db
echo "RCDB_CONNECTION=sqlite:///$GITHUB_WORKSPACE/tmp/test.sqlite.db" >> $GITHUB_ENV
# - name: Download HallD SQLite snapshot
# run: |
# mkdir -p $GITHUB_WORKSPACE/tmp
# # Future put db creation here

- name: Create database service (MySQL)
if: false # Disabled until we have a proper way to initialize the MySQL database
run: |
# This would be the place to set up an actual MySQL database if needed
# For now, we'll use SQLite for examples that accept a connection string parameter
echo "RCDB_MYSQL_CONNECTION=sqlite:///$GITHUB_WORKSPACE/tmp/test.sqlite.db" >> $GITHUB_ENV

- name: List example files
id: list-examples
run: |
cd $GITHUB_WORKSPACE/python/examples
echo "examples=$(ls -1 example_*.py | tr '\n' ' ')" >> $GITHUB_OUTPUT
# ── Run examples ──────────────────────────────────────────────
# Each example gets its own step so failures are visible per-script.
# continue-on-error keeps the workflow green while showing which
# script had problems (yellow badge instead of silent swallow).

- name: Run basic examples (with in-memory or SQLite DB)
run: |
cd $GITHUB_WORKSPACE/python/examples
echo "Running example_conditions_basic.py"
python example_conditions_basic.py

echo "Running example_conditions_store_array.py"
python example_conditions_store_array.py

echo "Running example_conditions_store_object.py"
python example_conditions_store_object.py

echo "Running example_sqlalchemy_query.py"
python example_sqlalchemy_query.py

echo "Running example_runs_by_date.py (with connection string)"
python example_runs_by_date.py $RCDB_CONNECTION || echo "Skipping - requires properly initialized database"

- name: Run query examples (with offline mode)
run: |
cd $GITHUB_WORKSPACE/python/examples
echo "Running example_simple_queries.py"
python example_simple_queries.py $RCDB_CONNECTION || echo "Skipping - requires properly initialized database"

# The following examples normally use the production database
# We'll try them with the test db, but expect some to fail gracefully
export RCDB_OFFLINE=true
echo "Running examples in offline mode (will show errors but not fail workflow)"

echo "Trying example_cdc_gas_pressure.py"
python example_cdc_gas_pressure.py || echo "Skipping - requires production database"

echo "Trying example_select_halld_values.py"
python example_select_halld_values.py || echo "Skipping - requires production database"

echo "Trying example_select_values.py"
python example_select_values.py || echo "Skipping - requires production database"

- name: Summary
run: |
echo "Examples testing completed. Check logs for any failures."
echo "Note: Some examples are expected to fail if they require a production database connection."
- name: "Example: 01_select_values_simple"
run: python $GITHUB_WORKSPACE/python/examples/01_select_values_simple.py
# Script must read RCDB_CONNECTION env var (see updated examples)

- name: "Example: 02_select_values_extended"
run: python $GITHUB_WORKSPACE/python/examples/02_select_values_extended.py

- name: "Example: 03_select_values_custom_runs"
run: python $GITHUB_WORKSPACE/python/examples/03_select_values_custom_runs.py

- name: "Example: 10_create_conditions_basic"
run: python $GITHUB_WORKSPACE/python/examples/10_create_conditions_basic.py

- name: "Example: 11_crete_conditions_store_array"
run: python $GITHUB_WORKSPACE/python/examples/11_crete_conditions_store_array.py

- name: "Example: 12_create_conditions_store_object"
run: python $GITHUB_WORKSPACE/python/examples/12_create_conditions_store_object.py

- name: "Example: 90_advanced_sqlalchemy_query"
run: python $GITHUB_WORKSPACE/python/examples/90_advanced_sqlalchemy_query.py
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ sql/schema.mwb.bak
reqvenv/

python/repomix-output.txt

python/uv.lock
3 changes: 3 additions & 0 deletions docs/development/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Here is a python one-liner that makes the site running at `localhost:3000`
```bash
# assuming current working directoy is rcdb/docs
python3 -m http.server 3000

# Using uv from rcdb repository root
uv --project ./python --directory docs run -m http.server 3000
```

> On windows machines you may have to use `python` instead of `python3`
Expand Down
12 changes: 0 additions & 12 deletions python/examples/example_cdc_gas_pressure.py

This file was deleted.

93 changes: 0 additions & 93 deletions python/examples/example_runs_by_date.py

This file was deleted.

5 changes: 0 additions & 5 deletions python/examples/example_select_halld_values.py

This file was deleted.

37 changes: 0 additions & 37 deletions python/examples/example_simple_queries.py

This file was deleted.

4 changes: 4 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ dependencies = [
"rich"
]

[project.optional-dependencies]
examples = ["jsonpickle"]


# If you want a console script, define it in [project.scripts]
[project.scripts]
rcdb = "rcdb.cli.app:rcdb_cli"
Expand Down
1 change: 1 addition & 0 deletions python/rcdb/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PASSWORD = 'default'
SQL_CONNECTION_STRING = "mysql+pymysql://rcdb@127.0.0.1/rcdb"


# Get the current directory
current_directory = os.path.dirname(os.path.abspath(__file__))
template_folder=os.path.join(current_directory, 'templates')
Expand Down
3 changes: 3 additions & 0 deletions python/rcdb/web/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from rcdb.web import app

app.run(host="0.0.0.0", port=8080, debug=False)