Skip to content
Merged
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
54 changes: 54 additions & 0 deletions .fz/calculators/Model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Model calculator script (mock implementation)
# Compatible with fz framework
#
# This is a template script that demonstrates the structure of a calculator.
# Replace this with actual calls to your simulation code.

# if directory as input, cd into it
if [ -d "$1" ]; then
cd "$1"
# Find the first input file (not .out or .msg)
input=$(ls | grep -v '\.out$' | grep -v '\.msg$' | grep -v '\.sh$' | head -n 1)
if [ -z "$input" ]; then
echo "No input file found in directory. Exiting."
exit 1
fi
shift
# if $1 is a file, use it
elif [ -f "$1" ]; then
input="$1"
shift
else
echo "Usage: $0 <input_file or input_directory>"
exit 2
fi

PID_FILE=$PWD/PID
echo $$ >> $PID_FILE

# Mock calculation: extract the value from the input file and write to output
# This simulates a real calculation that produces an output file
# Replace this section with actual calls to your simulation code

echo "Running mock calculation on $input..."

# Extract variable value from input (looking for "value = X" pattern)
value=$(grep -E '^value\s*=' "$input" | sed 's/.*=\s*//' | tr -d '[:space:]')

if [ -n "$value" ]; then
# Mock computation: just return the value (or compute something from it)
result=$value
echo "Input value: $value"
echo "Result: $result"
echo "$result" > output.txt
echo "Calculation completed successfully."
else
echo "Warning: No value found in input file"
echo "" > output.txt
fi

if [ -f "$PID_FILE" ]; then
rm -f "$PID_FILE"
fi
6 changes: 6 additions & 0 deletions .fz/calculators/localhost_Model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uri": "sh://",
"models": {
"Model": "bash .fz/calculators/Model.sh"
}
}
10 changes: 10 additions & 0 deletions .fz/models/Model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "Model",
"varprefix": "$",
"formulaprefix": "@",
"delim": "{}",
"commentline": "#",
"output": {
"result": "cat output.txt 2>/dev/null || echo ''"
}
}
122 changes: 122 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
test:
name: Test Plugin Structure
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install fz framework
run: |
pip install git+https://github.com/Funz/fz.git

- name: Validate JSON files
run: |
echo "Validating model files..."
for f in .fz/models/*.json; do
echo " Checking $f"
python -m json.tool "$f" > /dev/null
done
echo "Validating calculator config files..."
for f in .fz/calculators/*.json; do
echo " Checking $f"
python -m json.tool "$f" > /dev/null
done

- name: Check shell script syntax
run: |
echo "Checking shell scripts..."
for f in .fz/calculators/*.sh; do
echo " Checking $f"
bash -n "$f"
done

- name: Test fzi (parse variables)
run: |
python -c "
import fz
variables = fz.fzi('examples/Model/input.txt', 'Model')
print(f'Variables found: {list(variables.keys())}')
assert 'x' in variables, 'Variable x not found'
print('✓ fzi test passed')
"

- name: Test fzc (compile input)
run: |
python -c "
import fz
import tempfile
import os
with tempfile.TemporaryDirectory() as tmpdir:
fz.fzc('examples/Model/input.txt', {'x': 3.14}, 'Model', output_dir=tmpdir)
compiled = os.path.join(tmpdir, 'x=3.14', 'input.txt')
assert os.path.exists(compiled), 'Compiled file not created'
with open(compiled) as f:
content = f.read()
assert '3.14' in content, 'Variable not substituted'
print('✓ fzc test passed')
"

- name: Run plugin tests
run: |
python tests/test_plugin.py

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check shell scripts are executable
run: |
for f in .fz/calculators/*.sh; do
if [ ! -x "$f" ]; then
echo "Error: $f is not executable"
exit 1
fi
done

docs:
name: Check Documentation
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check required documentation files
run: |
for f in README.md LICENSE; do
if [ ! -f "$f" ]; then
echo "Error: Missing $f"
exit 1
fi
echo "✓ $f exists"
done

- name: Check example files
run: |
if [ ! -f "examples/Model/input.txt" ]; then
echo "Error: Missing example input file"
exit 1
fi
echo "✓ Example files present"
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Results and temporary files
results/
*.out
*.msg
*.html
PID

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
ENV/
.venv

# fz temporary files
.fz/tmp/

# OS
.DS_Store
Thumbs.db
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2025, Funz Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading