Skip to content

Commit

Permalink
Pydantic upgrade to support v2 (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter authored Jul 15, 2023
1 parent f2d5c4b commit d77865e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/kubernetes-helm
{
"name": "Kubernetes - Local Configuration",
"build": {
"context": "..",
"dockerfile": "../Dockerfile"
}
}
4 changes: 4 additions & 0 deletions .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
- name: Test with pytest
run: |
SKIP_DIFF_TESTS=1 pytest --cov=flux_local --cov-report=term-missing
- name: Test with pytest pydantic v1
run: |
pip install pydantic==1.10.11
SKIP_DIFF_TESTS=1 pytest --cov=flux_local --cov-report=term-missing
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Docker environment for local development in devcontainer
FROM ubuntu:jammy-20230308

RUN apt-get update --fix-missing && \
apt-get upgrade -y && \
apt-get install -y --fix-missing \
curl \
unzip \
software-properties-common \
vim \
git \
python3-pip

# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize
ARG KUSTOMIZE_VERSION=v5.0.3
RUN cd /usr/local/bin/ && \
curl -OL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
tar xf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
chmod +x kustomize
RUN kustomize version

# renovate: datasource=github-releases depName=helm/helm
ARG HELM_CLI_VERSION=v3.12.1
RUN mkdir -p /src && \
cd /src && \
curl -OL https://get.helm.sh/helm-${HELM_CLI_VERSION}-linux-amd64.tar.gz && \
tar xf helm-${HELM_CLI_VERSION}-linux-amd64.tar.gz && \
cp linux-amd64/helm /usr/local/bin/helm && \
rm -fr /src
RUN helm version

# renovate: datasource=github-releases depName=kyverno/kyverno
ARG KYVERNO_VERSION=v1.10.0
RUN mkdir -p /src && \
cd /src && \
curl -OL https://github.com/kyverno/kyverno/releases/download/${KYVERNO_VERSION}/kyverno-cli_${KYVERNO_VERSION}_linux_x86_64.tar.gz && \
tar xf kyverno-cli_${KYVERNO_VERSION}_linux_x86_64.tar.gz && \
cp kyverno /usr/local/bin/kyverno && \
chmod +x /usr/local/bin/kyverno && \
rm -fr /src
RUN kyverno version

COPY . /src/
WORKDIR /src/
RUN pip3 install -r /src/requirements.txt

SHELL ["/bin/bash", "-c"]
7 changes: 6 additions & 1 deletion flux_local/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

import aiofiles
import yaml
from pydantic import BaseModel, Field
try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

from .exceptions import InputException

Expand Down Expand Up @@ -427,6 +430,8 @@ async def read_manifest(manifest_path: Path) -> Manifest:
"""
async with aiofiles.open(str(manifest_path)) as manifest_file:
content = await manifest_file.read()
if not content:
raise ValueError("validation error for Manifest file {manifest_path}")
return cast(Manifest, Manifest.parse_yaml(content))


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nest_asyncio==1.5.6
pdoc==14.0.0
pip==23.1.2
pre-commit==3.3.3
pydantic==1.10.11
pydantic==2.0.3
pytest==7.4.0
pytest-asyncio==0.21.1
pytest-cov==4.1.0
Expand Down
3 changes: 1 addition & 2 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
import yaml
from pydantic import ValidationError

from flux_local.manifest import (
Cluster,
Expand Down Expand Up @@ -94,7 +93,7 @@ async def test_read_write_empty_manifest(tmp_path: Path) -> None:

async def test_read_manifest_invalid_file() -> None:
"""Test reading an invalid manifest file."""
with pytest.raises(ValidationError, match="validation error for Manifest"):
with pytest.raises(ValueError, match="validation error for Manifest"):
await read_manifest(Path("/dev/null"))


Expand Down

0 comments on commit d77865e

Please sign in to comment.