Skip to content

Commit

Permalink
chore: WIP pydantic v2 -> v1
Browse files Browse the repository at this point in the history
Also updating to python 3.11. Getting an insane amount of grief aka build errors.
Stopping for now and waiting till things are more stable
  • Loading branch information
alexpovel committed Aug 4, 2023
1 parent 36ca4a5 commit a6d1104
Show file tree
Hide file tree
Showing 7 changed files with 935 additions and 916 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Global ARG, available to all stages (if renewed)
ARG WORKDIR="/app"

FROM python:3.10 AS builder
FROM python:3.11 AS builder

# Renew (https://stackoverflow.com/a/53682110):
ARG WORKDIR
Expand All @@ -18,7 +18,7 @@ COPY . .

RUN poetry install --only main

FROM python:3.10-alpine
FROM python:3.11-alpine

ARG WORKDIR

Expand Down
84 changes: 31 additions & 53 deletions ancv/data/models/github.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module contains models for the relevant parts of GitHub's API."""

import typing as t
from datetime import datetime
from typing import Mapping, Optional

from pydantic import BaseModel, Field, HttpUrl

Expand All @@ -12,11 +12,11 @@ class File(BaseModel):
See: https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-the-authenticated-user, under the "files" key.
"""

filename: Optional[str] = None
type: Optional[str] = None
language: Optional[str] = None
raw_url: Optional[HttpUrl] = None
size: Optional[int] = None
filename: str | None = None
type: str | None = None
language: str | None = None
raw_url: HttpUrl | None = None
size: int | None = None


class GistUser(BaseModel):
Expand All @@ -25,49 +25,27 @@ class GistUser(BaseModel):
See: https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-the-authenticated-user
"""

name: Optional[str] = None
email: Optional[str] = None
login: str = Field(..., examples=["octocat"])
id: int = Field(..., examples=[1])
node_id: str = Field(..., examples=["MDQ6VXNlcjE="])
avatar_url: HttpUrl = Field(
..., examples=["https://github.com/images/error/octocat_happy.gif"]
)
gravatar_id: Optional[str] = Field(
None, examples=["41d064eb2195891e12d0413f63227ea7"]
)
url: HttpUrl = Field(..., examples=["https://api.github.com/users/octocat"])
html_url: HttpUrl = Field(..., examples=["https://github.com/octocat"])
followers_url: HttpUrl = Field(
..., examples=["https://api.github.com/users/octocat/followers"]
)
following_url: str = Field(
..., examples=["https://api.github.com/users/octocat/following{/other_user}"]
)
gists_url: str = Field(
..., examples=["https://api.github.com/users/octocat/gists{/gist_id}"]
)
starred_url: str = Field(
..., examples=["https://api.github.com/users/octocat/starred{/owner}{/repo}"]
)
subscriptions_url: HttpUrl = Field(
..., examples=["https://api.github.com/users/octocat/subscriptions"]
)
organizations_url: HttpUrl = Field(
..., examples=["https://api.github.com/users/octocat/orgs"]
)
repos_url: HttpUrl = Field(
..., examples=["https://api.github.com/users/octocat/repos"]
)
events_url: str = Field(
..., examples=["https://api.github.com/users/octocat/events{/privacy}"]
)
received_events_url: HttpUrl = Field(
..., examples=["https://api.github.com/users/octocat/received_events"]
)
type: str = Field(..., examples=["User"])
name: str | None = None
email: str | None = None
login: t.Annotated[str, Field(examples=["octocat"])]
id: t.Annotated[int, Field(examples=[1])]
node_id: t.Annotated[str, Field(examples=["MDQ6VXNlcjE="])]
avatar_url: t.Annotated[HttpUrl, Field(examples=["https://github.com/images/error/octocat_happy.gif"])]
gravatar_id: t.Annotated[str | None, Field(examples=["41d064eb2195891e12d0413f63227ea7"])] = None
url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat"])]
html_url: t.Annotated[HttpUrl, Field(examples=["https://github.com/octocat"])]
followers_url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat/followers"])]
following_url: t.Annotated[str, Field(examples=["https://api.github.com/users/octocat/following{/other_user}"])]
gists_url: t.Annotated[str, Field(examples=["https://api.github.com/users/octocat/gists{/gist_id}"])]
starred_url: t.Annotated[str, Field(examples=["https://api.github.com/users/octocat/starred{/owner}{/repo}"])]
subscriptions_url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat/subscriptions"])]
organizations_url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat/orgs"])]
repos_url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat/repos"])]
events_url: t.Annotated[str, Field(examples=["https://api.github.com/users/octocat/events{/privacy}"])]
received_events_url: t.Annotated[HttpUrl, Field(examples=["https://api.github.com/users/octocat/received_events"])]
type: t.Annotated[str, Field(examples=["User"])]
site_admin: bool
starred_at: Optional[datetime] = Field(None, examples=['"2020-07-09T00:17:55Z"'])
starred_at: t.Annotated[datetime | None, Field(examples=['"2020-07-09T00:17:55Z"'])] = None


class Gist(BaseModel):
Expand All @@ -83,13 +61,13 @@ class Gist(BaseModel):
git_pull_url: HttpUrl
git_push_url: HttpUrl
html_url: HttpUrl
files: Mapping[str, File]
files: t.Mapping[str, File]
public: bool
created_at: datetime
updated_at: datetime
description: Optional[str] = None
description: str | None = None
comments: int
user: Optional[GistUser] = None
user: GistUser | None = None
comments_url: HttpUrl
owner: Optional[GistUser] = None
truncated: Optional[bool] = None
owner: GistUser | None = None
truncated: bool | None = None
Loading

0 comments on commit a6d1104

Please sign in to comment.