Add support for CLI

This commit is contained in:
2026-01-09 14:06:58 +01:00
parent 7fbe57c05d
commit ee7b6cc02c
6 changed files with 37 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
import os
import click
import conmorfeusz.web as web
import conmorfeusz.concraft as ccpl
@click.command()
@click.option('--port', default=5000, help='Port on which the application will be listening to.')
@click.option('--ccpl-port', default=3000, help='Port on which internal concraft-pl server will be listening to.')
@click.option('--ccpl-model', default=None, help='Model used by concraft-pl. It will fallback to CONCRAFT_PL_MODEL envvar if not specified.')
@click.option('--ccpl-bin', default=None, help='Concraft-pl binary file. It will fallback to CONCRAFT_PL_BIN envvar if not specified.')
@click.option('--ccpl-core-num', default=1, help='Number of cores used to run Concraft-pl logic.')
@click.option('--ccpl-alloc-size', default=64, help='Allocation size for Concraft-pl.')
def run(port, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccpl_alloc_size):
"""
Glues all services together and starts the holistic app.
"""
ccpl_model = ccpl_model or os.environ.get('CONCRAFT_PL_MODEL')
ccpl_bin = ccpl_bin or os.environ.get('CONCRAFT_PL_BIN')
if ccpl_model is None:
raise Exception("Model must be specified either by --ccpl-model option or by CONCRAFT_PL_MODEL environment variable")
if ccpl_bin is None:
raise Exception("Concraft-pl binary file must be specified either by --ccpl-bin option or by CONCRAFT_PL_BIN environment variable")
concraft_cfg = (ccpl_model, ccpl_bin, ccpl_port, ccpl_core_num, ccpl_alloc_size)
with ccpl.start_server(*concraft_cfg):
web.start(port)

View File

@@ -1,14 +1,5 @@
import os from . import cli
from . import runner
def main(): def main():
exe = os.environ.get('CONCRAFT_PL_BIN') cli.run()
model = os.environ.get('CONCRAFT_PL_MODEL')
port=3000
core_num=1
allocation_size=64
concraft_cfg = (model, exe, port, core_num, allocation_size)
runner.run(concraft_cfg)

View File

@@ -1,9 +0,0 @@
import conmorfeusz.web as web
import conmorfeusz.concraft as cc
def run(concraft):
"""
Glues all services together and starts the holistic app.
"""
with cc.start_server(*concraft):
web.start()

View File

@@ -11,6 +11,6 @@ def create_app():
return app return app
def start(): def start(port):
app = create_app() app = create_app()
app.run() app.run(port=port)

View File

@@ -48,6 +48,7 @@ in
morfeusz2 morfeusz2
flask flask
requests requests
click
]; ];
nativeBuildInputs = with pythonPackages; [ nativeBuildInputs = with pythonPackages; [

View File

@@ -11,7 +11,8 @@ requires-python = "==3.6"
dependencies = [ dependencies = [
"morfeusz2==1.99.12", "morfeusz2==1.99.12",
"flask", "flask",
"requests" "requests",
"click"
] ]
[tool.setuptools.packages.find] [tool.setuptools.packages.find]