From c702f502998c065fed597afce960bf6c338d0b8e Mon Sep 17 00:00:00 2001
From: Dilawar Singh <dilawar@subcom.tech>
Date: Fri, 30 Sep 2022 19:36:15 +0530
Subject: [PATCH] fix: Accepts versioned API url

Doesn't append '/api/v1' by itself anymore.
---
 README.md         | 18 ++++++++++++++++++
 bitia/__main__.py | 19 +++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index b39e80f..7b18c6a 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,24 @@ python -m pip install bitia --user
 python -m bitia --help
 ```
 
+## Configuration
+
+TODO: Order of searching configuration file.
+
+### Unix like systems
+
+1. `./bitia.toml`
+2. `~/.bitia.toml`
+3. `$HOME/.config/bitia.toml`
+3. `/etc/bitia.toml`
+
+
+### Windows
+
+1. `bitia.toml`
+2. `%APPDATA%\bitia.toml`
+3. `%PROGRAMDATA%\bitia.toml`
+
 ## BiTIA runner
 
 If you are self-hosting the BiTIA server, you need `bitia-runner` as well. See
diff --git a/bitia/__main__.py b/bitia/__main__.py
index dbe9006..5472bff 100644
--- a/bitia/__main__.py
+++ b/bitia/__main__.py
@@ -91,7 +91,7 @@ def create_pipeline_from_single_script(script: Path) -> Path:
     # move the script to this directory.
     shutil.copy2(script, pipeline_dir)
     script_name = script.name
-    with pipeline_file.open('w', newline='\n') as outf:
+    with pipeline_file.open("w", newline="\n") as outf:
         outf.write(f"#!/bin/sh\nchmod +x ./{script_name}\n./{script_name}")
     return prepare_archive(pipeline_dir)
 
@@ -105,31 +105,30 @@ def create_pipeline_from_command(cmd: str) -> Path:
     """
     pipeline_dir = Path(tempfile.mkdtemp(prefix="bitia_"))
     pipeline_file = pipeline_dir / g_default_bitia_main_script_name
-    with pipeline_file.open('w', newline='\n') as outf:
+    with pipeline_file.open("w", newline="\n") as outf:
         outf.write(f"#!/bin/sh\n\n{cmd}")
-    logging.info("Wrote pipeline %s", pipeline_file.read_text())
+    logger.info("Wrote pipeline %s", pipeline_file.read_text())
     return prepare_archive(pipeline_dir)
 
 
-def submit_job(pipeline_zip: Path, server: str):
+def submit_job_and_stream(pipeline_zip: Path, api_url: str):
     """Submit job to the API and stream the output."""
     session = requests.Session()
     numbytes = pipeline_zip.stat().st_size
     assert numbytes > 0
     logger.info(
-        f"Submitting {pipeline_zip} (size={numbytes/1024.0:.2f} KB) to the {server}"
+        f"Submitting {pipeline_zip} (size={numbytes/1024.0:.2f} KB) to the {api_url}"
     )
     files = {"pipeline_zip": open(str(pipeline_zip), "rb")}
     response = session.post(
-        f"{server}/api/v1/submit", files=files, data=dict(filename=pipeline_zip), stream=True
+        f"{api_url}/submit", files=files, data=dict(filename=pipeline_zip), stream=True
     )
     for line in response.iter_lines():
         print(line.decode())
 
 
 @app.command("run")
-@app.command("submit")
-def run_pipeline(user_input: str, server: str = "https://public.bitia.link"):
+def run_pipeline(user_input: str, server: str = "https://public.bitia.link/api/v1"):
     """Submit your pipelin (url, directory, zip_file).
 
     Prepare the user directory to send to the server. User can also provide link
@@ -150,8 +149,8 @@ def run_pipeline(user_input: str, server: str = "https://public.bitia.link"):
     else:
         # generate a temporary pipeline and submit.
         pipeline_zip = create_pipeline_from_command(user_input)
-        logging.info(f"Created pipeline in {pipeline_zip}")
-    submit_job(pipeline_zip, server)
+        logger.info(f"Created pipeline in {pipeline_zip}")
+    submit_job_and_stream(pipeline_zip, server)
 
 
 @app.command()
-- 
GitLab