Skip to content

Commit

Permalink
Merge pull request #17 from kbaseapps/PUBLIC-2591_python_312_update
Browse files Browse the repository at this point in the history
PUBLIC-2591: Python 3.12 update
  • Loading branch information
ialarmedalien authored Aug 14, 2024
2 parents 4579574 + a2956b8 commit ea6cc87
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 28 deletions.
1 change: 0 additions & 1 deletion .github/workflows/kb_sdk_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4-rc-1 -l /var/run/docker.sock|awk '{print $4}' > $HOME/.kbsdk.cache
fi
# ignore the exit code
docker run -i --rm -v $HOME:$HOME -u $(id -u) -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=$USER -e DSHELL=$SHELL --group-add $(cat $HOME/.kbsdk.cache) ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4-rc-1 test || true
Expand Down
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
FROM kbase/sdkpython:3.8.10
FROM python:3.12-bookworm
LABEL maintainer="KBase Developers [[email protected]]"

WORKDIR /kb/module
# Update
RUN apt-get update \
&& apt-get upgrade -y && \
update-ca-certificates && \
apt-get -y install xvfb curl && \
# these are all needed by PyQt5
apt-get -y install libdbus-1-3 libxcb-keysyms1 libxcb-image0 libxkbcommon-x11-0 libxkbcommon0 libxcb-icccm4 libxcb-image0 libxcb-render-util0 libxcb-shape0 libxcb-xinerama0 && \
apt-get clean && \
# Install FastTree
mkdir -p /kb/module/FastTree/bin && \
cd /kb/module/FastTree/bin && \
curl -o FastTree http://www.microbesonline.org/fasttree/FastTree && \
chmod 555 FastTree && \
pip install --upgrade pip && \
# install the python requirements
# Note: You must use PyQt5==5.11.3 on debian
pip install ete3==3.1.2 PyQt5==5.11.3 numpy==1.23.1 pytest coverage pytest-cov vcrpy
pip install --upgrade pip

COPY ./ /kb/module

RUN mkdir -p /kb/module/work && \
# install the python requirements
RUN pip install -r requirements.txt && \
mkdir -p /kb/module/work && \
chmod -R a+rw /kb/module && \
mv /kb/module/compile_report.json /kb/module/work/compile_report.json

Expand Down
14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
coverage==7.6.1
ete3==3.1.3
jinja2==3.1.4
jsonrpcbase==0.2.0
numpy==2.0.1
PyQt5==5.15.11
pytest==8.3.2
pytest-cov==5.0.0
pytest-recording==0.13.2
requests==2.32.3
ruff==0.5.7
six==1.16.0
vcrpy==6.0.1
uwsgi==2.0.26
6 changes: 1 addition & 5 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

. /kb/deployment/user-env.sh

python ./scripts/prepare_deploy_cfg.py ./deploy.cfg ./work/config.properties

if [ -f ./work/token ] ; then
Expand All @@ -16,13 +14,11 @@ elif [ "${1}" = "test" ] ; then
elif [ "${1}" = "async" ] ; then
# sh ./scripts/run_async.sh
xvfb-run bash ./scripts/run_async.sh
elif [ "${1}" = "init" ] ; then
echo "Initialize module"
elif [ "${1}" = "bash" ] ; then
bash
elif [ "${1}" = "report" ] ; then
export KB_SDK_COMPILE_REPORT_FILE=./work/compile_report.json
echo The compile report is available at /kb/module/work/compile_report.json
else
echo Unknown
echo Unknown command
fi
43 changes: 33 additions & 10 deletions scripts/prepare_deploy_cfg.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
"""Generate the deployment config file."""

import os
import os.path
import sys
from configparser import ConfigParser

from jinja2 import Template
from configparser import ConfigParser # py3

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: <program> <deploy_cfg_template_file> <file_with_properties>")
print("Properties from <file_with_properties> will be applied to <deploy_cfg_template_file>")
print("template which will be overwritten with .orig copy saved in the same folder first.")
if len(sys.argv) < 2 or len(sys.argv) > 3:
print("Usage:\nprepare_deploy_config.py <deploy_cfg_template_file> <file_with_properties>\nor:") # noqa: T201
print("KBASE_ENDPOINT=https://kbase.endpoint.url prepare_deploy_config.py <deploy_cfg_template_file>") # noqa: T201
print( # noqa: T201
"Properties from <file_with_properties> or the KBASE_ENDPOINT env var will be applied to <deploy_cfg_template_file>"
)
print("template which will be overwritten with .orig copy saved in the same folder first.") # noqa: T201
sys.exit(1)
file = open(sys.argv[1], 'r')
text = file.read()

with open(sys.argv[1]) as file:
text = file.read()
t = Template(text)
config = ConfigParser()
config.read(sys.argv[2])

if os.path.isfile(sys.argv[2]):
config.read(sys.argv[2])
elif "KBASE_ENDPOINT" in os.environ:
kbase_endpoint = os.environ.get("KBASE_ENDPOINT")
props = f"[global]\nkbase_endpoint = {kbase_endpoint}\n"
for key in os.environ:
if key.startswith("KBASE_SECURE_CONFIG_PARAM_"):
param_name = key[len("KBASE_SECURE_CONFIG_PARAM_") :]
props += f"{param_name} = {os.environ.get(key)}\n"
config.read_string(props)
else:
err_msg = f"Neither {sys.argv[2]} file nor KBASE_ENDPOINT env var found"
raise ValueError(err_msg)

props = dict(config.items("global"))
output = t.render(props)
with open(sys.argv[1] + ".orig", 'w') as f:
with open(sys.argv[1] + ".orig", "w") as f:
f.write(text)
with open(sys.argv[1], 'w') as f:
with open(sys.argv[1], "w") as f:
f.write(output)
6 changes: 2 additions & 4 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ export PYTHONPATH=$PYTHON_LIB_DIR:$PYTHONPATH

# collect coverage data
pytest \
-vv
--cov=$PYTHON_LIB_DIR \
--cov-config=.coveragerc \
--cov-report=html \
--cov-report=xml \
--cov=/kb/module/lib \
-vv \
test

echo "Finished tests!"

0 comments on commit ea6cc87

Please sign in to comment.