From 06519d6d2b64de000643257fcbde0914460455e1 Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Wed, 2 Oct 2024 12:28:26 +0200
Subject: [PATCH] Validated instructions to install package

---
 README.md               | 30 ++++++++++++++++++++----------
 conda-recipe/publish.py | 27 +++++++++++++++++++--------
 requirements.yml        |  2 +-
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md
index 4770aa9a..2acdf5e3 100644
--- a/README.md
+++ b/README.md
@@ -8,19 +8,29 @@ model_server is a service for on-demand computer vision, adapted specifically to
 and other life sciences applications.  It abstracts image data access, persists machine learning models, 
 and exposes an extensible API to facilitate low-latency analysis.  
 
-## Installation from source:
+## Install Git and miniforge
+1. Install Miniforge for environment management:<br>https://github.com/conda-forge/miniforge/releases
+2. Under the Start menu, open `Miniforge3 > Miniforge Prompt`
 
+## Option 1: install model_server as a package:
+1. Download the most recent version of the built package from:<br>https://git.embl.de/rhodes/model_server/-/packages/1280
+2. (optional) activate the target conda environment: `mamba activate <target_environment>`
+3. From the package repository https://git.embl.de/rhodes/model_server/-/packages/ download:
+   - The most recent requirements.yml
+   - The most recent .tar.bz2 file containing the built conda package
+4. In a text editor, open requirements.yml and remove all but the "channels" and "dependencies" blocks, then save.
+5. Change directories to the location of 'requirements.yml' and install dependencies:<br>`mamba env update -f requirements.yml`
+6. Download the most recent .tar.bz2 file containing the built conda package from:<br>https://git.embl.de/rhodes/model_server/-/packages/1283
+7. Change directories to the downloaded file and install model_server package: `mamba install model_server-<version>-py_0.tar.bz2`
+
+## Option 2: install model_server from source:
 1. Install Git:<br>https://git-scm.com/download/win
-2. Install Miniforge for environment management:<br>https://github.com/conda-forge/miniforge/releases
-3. Under the Start menu, open `Miniforge3 > Miniforge Prompt`
-4. In the new terminal, clone the model_server repository:<br>
-   `cd %userprofile%`<br>
-   `git clone https://almf-staff:KJmFvyPRbpzoVZDqfMzV@git.embl.de/rhodes/model_server.git`
-5. Create the environment: `mamba env create --file requirements.yml --name model_server_env`
-6. Activate the environment: `mamba activate model_server_env`
-7. Add the project source as a Python package: `pip install --no-deps -e .`
+2. In the new terminal, clone the model_server repository:<br>`cd %userprofile%`<br>`git clone https://almf-staff:KJmFvyPRbpzoVZDqfMzV@git.embl.de/rhodes/model_server.git`
+3. Create the target environment: `mamba env create --file requirements.yml --name model_server_env`
+4. Activate the target environment: `mamba activate model_server_env`
+5. Add the project source as a Python package: `pip install --no-deps -e .`
 
 ## To start the server:
-1. From the Miniforge prompt, run `mamba activate model_server_env`
+1. From the Miniforge prompt, run `mamba activate <target_environment>`
 2. Then run `python -m scripts.run_server --port 6221`
 3. A browser window should appear, with basic status information.
diff --git a/conda-recipe/publish.py b/conda-recipe/publish.py
index f0d7110e..071d9a5f 100644
--- a/conda-recipe/publish.py
+++ b/conda-recipe/publish.py
@@ -21,20 +21,31 @@ with open(root / 'channeldata.json', 'r') as fh:
     chdata = json.load(fh)
 
 # upload to GitLab API
-res = []
+res = {}
 for sd in ['noarch', 'win-64']:
     with open(root / sd / 'repodata.json', 'r') as fh:
         dd = json.load(fh)
+    pkgname = f'conda_{sd}'
+
+    if len(dd['packages']) == 0:
+        continue
+
+    # put each .tar.bz2
     for fn in dd['packages'].keys():
         ver = dd['packages'][fn]['version']
         stem = fn.split('.tar.bz2')[0]
-        pkgname = f'conda_{sd}'
-        res.append(
-            requests.put(
-                f'https://git.embl.de/api/v4/projects/{id}/packages/generic/{pkgname}/{ver}/{fn}?status=default',
-                files={'file': open(root / sd / fn, 'rb')},
-                headers={'PRIVATE-TOKEN': pwd},
-            )
+        res[(sd, fn)] = requests.put(
+            f'https://git.embl.de/api/v4/projects/{id}/packages/generic/{pkgname}/{ver}/{fn}?status=default',
+            files={'file': open(root / sd / fn, 'rb')},
+            headers={'PRIVATE-TOKEN': pwd},
         )
+
+    # put requirements.yml
+    fn = 'requirements.yml'
+    res[(sd, fn)] = requests.put(
+        f'https://git.embl.de/api/v4/projects/{id}/packages/generic/{pkgname}/{ver}/{fn}?status=default',
+        files={'file': open(root.parent / fn, 'r')},
+        headers={'PRIVATE-TOKEN': pwd, 'Content-Type': 'text/html'},
+    )
 print('Finished')
 print(res)
\ No newline at end of file
diff --git a/requirements.yml b/requirements.yml
index 0953d353..fa5b53ab 100644
--- a/requirements.yml
+++ b/requirements.yml
@@ -1,4 +1,4 @@
-name: model_server_mqtt
+name: model_server
 channels:
   - pytorch
   - ilastik-forge
-- 
GitLab