Skip to content

Commit

Permalink
Merge branch 'pydantic_v2_migration_do_not_squash_updates' into is448…
Browse files Browse the repository at this point in the history
…1/upgrade-api-server-service
  • Loading branch information
giancarloromeo authored Oct 25, 2024
2 parents 593df29 + 82c69d0 commit fd1ae8d
Show file tree
Hide file tree
Showing 109 changed files with 1,007 additions and 751 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ops/
*.py[cod]

# virtualenv
.venv
**/.venv

#python eggs
**/*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ email-validator==2.2.0
# via pydantic
fast-depends==2.4.12
# via faststream
faststream==0.5.23
faststream==0.5.28
# via -r requirements/../../../packages/service-library/requirements/_base.in
frozenlist==1.4.1
# via
Expand Down
38 changes: 27 additions & 11 deletions packages/models-library/src/models_library/projects_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

from enum import Enum, unique

from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
ValidationInfo,
field_validator,
model_validator,
)

from .projects_access import Owner

Expand Down Expand Up @@ -56,12 +63,12 @@ class ProjectStatus(str, Enum):

class ProjectLocked(BaseModel):
value: bool = Field(..., description="True if the project is locked")
status: ProjectStatus = Field(..., description="The status of the project")
owner: Owner | None = Field(
default=None,
description="If locked, the user that owns the lock",
validate_default=True,
)
status: ProjectStatus = Field(..., description="The status of the project")
model_config = ConfigDict(
extra="forbid",
use_enum_values=True,
Expand All @@ -81,15 +88,7 @@ class ProjectLocked(BaseModel):
},
)

@field_validator("owner", mode="before")
@classmethod
def check_not_null(cls, v, info: ValidationInfo):
if info.data["value"] is True and v is None:
msg = "value cannot be None when project is locked"
raise ValueError(msg)
return v

@field_validator("status")
@field_validator("status", mode="after")
@classmethod
def check_status_compatible(cls, v, info: ValidationInfo):
if info.data["value"] is False and v not in ["CLOSED", "OPENED"]:
Expand All @@ -100,6 +99,23 @@ def check_status_compatible(cls, v, info: ValidationInfo):
raise ValueError(msg)
return v

@model_validator(mode="before")
@classmethod
def check_owner_compatible(cls, values):
if (
values["value"] is True
and values.get("owner") is None
and values["status"]
in [
status.value
for status in ProjectStatus
if status != ProjectStatus.MAINTAINING
]
):
msg = "Owner must be specified when the project is not in the 'MAINTAINING' status."
raise ValueError(msg)
return values


class ProjectRunningState(BaseModel):
value: RunningState = Field(
Expand Down
4 changes: 4 additions & 0 deletions packages/models-library/tests/test_projects_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def test_project_locked_with_missing_owner_raises():
ProjectLocked.model_validate({"value": False, "status": ProjectStatus.OPENED})


def test_project_locked_with_missing_owner_ok_during_maintaining():
ProjectLocked.parse_obj({"value": True, "status": ProjectStatus.MAINTAINING})


@pytest.mark.parametrize(
"lock, status",
[
Expand Down
16 changes: 10 additions & 6 deletions packages/postgres-database/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# syntax=docker/dockerfile:1
FROM python:3.6-slim AS base
ARG PYTHON_VERSION="3.11.9"
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:${PYTHON_VERSION}-slim-bookworm AS base

LABEL maintainer=sanderegg

Expand All @@ -22,16 +26,14 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install uv~=0.2
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=uv_build /uv /uvx /bin/

# NOTE: python virtualenv is used here such that installed packages may be moved to production image easily by copying the venv
RUN uv venv "${VIRTUAL_ENV}"

RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --upgrade \
pip~=24.0 \
wheel \
setuptools

Expand All @@ -44,6 +46,8 @@ RUN git clone --single-branch --branch ${GIT_BRANCH} ${GIT_REPOSITORY} osparc-si
FROM base AS production

ENV PYTHONOPTIMIZE=TRUE
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
ENV UV_COMPILE_BYTECODE=1

WORKDIR /home/scu
# ensure home folder is read/writable for user scu
Expand Down
16 changes: 10 additions & 6 deletions packages/postgres-database/scripts/erd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# syntax=docker/dockerfile:1

# Define arguments in the global scope
ARG PYTHON_VERSION="3.11.9"
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:${PYTHON_VERSION}-slim-bookworm AS base

RUN apt-get update \
Expand All @@ -15,15 +20,14 @@ RUN apt-get update \
&& apt-get clean


RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=24.0 \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --upgrade \
wheel \
setuptools


# devenv
COPY requirements.txt requirements.txt
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install \
-r requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip sync \
requirements.txt
19 changes: 11 additions & 8 deletions packages/service-integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# syntax=docker/dockerfile:1

# Define arguments in the global scope
ARG PYTHON_VERSION="3.11.9"
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:${PYTHON_VERSION}-slim-bookworm AS base

LABEL maintainer=pcrespov
Expand Down Expand Up @@ -38,12 +43,13 @@ ENV LANG=C.UTF-8
# Turns off writing .pyc files; superfluous on an ephemeral container.
ENV PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/home/scu/.venv
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
ENV UV_COMPILE_BYTECODE=1

# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"


# -------------------------- Build stage -------------------

FROM base AS build
Expand All @@ -55,15 +61,14 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
&& apt-get install -y --no-install-recommends \
build-essential

# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install uv~=0.2
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=uv_build /uv /uvx /bin/

# NOTE: python virtualenv is used here such that installed
# packages may be moved to production image easily by copying the venv
RUN uv venv "${VIRTUAL_ENV}"

RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --upgrade \
pip~=24.0 \
wheel \
Expand All @@ -74,7 +79,7 @@ WORKDIR /build/packages/service-integration
RUN \
--mount=type=bind,source=packages,target=/build/packages,rw \
--mount=type=bind,source=packages/service-integration,target=/build/packages/service-integration,rw \
--mount=type=cache,mode=0755,target=/root/.cache/uv \
--mount=type=cache,target=/root/.cache/uv \
uv pip install \
--requirement requirements/prod.txt \
&& uv pip list
Expand All @@ -86,8 +91,6 @@ FROM base AS development
# NOTE: this is necessary to allow to build development images but is the same as production here
FROM base AS production

ENV PYTHONOPTIMIZE=TRUE

WORKDIR /home/scu
# ensure home folder is read/writable for user scu
RUN chown -R scu /home/scu
Expand Down
2 changes: 1 addition & 1 deletion packages/service-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ email-validator==2.2.0
# via pydantic
fast-depends==2.4.12
# via faststream
faststream==0.5.23
faststream==0.5.28
# via -r requirements/_base.in
frozenlist==1.4.1
# via
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def __init__(
ClassUniqueReference, type[BaseDeferredHandler]
] = {}

self.broker: RabbitBroker = RabbitBroker(rabbit_settings.dsn)
self.broker: RabbitBroker = RabbitBroker(
rabbit_settings.dsn, log_level=logging.DEBUG
)
self.router: RabbitRouter = RabbitRouter()

# NOTE: do not move this to a function, must remain in constructor
Expand Down
2 changes: 1 addition & 1 deletion packages/simcore-sdk/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ email-validator==2.2.0
# via pydantic
fast-depends==2.4.12
# via faststream
faststream==0.5.23
faststream==0.5.28
# via -r requirements/../../../packages/service-library/requirements/_base.in
flexcache==0.3
# via pint
Expand Down
14 changes: 7 additions & 7 deletions requirements/tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#
#
ARG PYTHON_VERSION="3.11.9"
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:${PYTHON_VERSION}-slim-bookworm AS base

ENV VIRTUAL_ENV=/home/scu/.venv
Expand All @@ -24,24 +27,21 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
&& apt-get clean -y


# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install uv~=0.2
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=uv_build /uv /uvx /bin/

RUN uv venv "${VIRTUAL_ENV}"

RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --upgrade \
pip~=24.0 \
wheel \
setuptools



# devenv
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install \
pip-tools \
pipreqs \
pipdeptree && \
uv pip list -vv
14 changes: 9 additions & 5 deletions scripts/erd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#

ARG PYTHON_VERSION="3.11.9"
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:${PYTHON_VERSION}-slim-bookworm AS base

RUN apt-get update \
Expand All @@ -22,13 +25,14 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=uv_build /uv /uvx /bin/

RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=24.0 \
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --upgrade \
wheel \
setuptools

COPY requirements.txt .
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install -r requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install -r requirements.txt
18 changes: 12 additions & 6 deletions scripts/maintenance/migrate_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# syntax=docker/dockerfile:1
ARG UV_VERSION="0.4"
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
# we docker image is built based on debian
FROM python:3.11.9-buster

RUN curl https://rclone.org/install.sh | bash && \
rclone --version

# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=uv_build /uv /uvx /bin/

WORKDIR /scripts

COPY packages/postgres-database postgres-database
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
cd postgres-database && pip install .
RUN --mount=type=cache,target=/root/.cache/uv \
cd postgres-database && uv pip install .

COPY packages/settings-library settings-library
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
cd settings-library && pip install .
RUN --mount=type=cache,target=/root/.cache/uv \
cd settings-library && uv pip install .

COPY scripts/maintenance/migrate_project/requirements.txt /scripts/requirements.txt
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install -r /scripts/requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install -r /scripts/requirements.txt

COPY scripts/maintenance/migrate_project/src/*.py /scripts/
Loading

0 comments on commit fd1ae8d

Please sign in to comment.