Skip to content

Commit 2c7cbbf

Browse files
authored
CU-8699nbgbh Test against changes (#26)
* CU-8699nbgbh: Run tests on tutorials using changes in the PR branch * CU-8699nbgbh: Add method to change install targets of notebooks * CU-8699nbgbh: Update notebook install targets during CI to refer to PR * CU-8699nbgbh: Check out changes for preflight at CI * CU-8699nbgbh: Update notebook install patcher * CU-8699nbgbh: Patch requirements.txt alongside notebooks * CU-8699nbgbh: Rename patch script * CU-8699nbgbh: Update patch file in workflow * CU-8699nbgbh: Move install patching before installation * CU-8699nbgbh: Move CI helper script to root * CU-8699nbgbh: Update patch method to be more robust / flexible * CU-8699nbgbh: Update demo web app dependencies to PR during CI * CU-8699nbgbh: Run demo app build upon MedCAT changes * CU-8699nbgbh: Fix usage of branch in demo app workflow * CU-8699nbgbh: Fix usage of branch name in demo app workflow (try 2) * Revert "CU-8699nbgbh: Fix usage of branch name in demo app workflow (try 2)" This reverts commit f1fc582. * CU-8699nbgbh: Move install patcher * CU-8699nbgbh: Move the notebook install patcher to correct folder * CU-8699nbgbh: Only do notebooks for install patcher * CU-8699nbgbh: Remove branch from install patcher (not relevant) * CU-8699nbgbh: Fix notebook install fixer * CU-8699nbgbh: Update workflow to use correct notebook patch functionality and avoid preflight * CU-8699nbgbh: Update workflow to install branch-specific changes after requiremnets (v2 tutorials workflow) * CU-8699nbgbh: Remove usage of notebook install fixes from demo web app workflow * CU-8699nbgbh: Install medcat based on local / PR changes during demo web app workflow * CU-8699nbgbh: Fix basic and meta workflow for tutorials * CU-8699nbgbh: Fix install targets for v2 tutorials * CU-8699nbgbh: Fix demo web app workflow * CU-8699nbgbh: Update patch info / output * CU-8699nbgbh: Use absolute path for notebook install fixes * CU-8699nbgbh: Fix rel-cat tutorial requirements * CU-8699nbgbh: Fix order or installation for demo web app (reinstall after main install) * CU-8699nbgbh: [TEMP] Add debug output for rel-cat notebook tests * CU-8699nbgbh: Add MetaCAT during RelCAT tutorials * CU-8699nbgbh: Make sure to import RelCAT after package install * Revert "CU-8699nbgbh: Make sure to import RelCAT after package install" This reverts commit 2fc7758. * CU-8699nbgbh: just install pip at notebook run time during tests * CU-8699nbgbh: Install all necessary optional dependencies at once at test time * CU-8699nbgbh: Install all necessary optional dependencies at once at test time (nr2) * CU-8699nbgbh: Install PR-based MedCAT for medcat-service tests * CU-8699nbgbh: Run medcat-service tests upon core libe update * CU-8699nbgbh: Test docker image against current medcat state / changes in medcat-service * CU-8699nbgbh: Fix medcat-v2 install target when installing from local * CU-8699nbgbh: Make sure the core library is available for install during docker image creation * CU-8699nbgbh: Fix medcat lib path in Dockerfile(s) * CU-8699nbgbh: Fix medcat lib path in Dockerfiles - make sure its a relative path * CU-8699nbgbh: Copy medcat-v2 before building images * CU-8699nbgbh: Update docker build workflow to include checking out repo and using local context for build * CU-8699nbgbh: Update docker context path for build workflow * CU-8699nbgbh: Update Dockerfile path for GPU-based service * CU-8699nbgbh: Make sure to run gpu-based service with PR changes
1 parent 1fbfeb0 commit 2c7cbbf

File tree

10 files changed

+128
-9
lines changed

10 files changed

+128
-9
lines changed

.github/workflows/medcat-demo-app_build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
pull_request:
77
paths:
88
- 'medcat-demo-app/**'
9+
- 'medcat-v2/**'
910
- '.github/workflows/medcat-demo-app**'
1011
defaults:
1112
run:
@@ -14,13 +15,18 @@ defaults:
1415
jobs:
1516
integration-test:
1617
runs-on: ubuntu-latest
18+
env:
19+
MEDCAT_BRANCH: ${{ github.head_ref || github.ref_name }}
1720

1821
steps:
1922
- uses: actions/checkout@v3
2023

2124
- name: Set up Docker Compose
2225
run: sudo apt-get update && sudo apt-get install -y docker-compose
2326

27+
- name: Make medact-v2 available within webapp
28+
run: cp -r ../medcat-v2 webapp/medcat-v2
29+
2430
- name: Build and start containers
2531
run: docker-compose -f docker-compose-test.yml up -d --build
2632

.github/workflows/medcat-service_docker.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- 'medcat-service/v*.*.*' # e.g., medcat-serice/v0.1.1
88
pull_request:
99
paths:
10+
- 'medcat-v2/**'
1011
- 'medcat-service/**'
1112
- '.github/workflows/medcat-service**'
1213
release:
@@ -24,7 +25,10 @@ jobs:
2425
runs-on: ubuntu-latest
2526
outputs:
2627
image_version: ${{ steps.meta.outputs.version }}
27-
steps:
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
2832
- name: Log in to Docker Hub
2933
uses: docker/login-action@v1
3034
with:
@@ -51,17 +55,22 @@ jobs:
5155
# Create version tag based on tag prefix
5256
type=match,pattern=medcat-service/v(\d+\.\d+\.\d+),group=1
5357
58+
- name: Make medact-v2 available within build
59+
run: cp -r ../medcat-v2 medcat-v2
60+
5461
- name: Build and push Docker MedCATservice image
5562
id: docker_build
5663
uses: docker/build-push-action@v6
5764
with:
58-
context: "{{defaultContext}}:medcat-service" # Set the working directory as the action doesnt use the working-directory default
65+
context: ./medcat-service/
5966
push: true
6067
allow: network.host
6168
tags: ${{ steps.meta.outputs.tags }}
6269
labels: ${{ steps.meta.outputs.labels }}
6370
cache-from: type=registry,ref=cogstacksystems/medcat-service:buildcache
6471
cache-to: type=registry,ref=cogstacksystems/medcat-service:buildcache,mode=max
72+
build-args: |
73+
REINSTALL_CORE_FROM_LOCAL=true
6574
6675
- name: Extract metadata (tags, labels) for Docker MedCATservice-gpu
6776
id: meta-gpu
@@ -79,19 +88,23 @@ jobs:
7988
type=sha
8089
# Create version tag based on tag prefix
8190
type=match,pattern=medcat-service/v(\d+\.\d+\.\d+),group=1
91+
build-args: |
92+
REINSTALL_CORE_FROM_LOCAL=true
8293
8394
- name: Build and push Docker Jupyter singleuser image with GPU support
8495
id: docker_build_gpu
8596
uses: docker/build-push-action@v6
8697
with:
87-
context: "{{defaultContext}}:medcat-service" # Set the working directory as the action doesnt use the working-directory default
88-
file : "Dockerfile_gpu"
98+
context: ./medcat-service/
99+
file : "./medcat-service/Dockerfile_gpu"
89100
allow: network.host
90101
tags: ${{ steps.meta-gpu.outputs.tags }}
91102
labels: ${{ steps.meta-gpu.outputs.labels }}
92103
push: true
93104
cache-from: type=registry,ref=cogstacksystems/medcat-service-gpu:buildcache
94105
cache-to: type=registry,ref=cogstacksystems/medcat-service-gpu:buildcache,mode=max
106+
build-args: |
107+
REINSTALL_CORE_FROM_LOCAL=true
95108
96109
- name: Image digest
97110
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/medcat-service_run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ main ]
66
pull_request:
77
paths:
8+
- 'medcat-v2/**'
89
- 'medcat-service/**'
910
- '.github/workflows/medcat-service**'
1011

