Docker basado en un sh en vez de en compose

This commit is contained in:
Álvaro González 2026-01-28 11:04:33 +01:00
parent 57becb5577
commit 28671888e1
10 changed files with 109 additions and 20 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.flutter-plugins-dependencies
.dart_tool/
.dart-tool/
.dartServer/
@ -12,7 +13,7 @@
.zcompdump
.zshrc
.idea
/d4rt-formulas.iml
/build/
/d4rt_formulas.iml
.aider*
.build-container-cache

View file

@ -1,22 +1,20 @@
flutter-container-exec = podman-compose run --entrypoint "$(1)" flutter
all: clean-podman build-linux-debug-podman build-linux-debug-podman
build-podman:
podman-compose build
./docker-exec.sh build
clean-podman: build-podman
$(call flutter-container-exec, flutter clean)
./docker-exec.sh exec flutter clean
pub-get-podman: build-podman
$(call flutter-container-exec, flutter pub get)
./docker-exec.sh exec flutter pub get
build-android-release-podman: pub-get-podman
$(call flutter-container-exec, flutter build apk --release)
./docker-exec.sh exec flutter build apk --release
build-linux-debug-podman: pub-get-podman
$(call flutter-container-exec, flutter build linux --debug)
./docker-exec.sh exec flutter build linux --debug
run-linux-debug: build-linux-debug-podman
build/linux/x64/debug/bundle/d4rt_formulas

View file

@ -1,2 +0,0 @@
aider --git --watch-files --read CLAUDE.md --notifications --no-auto-commits

View file

@ -149,4 +149,28 @@ Where:
""",
"tags": ["medical", "pediatrics", "assessment"]
}
,
{
"name": "Compare price per mass",
"description": "Compares two products by their price per mass and returns which is cheaper.",
"input": [
{"name": "price1", "unit": "scalar"},
{"name": "mass1", "unit": "kilogram"},
{"name": "price2", "unit": "scalar"},
{"name": "mass2", "unit": "kilogram"}
],
"output": {"name": "Result", "unit": "scalar"},
"d4rtCode": """
var p1 = price1 / mass1;
var p2 = price2 / mass2;
if (p1 < p2) {
Result = 'first product is cheaper';
} else if (p2 < p1) {
Result = 'second product is cheaper';
} else {
Result = 'both products have the same price per mass';
}
""",
"tags": ["comparison", "shopping", "economics"]
}
]

40
docker-exec.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
set -e
DOCKER=podman
build_image(){
$DOCKER build -t d4rt-formulas-builder -f Dockerfile .
}
exec_in_container(){
local XOPTIONS="--env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --security-opt=label=disable"
local WOPTIONS="--env=XDG_RUNTIME_DIR=/run/user/$(id -u) --volume=/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland --group-add=video"
local SPIOPTIONS="--env AT_SPI_BUS=/run/user/$(id -u)/at-spi/bus_0 --volume=/run/user/$(id -u)/at-spi:/run/user/$(id -u)/at-spi --device=/dev/dri"
$DOCKER run \
--rm \
$XOPTIONS \
$SPIOPTIONS \
-v ./.build-container-cache:/cache:z \
-v .:/app:z \
-e FLUTTER_FLAVOR=prod \
d4rt-formulas-builder \
"$@"
}
if [ "$1" = "build" ]; then
build_image
exit $?
fi
if [ "$1" = "exec" ]; then
exec_in_container ${@:2}
exit $?
fi
echo "Usage: $0 {build|exec <command>}"
exit 1

View file

@ -27,6 +27,9 @@ class D4rtEditingController extends TextEditingController {
bool validate() {
try {
_lastValue = null;
if( text.trim().isEmpty ){
return true;
}
_lastValue = FormulaEvaluator.evaluateExpression(text);
_lastError = null;
return true;
@ -141,7 +144,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
// Convert output to selected unit if needed
String? unit = widget.formula.output.unit;
if (unit != null) {
if (unit != null && unit is Number) {
final converted = widget.corpus.convert(result, unit, _selectedOutputUnit!);
if (converted is num) {
_result = converted.toStringAsFixed(2);

View file

@ -35,7 +35,7 @@ class Corpus{
if( checkUnits ){
for( final inputVar in formula.input + [formula.output] ){
if( inputVar.unit != null && !_allUnits.containsKey(inputVar.unit) ){
throw ArgumentError( "Unit not found: ${inputVar.unit}");
throw ArgumentError( "Unit not found in formula ${formula.name}: ${inputVar.unit}");
}
}
}

View file

@ -168,14 +168,39 @@ class FormulaEvaluator {
""");
}
}
// Build a Map<String, List<String>> named `variableValues` that exposes allowed values
// for each VariableSpec (inputs and output) to the interpreted code. Values are
// converted to strings and quoted in the produced d4rt source.
final variableValuesMap = <String, List<String>>{};
// Include input VariableSpecs when they have allowed values
for (final vs in formula.input) {
final values = vs.values;
if (values != null && values.isNotEmpty) {
variableValuesMap[vs.name] = values.map((v) => v.toString()).toList(growable: false);
}
}
// Explicitly include the output VariableSpec if it has allowed values
final outValues = formula.output.values;
if (outValues != null && outValues.isNotEmpty) {
variableValuesMap[formula.output.name] = outValues.map((v) => v.toString()).toList(growable: false);
}
// Write the variableValues map into the generated source without escaping names/values
buffer.writeln("final variableValues = {");
variableValuesMap.forEach((name, list) {
final listLiteral = list.map((s) => '"' + s + '"').join(', ');
buffer.writeln(' "' + name + '": [' + listLiteral + '],');
});
buffer.writeln('};');
buffer.writeln("""
late var ${formula.output.name};
${formula.d4rtCode}
return ${formula.output.name};
}
"""
);
""");
return buffer.toString();
}
}
}

View file

@ -702,5 +702,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.10.7 <4.0.0"
dart: ">=3.10.4 <4.0.0"
flutter: ">=3.38.0"

View file

@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ^3.10.7
sdk: ^3.10.4
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions