Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate package manager from Poetry to Rye #6

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM python:3.11-buster

RUN pip install poetry

RUN poetry config virtualenvs.create false
SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
RUN curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11]
poetry-version: [1.4.2]
python-version: [3.11, 3.12]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
- name: Install Rye
run: |
curl -sSL https://install.python-poetry.org | POETRY_HOME=$HOME/.poetry/ python
$HOME/.poetry/bin/poetry install
$HOME/.poetry/bin/poetry env use python${{ matrix.python-version }}
curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
source $HOME/.rye/env
rye sync
- name: Pytest
run: |
$HOME/.poetry/bin/poetry run pytest
rye run pytest
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.formatting.provider": "none",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.testing.pytestArgs": [
"tests",
"-vv"
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
POETRY=poetry
PYTEST=$(POETRY) run pytest
MYPY=$(POETRY) run mypy --ignore-missing-imports
BLACK=$(POETRY) run black
ISORT=$(POETRY) run isort
PYLINT=$(POETRY) run pylint
UVICORN=$(POETRY) run uvicorn
RYE=rye
PYTEST=$(RYE) run pytest
MYPY=$(RYE) run mypy --ignore-missing-imports
BLACK=$(RYE) run black
ISORT=$(RYE) run isort
PYLINT=$(RYE) run pylint
UVICORN=$(RYE) run uvicorn
PACKAGE=dddpy

install:
$(POETRY) install
$(RYE) sync
$(POETRY_EXPORT)

update:
$(POETRY) update
$(POETRY_EXPORT)
$(POETRY) sync

test: install
$(MYPY) main.py ./${PACKAGE}/
Expand Down
4 changes: 4 additions & 0 deletions dddpy/domain/book/book_exception.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
"""Book exception"""


class BookNotFoundError(Exception):
"""BookNotFoundError is an error that occurs when a book is not found."""

message = "The book you spcecified does not exist."

def __str__(self):
Expand All @@ -11,6 +13,7 @@ def __str__(self):

class BooksNotFoundError(Exception):
"""BooksNotFoundError is an error that occurs when books are not found."""

message = "No books were found."

def __str__(self):
Expand All @@ -19,6 +22,7 @@ def __str__(self):

class BookIsbnAlreadyExistsError(Exception):
"""BookIsbnAlreadyExistsError is an error that occurs when a book with the same ISBN code already exists."""

message = "The book with the ISBN code you specified already exists."

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion dddpy/domain/book/book_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Book repository"""

from abc import ABC, abstractmethod
from typing import Optional
from typing import Optional

from dddpy.domain.book import Book

Expand Down
3 changes: 1 addition & 2 deletions dddpy/infrastructure/sqlite/book/book_dto.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime

from sqlalchemy import String
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column


from dddpy.domain.book import Book, Isbn
from dddpy.infrastructure.sqlite.database import Base
from dddpy.usecase.book import BookReadModel
Expand Down
6 changes: 3 additions & 3 deletions dddpy/presentation/schema/book/book_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


class ErrorMessageBookNotFound(BaseModel):
detail: str = Field(example=BookNotFoundError.message)
detail: str = Field(examples=[BookNotFoundError.message])


class ErrorMessageBooksNotFound(BaseModel):
detail: str = Field(example=BooksNotFoundError.message)
detail: str = Field(examples=[BooksNotFoundError.message])


class ErrorMessageBookIsbnAlreadyExists(BaseModel):
detail: str = Field(example=BookIsbnAlreadyExistsError.message)
detail: str = Field(examples=[BookIsbnAlreadyExistsError.message])
12 changes: 6 additions & 6 deletions dddpy/usecase/book/book_command_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
class BookCreateModel(BaseModel):
"""BookCreateModel represents a write model to create a book."""

isbn: str = Field(example="978-0321125217")
isbn: str = Field(examples=["978-0321125217"])
title: str = Field(
example="Domain-Driven Design: Tackling Complexity in the Heart of Softwares"
examples=["Domain-Driven Design: Tackling Complexity in the Heart of Softwares"]
)
page: int = Field(ge=0, example=320)
page: int = Field(ge=0, examples=[320])


class BookUpdateModel(BaseModel):
"""BookUpdateModel represents a write model to update a book."""

title: str = Field(
example="Domain-Driven Design: Tackling Complexity in the Heart of Softwares"
examples=["Domain-Driven Design: Tackling Complexity in the Heart of Softwares"]
)
page: int = Field(ge=0, example=320)
read_page: int = Field(ge=0, example=120)
page: int = Field(ge=0, examples=[320])
read_page: int = Field(ge=0, examples=[120])

@validator("read_page")
def _validate_read_page(cls, v, values, **kwargs):
Expand Down
8 changes: 6 additions & 2 deletions dddpy/usecase/book/book_command_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def create_book(self, data: BookCreateModel) -> Optional[BookReadModel]:
raise NotImplementedError

@abstractmethod
def update_book(self, book_id: str, data: BookUpdateModel) -> Optional[BookReadModel]:
def update_book(
self, book_id: str, data: BookUpdateModel
) -> Optional[BookReadModel]:
raise NotImplementedError

@abstractmethod
Expand Down Expand Up @@ -78,7 +80,9 @@ def create_book(self, data: BookCreateModel) -> Optional[BookReadModel]:

return BookReadModel.from_entity(cast(Book, created_book))

def update_book(self, book_id: str, data: BookUpdateModel) -> Optional[BookReadModel]:
def update_book(
self, book_id: str, data: BookUpdateModel
) -> Optional[BookReadModel]:
try:
existing_book = self.uow.book_repository.find_by_id(book_id)
if existing_book is None:
Expand Down
14 changes: 7 additions & 7 deletions dddpy/usecase/book/book_query_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
class BookReadModel(BaseModel):
"""BookReadModel represents data structure as a read model."""

id: str = Field(example="vytxeTZskVKR7C7WgdSP3d")
isbn: str = Field(example="978-0321125217")
id: str = Field(examples=["vytxeTZskVKR7C7WgdSP3d"])
isbn: str = Field(examples=["978-0321125217"])
title: str = Field(
example="Domain-Driven Design: Tackling Complexity in the Heart of Softwares"
examples=["Domain-Driven Design: Tackling Complexity in the Heart of Softwares"]
)
page: int = Field(ge=0, example=320)
read_page: int = Field(ge=0, example=120)
created_at: int = Field(example=1136214245000)
updated_at: int = Field(example=1136214245000)
page: int = Field(ge=0, examples=[320])
read_page: int = Field(ge=0, examples=[120])
created_at: int = Field(examples=[1136214245000])
updated_at: int = Field(examples=[1136214245000])

class Config:
orm_mode = True
Expand Down
Loading