@@ -39,6 +40,7 @@ jobs:
3940
python -m pip install virtualenv setuptools
4041
python -m pip install isort flake8 mypy stubs types-Flask types-simplejson types-setuptools types-requests
4142
python -m pip install -r ./requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu/;
43+
python -m pip install "../medcat-v2[meta-cat,spacy,deid]"
4244
4345
- name: Check linting and types
4446
run: |

.github/workflows/medcat-v2-tutorials_main.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ jobs:
2323
with:
2424
python-version: "3.11"
2525
cache: 'pip'
26+
27+
- name: Update install targets in notebooks
28+
run: |
29+
python .ci/patch_notebook_installs.py .
30+
2631
- name: Install dependencies
2732
run: |
2833
pip install -U pip
2934
pip install -r requirements.txt
35+
pip install "../medcat-v2[spacy,deid,rel-cat,meta-cat]"
36+
3037
- name: Install IPython kernel
3138
run: |
3239
python -m ipykernel install --name smoketests --user
@@ -44,7 +51,6 @@ jobs:
4451
pytest --nbmake -n=auto --nbmake-kernel=smoketests --nbmake-timeout=1800 ./notebooks/introductory/custom/*.ipynb
4552
4653
migrate-and-advanved:
47-
4854
runs-on: ubuntu-latest
4955
strategy:
5056
matrix:
@@ -60,14 +66,21 @@ jobs:
6066
uses: actions/setup-python@v5
6167
with:
6268
python-version: "3.11"
69+
70+
- name: Update install targets in notebooks
71+
run: |
72+
python .ci/patch_notebook_installs.py .
73+
6374
- name: Install dependencies
6475
run: |
6576
pip install -U pip
6677
pip install -r requirements.txt
78+
pip install "../medcat-v2[spacy,deid,rel-cat,meta-cat]"
79+
6780
- name: Install IPython kernel
6881
run: |
6982
python -m ipykernel install --name smoketests --user
7083
- name: Smoke test tutorial
7184
run: |
72-
pytest --collect-only --nbmake ${{ matrix.part }}
73-
pytest --nbmake -n=auto --nbmake-kernel=smoketests --nbmake-timeout=1800 ${{ matrix.part }}
85+
pytest --capture=no --collect-only --nbmake ${{ matrix.part }}
86+
pytest --capture=no --nbmake -n=auto --nbmake-kernel=smoketests --nbmake-timeout=1800 ${{ matrix.part }}

medcat-demo-app/docker-compose-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ services:
44
medcatweb:
55
build:
66
context: ./webapp
7+
args:
8+
REINSTALL_CORE_FROM_LOCAL: "true"
79
command: >
810
bash -c "/etc/init.d/cron start &&
911
python /webapp/manage.py runserver 0.0.0.0:8000"

medcat-demo-app/webapp/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1616
sqlite3 \
1717
libsqlite3-dev
1818

19+
1920
# Install Python dependencies
2021
ARG USE_CPU_TORCH=false
2122
# NOTE: Allow building without GPU so as to lower image size (disabled by default)
@@ -25,6 +26,13 @@ RUN pip install -U pip && if [ "$USE_CPU_TORCH" = "true" ]; then \
2526
pip install -r /webapp/requirements.txt; \
2627
fi
2728

29+
# NOTE: for test/CI time, this will install medcat based on local path
30+
ARG REINSTALL_CORE_FROM_LOCAL=false
31+
RUN if [ "$REINSTALL_CORE_FROM_LOCAL" = "true" ]; then \
32+
echo "Reinstalling medcat based on relative path"; \
33+
pip install -e "/webapp/medcat-v2[meta-cat,spacy]"; \
34+
fi
35+
2836
# Get the spacy model (for later copy)
2937
RUN python -m spacy download en_core_web_md
3038

medcat-service/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@ RUN for spacy_model in $SPACY_MODELS; do python -m spacy download $spacy_model;
2828
# Copy the remaining files
2929
COPY . /cat
3030

31+
# NOTE: for test/CI time, this will install medcat based on local path
32+
ARG REINSTALL_CORE_FROM_LOCAL=false
33+
RUN if [ "$REINSTALL_CORE_FROM_LOCAL" = "true" ]; then \
34+
echo "Reinstalling medcat based on relative path"; \
35+
pip install -e "./medcat-v2[meta-cat,spacy]"; \
36+
fi
37+
3138
# Now run the simple api
3239
CMD ["/bin/bash", "start_service_production.sh"]

medcat-service/Dockerfile_gpu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,12 @@ RUN for spacy_model in $SPACY_MODELS; do python -m spacy download $spacy_model;
4646
# Copy the remaining files
4747
COPY . /cat
4848

49+
# NOTE: for test/CI time, this will install medcat based on local path
50+
ARG REINSTALL_CORE_FROM_LOCAL=false
51+
RUN if [ "$REINSTALL_CORE_FROM_LOCAL" = "true" ]; then \
52+
echo "Reinstalling medcat based on relative path"; \
53+
pip install -e "./medcat-v2[meta-cat,spacy]"; \
54+
fi
55+
4956
# Now run the simple api
5057
CMD ["/bin/bash", "start_service_production.sh"]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sys
2+
import pathlib
3+
import re
4+
from functools import partial
5+
6+
7+
# rel_install_path = "../medcat-v2/"
8+
# abs_install_path = str(pathlib.Path(rel_install_path).resolve())
9+
10+
# Matches either:
11+
# 1. `! pip install medcat[extras]`
12+
# 2. `! pip install medcat[extras] @ git+...`
13+
shell_pattern = re.compile(
14+
r'(!\s*pip\s+install\s+)(\\["\']?)medcat(\[.*?\])'
15+
r'(\s*@\s*git\+[^"\'\s]+)?\2'
16+
)
17+
req_txt_pattern = re.compile(
18+
r'^(medcat(\[.*?\])?)\s*@\s*git\+\S+', flags=re.MULTILINE
19+
)
20+
21+
22+
def repl_nb(m, file_path: pathlib.Path):
23+
# extras = m[3]
24+
old_url = m[4]
25+
if old_url and "medcat/v" in old_url:
26+
print(f"[WARN] {file_path} refers to alpha/tagged release: "
27+
f"{old_url.strip()}")
28+
# to_write = f'{m[1]}\\"{abs_install_path}{extras}\\"'
29+
to_write = '! pip install \\"pip\\"'
30+
print(f"[PATCHED] {file_path}\n with: '{to_write}'")
31+
return to_write
32+
33+
34+
def do_patch(nb_path: pathlib.Path,
35+
regex: re.Pattern = shell_pattern, repl_method=repl_nb):
36+
nb_text = nb_path.read_text(encoding="utf-8")
37+
38+
repl = partial(repl_method, file_path=nb_path)
39+
new_text = regex.sub(repl, nb_text)
40+
41+
if nb_text != new_text:
42+
nb_path.write_text(new_text, encoding="utf-8")
43+
44+
45+
def main(path: str):
46+
for nb_path in pathlib.Path(path).rglob("**/*.ipynb"):
47+
do_patch(nb_path)
48+
49+
50+
if __name__ == "__main__":
51+
if len(sys.argv) != 2:
52+
print("Usage: python patch_notebook_installs.py <path>")
53+
sys.exit(1)
54+
55+
path = sys.argv[1]
56+
57+
if not pathlib.Path(path).exists():
58+
print(f"Path {path} does not exist.")
59+
sys.exit(1)
60+
61+
main(path)

medcat-v2-tutorials/notebooks/introductory/relcat/1._Supervised_Training_Relation_Extraction.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 1,
14+
"execution_count": null,
1515
"id": "b52c34cc",
1616
"metadata": {},
1717
"outputs": [
@@ -101,7 +101,7 @@
101101
],
102102
"source": [
103103
"# Install medcat\n",
104-
"! pip install \"medcat[spacy,meta-cat] @ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2\" # NOTE: VERSION-STRING"
104+
"! pip install \"medcat[spacy,rel-cat,meta-cat] @ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2\" # NOTE: VERSION-STRING"
105105
]
106106
},
107107
{

0 commit comments

Comments
 (0)