Skip to content

Commit

Permalink
build!: Update to python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
zusorio committed Dec 17, 2024
1 parent 7435a56 commit 5a709c0
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- run: pip install -r docs/requirements.txt
- run: mkdocs gh-deploy --strict --force
working-directory: ./docs
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
cache: pip
cache-dependency-path: ./backend/pyproject.toml
python-version: '3.11'
python-version: '3.12'
- name: Install pre-commit
run: |-
python -m pip install pre-commit
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
cache: pip
cache-dependency-path: ./backend/pyproject.toml
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
working-directory: ./backend
run: python -m venv .venv && .venv/bin/pip install -e ".[dev]"
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
with:
cache: pip
cache-dependency-path: ./backend/pyproject.toml
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
working-directory: ./backend
run: python -m venv .venv && .venv/bin/pip install -e ".[dev]"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
cache: pip
cache-dependency-path: ./backend/pyproject.toml
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
run: |
pip install -e "./backend[dev]"
Expand Down
22 changes: 4 additions & 18 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

ARG BASE_IMAGE=debian:bookworm-slim
ARG BASE_IMAGE=python:3.12-slim-bookworm
FROM $BASE_IMAGE

SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
Expand All @@ -13,40 +13,26 @@ RUN apt-get update && \
apt-get upgrade --yes && \
apt-get install --yes \
ca-certificates \
curl \
git-lfs \
gnupg \
libpq-dev \
python3 \
python3-pip \
python3-venv \
unzip \
&& rm -rf /var/lib/apt/lists/*

ARG KUBECTL_APT_REMOTE=https://pkgs.k8s.io/core:/stable:/v1.29/deb/

# Install kubectl if not available in base image
# kubectl is needed for the list files endpoint
RUN mkdir -p /etc/apt/keyrings && \
curl --proto "=https" -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] $KUBECTL_APT_REMOTE /" | tee /etc/apt/sources.list.d/kubernetes.list && \
apt-get update && apt-get install -y kubectl && rm -rf /var/lib/apt/lists/*

EXPOSE 8000
COPY . /tmp/backend
COPY .git_archival.txt /tmp/.git_archival.txt
COPY startup.sh /opt/.startup.sh

# Activate venv
RUN ln -s "$(which python3.11)" /usr/bin/python && \
ln -sf "$(which python3.11)" /usr/bin/python3 && \
RUN ln -s "$(which python3.12)" /usr/bin/python && \
ln -sf "$(which python3.12)" /usr/bin/python3 && \
python -m venv /opt/.venv
ENV _OLD_VIRTUAL_PATH="$PATH"
ENV VIRTUAL_ENV=/opt/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

WORKDIR /tmp/backend
RUN pip install . && chmod +x "$VIRTUAL_ENV/lib/python3.11/site-packages/capellacollab/settings/modelsources/git/askpass.py"
RUN pip install . && chmod +x "$VIRTUAL_ENV/lib/python3.12/site-packages/capellacollab/settings/modelsources/git/askpass.py"

RUN mkdir -p /var/log/backend && \
chmod -R 777 /var/log/backend
Expand Down
75 changes: 38 additions & 37 deletions backend/capellacollab/sessions/operators/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import random
import shlex
import string
import subprocess
import typing as t

import kubernetes
Expand Down Expand Up @@ -70,9 +69,7 @@ def __init__(self) -> None:
self.v1_policy = client.PolicyV1Api(api_client=self.client)

def load_config(self) -> None:
self.kubectl_arguments = []
if cfg.context:
self.kubectl_arguments += ["--context", cfg.context]
kubernetes.config.load_config(context=cfg.context)
else:
kubernetes.config.load_incluster_config()
Expand Down Expand Up @@ -977,47 +974,51 @@ def get_files(dir: pathlib.Path, show_hidden: bool):
)

source = helper.get_source_of_python_function(print_file_tree_as_json)

# We have to use subprocess to get it running until this issue is solved:
# https://github.com/kubernetes/kubernetes/issues/89899
# Python doesn't start evaluating the code before EOF, but there is no way to close stdin
encoded = base64.b64encode(source.encode("utf-8")).decode("utf-8")

Check warning on line 977 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L977

Added line #L977 was not covered by tests

try:
response = subprocess.run(
["kubectl"]
+ self.kubectl_arguments
+ [
"--namespace",
namespace,
"exec",
"--stdin",
session_id,
"--container",
"session",
"--",
"python",
"-",
directory,
json.dumps(show_hidden),
],
input=source.encode(),
capture_output=True,
check=True,
)
except subprocess.CalledProcessError as e:
log.error(
"Loading files of session '%s' failed - STDOUT: %s",
stream = kubernetes.stream.stream(

Check warning on line 980 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L980

Added line #L980 was not covered by tests
self.v1_core.connect_get_namespaced_pod_exec,
session_id,
e.stdout.decode(),
container="session",
namespace=namespace,
command=[
"bash",
"-c",
f'echo "{encoded}" | base64 --decode | python - {directory} {json.dumps(show_hidden)}',
],
stderr=True,
stdin=False,
stdout=True,
tty=False,
_preload_content=False,
)
log.error(
"Loading files of session '%s' failed - STDERR: %s",
session_id,
e.stderr.decode(),

stream.update(timeout=15)

Check warning on line 997 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L997

Added line #L997 was not covered by tests

stdout = ""

Check warning on line 999 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L999

Added line #L999 was not covered by tests

if stream.peek_stdout():
stdout = stream.read_stdout()
log.debug(

Check warning on line 1003 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L1002-L1003

Added lines #L1002 - L1003 were not covered by tests
"Loading files of session '%s' - STDOUT: %s",
session_id,
stdout,
)
if stream.peek_stderr():
stderr = stream.read_stderr()
log.debug(

Check warning on line 1010 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L1009-L1010

Added lines #L1009 - L1010 were not covered by tests
"Loading files of session '%s' - STDERR: %s",
session_id,
stderr,
)
except exceptions.ApiException:
log.exception(

Check warning on line 1016 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L1015-L1016

Added lines #L1015 - L1016 were not covered by tests
"Exception when copying file to the pod with id %s", id
)
raise

return json.loads(response.stdout)
return json.loads(stdout)

Check warning on line 1021 in backend/capellacollab/sessions/operators/k8s.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/operators/k8s.py#L1021

Added line #L1021 was not covered by tests

def upload_files(
self,
Expand Down
6 changes: 3 additions & 3 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dynamic = ["version"]

name = "capellacollab-backend"
readme = "README.md"
requires-python = ">=3.11, <3.13"
requires-python = ">=3.12, <3.14"
license = { text = "Apache-2.0" }
authors = [{ name = "DB InfraGO AG" }]
keywords = []
Expand Down Expand Up @@ -95,7 +95,7 @@ no_implicit_optional = true
show_error_codes = true
warn_redundant_casts = true
warn_unreachable = true
python_version = "3.11"
python_version = "3.12"
exclude = "capellacollab/alembic"

[[tool.mypy.overrides]]
Expand Down Expand Up @@ -222,7 +222,7 @@ xfail_strict = true

[tool.ruff]
line-length = 79
target-version = "py311"
target-version = "py312"

[tool.ruff.lint]
select = ["I", "UP"]
Expand Down
2 changes: 1 addition & 1 deletion docs/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: '3.11'
python: '3.12'

mkdocs:
configuration: docs/mkdocs.yml
Expand Down
2 changes: 1 addition & 1 deletion docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

ARG BASE_IMAGE=python:3.11-bookworm
ARG BASE_IMAGE=python:3.12-slim-bookworm
FROM $BASE_IMAGE as build

USER root
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/admin/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sessions.
## Installation

In order to use the CLI tooling, you'll need to have a local copy of the
collab-manager application and Python 3.11 installed.
collab-manager application and Python 3.12 installed.

```bash
git clone https://github.com/DSD-DBS/capella-collab-manager.git
Expand Down

0 comments on commit 5a709c0

Please sign in to comment.