Skip to content
Snippets Groups Projects
Commit e7810cdb authored by dilawar's avatar dilawar :ant:
Browse files

feat: --versbose and --server are options

parent d13dd449
No related branches found
No related tags found
1 merge request!2version 0.2.0
Pipeline #3721 failed with stages
in 1 minute and 42 seconds
......@@ -30,9 +30,6 @@ gr runner gitlab-runner:
gitlab-runner exec docker test
gitlab-runner exec docker deploy
test_pipeline: install
$(POETRY) run bitia_runner run tests/test_20220727
release:
rm -rf dist/*.whl
bash ./.ci/realese.sh
......@@ -41,5 +38,5 @@ doc html:
cd docs && make html
.PHONY : copr fix test install lint build \
all check test_pipeline \
all check \
runner gitlab-runner image image_upload
......@@ -6,6 +6,7 @@ https://bitia.link
"""
import typing as T
import os
import functools
import bitia.helper as bhelper
......@@ -42,16 +43,14 @@ def session(func):
@app.command("create-container")
@session
def create_remote_container(
user_input: str, recreate: bool = False, server: str = bconfig.DEFAULT_SERVER
):
def create_remote_container(user_input: str, recreate: bool = False):
"""Run a pipeline"""
pipeline_zip, _ = bhelper.user_input_to_pipeline(user_input)
res = bhelper.post_pipeline_task(
pipeline_zip,
server=server,
endpoint="container/create",
params=dict(recreate="true" if recreate else "false"),
server=bconfig.server(),
stream=True,
)
res.raise_for_status()
......@@ -62,15 +61,15 @@ def create_remote_container(
@app.command("list-container")
@session
def list_remote_container(
user_input: str, server: str = bconfig.DEFAULT_SERVER
user_input: str, server: str = bconfig.g_server
) -> T.List[str]:
"""List the remote server associated with the pipeline."""
_, pipeline_hash = bhelper.user_input_to_pipeline(user_input)
logger.info(f"Finding container for {user_input}, sha256sum={pipeline_hash}")
res = bhelper.get(
endpoint="container/list",
server=bconfig.server(),
params=dict(pipeline_sha256=pipeline_hash),
server=server,
)
res.raise_for_status()
_json = res.json()
......@@ -80,14 +79,14 @@ def list_remote_container(
@app.command("logs")
@session
def stream_log(user_input: str, server: str = bconfig.DEFAULT_SERVER) -> T.List[str]:
def stream_log(user_input: str, server: str = bconfig.g_server):
"""Stream logs for the most recent run of a given pipeline."""
_, pipeline_hash = bhelper.user_input_to_pipeline(user_input)
logger.info(f"Finding container for {user_input}, sha256sum={pipeline_hash}")
res = bhelper.get(
endpoint="logs",
params=dict(pipeline_sha256=pipeline_hash),
server=server,
server=bconfig.server(),
stream=True,
)
res.raise_for_status()
......@@ -97,9 +96,7 @@ def stream_log(user_input: str, server: str = bconfig.DEFAULT_SERVER) -> T.List[
@app.command("submit")
@session
def submit_pipeline(
user_input: str, rerun: bool = False, server: str = bconfig.DEFAULT_SERVER
):
def submit_pipeline(user_input: str, rerun: bool = False):
"""Submit your pipelin (url, directory, zip_file).
Prepare the user directory to send to the server. User can also provide link
......@@ -113,13 +110,31 @@ def submit_pipeline(
@app.command("run")
@session
def run_pipeline(
user_input: str, *, rerun: bool = False, server: str = bconfig.DEFAULT_SERVER
):
def run_pipeline(user_input: str, *, rerun: bool = False):
"""Run a pipeline"""
create_remote_container(user_input, recreate=rerun, server=server)
containers = list_remote_container(user_input, server=server)
return [bhelper.log_container(container, server=server) for container in containers]
create_remote_container(user_input, recreate=rerun)
containers = list_remote_container(user_input)
return [
bhelper.log_container(container, server=bconfig.server())
for container in containers
]
@app.callback()
def main(verbose: bool = False, server: T.Optional[str] = None):
"""
Callback
"""
if verbose:
logger.info("--verbose mode enabled")
if server is not None:
bconfig.set_server(server)
elif os.environ.get("BITIA_SERVER") is not None:
bconfig.set_server(os.environ["BITIA_SERVER"])
else:
pass
logger.info(f"Using server {bconfig.server()}")
@app.command()
......
......@@ -3,7 +3,8 @@ from pathlib import Path
import tempfile
BITIA_MAIN_SCRIPT_NAME: T.Final[str] = "__main__.bitia.sh"
DEFAULT_SERVER: T.Final[str] = "https://public.bitia.link/api/v1"
g_server = "https://public.bitia.link/api/v1"
def bitia_dir() -> Path:
......@@ -11,3 +12,14 @@ def bitia_dir() -> Path:
bdir = Path(tempfile.gettempdir()) / "bitia"
bdir.mkdir(parents=True, exist_ok=True)
return bdir
def server() -> str:
"""Server to use"""
return g_server
def set_server(server: str):
"""set bitia server"""
global g_server
g_server = server
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment