Skip to content
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
40 changes: 10 additions & 30 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 as devcontainer
FROM ubuntu:22.04

# Install prerequisites
RUN set -x \
Expand All @@ -23,23 +23,22 @@ ENV LANG ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8
ENV LC_CTYPE ja_JP.UTF-8

# ミラーは遅いのが混じっているので好きなリポジトリに変更すべき
RUN set -x \
&& sed -i.bak -r 's!(deb|deb-src) \S+!\1 mirror://mirrors.ubuntu.com/mirrors.txt!' /etc/apt/sources.list
&& sed -i.bak -r 's!(deb|deb-src) \S+!\1 http://jp.archive.ubuntu.com/ubuntu/!' /etc/apt/sources.list

# Install Ubuntu packages
RUN set -x \
# Add repositories
# for docker
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
# Python3.11をインストールするために、deadsnakes PPAを追加
&& add-apt-repository ppa:deadsnakes/ppa \
# Install packages
&& apt-get update \
&& apt-get install -y --no-install-recommends \
# docker
docker-ce-cli \
# python
python3.10-dev \
python3.11-dev \
python3-pip \
# common tools
bash-completion \
Expand All @@ -61,27 +60,17 @@ RUN set -x \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

# docker compose
# 1系はさすがにバージョン古すぎ、docker compose自体オワコンなので推奨しない
# 使用しない場合は、docker / docker-compose hack in devcontainerのところも変更が必要
# 2系はbash completionスクリプトが存在しないので修正が必要
ARG COMPOSE_VERSION=1.29.2
RUN set -x \
&& curl -fsSL "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose \
&& curl -fsSL -o /etc/bash_completion.d/docker-compose "https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose"

# docker / docker-compose hack in devcontainer
# docker hack in devcontainer
RUN set -x \
&& mkdir -p /usr/local/devcontainer-tool/bin \
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker https://github.com/thamaji/devcontainer-docker/releases/download/v1.0.3/docker \
&& chmod +x /usr/local/devcontainer-tool/bin/docker \
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker-compose https://github.com/thamaji/devcontainer-compose/releases/download/v1.0.3/docker-compose \
&& chmod +x /usr/local/devcontainer-tool/bin/docker-compose
&& chmod +x /usr/local/devcontainer-tool/bin/docker
ENV PATH=/usr/local/devcontainer-tool/bin:${PATH}


# Python / pip
RUN ln -s $(which python3.10) /usr/bin/python
RUN ln -s $(which python3.11) /usr/bin/python
ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_NO_CACHE_DIR=on \
Expand All @@ -102,17 +91,8 @@ RUN useradd -m -s /bin/bash -u 5000 -U vscode \
&& groupadd --gid 999 docker \
&& usermod -aG docker vscode

ADD entrypoint.sh /entrypoint.sh

USER vscode

RUN poetry config virtualenvs.in-project true

# vscode extensions cache
# https://code.visualstudio.com/docs/remote/containers-advanced#_avoiding-extension-reinstalls-on-container-rebuild
RUN set -x \
&& mkdir -p /home/vscode/.vscode-server/extensions /home/vscode/.vscode-server-insiders \
&& ln -s /home/vscode/.vscode-server/extensions /home/vscode/.vscode-server-insiders/extensions


ENTRYPOINT [ "bash", "/entrypoint.sh" ]
ENTRYPOINT [ "bash", "/entrypoint.sh" ]
16 changes: 8 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
"dockerfile": "Dockerfile",
"context": ".",
"args": {},
"target": "devcontainer"
},
"containerUser": "vscode",
"remoteUser": "vscode",
"updateRemoteUserUID": true,
"overrideCommand": false,
// 事前にマウントするディレクトリを作成する
// マウント対象のディレクトリを事前に作成する
"initializeCommand": "mkdir -p ${localWorkspaceFolder}/.devcontainer/venv",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
"source=${localWorkspaceFolder}/.devcontainer/.extensions,target=/home/vscode/.vscode-server/extensions,type=bind",
//ホスト側のvenvとコンテナ側のvenvを分離して、ホスト側でもpoetryコマンドを実行できるようにする
// ホスト側のvenvとコンテナ側のvenvを分類して、ホスト側でpoetryコマンドを利用できるようにする
"source=${localWorkspaceFolder}/.devcontainer/venv,target=${containerWorkspaceFolder}/.venv,type=bind"
],
"forwardPorts": [],
Expand All @@ -31,17 +28,20 @@
"CONTAINER_WORKSPACE": "${containerWorkspaceFolder}",
"LOCAL_WORKSPACE": "${localWorkspaceFolder}"
},
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind,consistency=cached",
"workspaceFolder": "/workspaces",
"postStartCommand": "poetry install --all-extras",
"customizations":{
"vscode":{
"customizations": {
"vscode": {
"extensions": [
"mosapride.zenkaku",
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"streetsidesoftware.code-spell-checker",
"bungcip.better-toml",
"njpwerner.autodocstring",
"dawhite.mustache",
"mechatroner.rainbow-csv",
"lextudio.restructuredtext"
]
}
Expand Down
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- python: 3.8
- python: 3.9
- python: 3.10
- python: 3.11
script:
# 開発環境と同じPythonバージョンのみlintを実行する
- make lint
- python: 3.11
- python: 3.12


Expand Down
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
ifndef SOURCE_FILES
export SOURCE_FILES:=annofabapi
endif
ifndef TEST_FILES
export TEST_FILES:=tests
endif

.PHONY: docs lint test format test publish

format:
poetry run autoflake --in-place --remove-all-unused-imports --ignore-init-module-imports --recursive annofabapi tests
poetry run isort annofabapi tests
poetry run black annofabapi tests
poetry run ruff format ${SOURCE_FILES} ${TEST_FILES}
poetry run ruff check ${SOURCE_FILES} ${TEST_FILES} --fix-only --exit-zero

lint:
poetry run mypy annofabapi tests
poetry run flake8 annofabapi tests
poetry run pylint --jobs=0 annofabapi
poetry run ruff check ${SOURCE_FILES}
# テストコードはチェックを緩和する
# pygrep-hooks, flake8-datetimez, line-too-long, flake8-annotations, unused-noqa
poetry run ruff check ${TEST_FILES} --ignore PGH,DTZ,E501,ANN,RUF100,G004
poetry run mypy ${SOURCE_FILES} ${TEST_FILES}
# テストコードはチェックを緩和するためpylintは実行しない
poetry run pylint --jobs=0 ${SOURCE_FILES}


test:
# 並列で実行するとエラーになるので、シーケンシャルで実行する
poetry run pytest --cov=annofabapi --cov-report=html tests
poetry run pytest --cov=${SOURCE_FILES} --cov-report=html ${TEST_FILES}

publish:
poetry publish --build
Expand Down
26 changes: 10 additions & 16 deletions annofabapi/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from typing import Optional


def _issue_deprecated_warning_with_class(
cls, stacklevel: int, deprecated_date: str, new_class_name: Optional[str] = None
):
def _issue_deprecated_warning_with_class(cls, stacklevel: int, deprecated_date: str, new_class_name: Optional[str] = None): # noqa: ANN001
"""非推奨なクラスに対する警告メッセージを出力する。"""
old_class_name = f"{cls.__module__}.{cls.__name__}"
message = f"deprecated: '{old_class_name}'は{deprecated_date}以降に廃止します。"
Expand All @@ -15,36 +13,32 @@ def _issue_deprecated_warning_with_class(
warnings.warn(message, FutureWarning, stacklevel=stacklevel)


def _process_class(cls, deprecated_date: str, new_class_name: Optional[str] = None):
def decorator(function):
def _process_class(cls, deprecated_date: str, new_class_name: Optional[str] = None): # noqa: ANN001
def decorator(function): # noqa: ANN001
@wraps(function)
def wrapped(*args, **kwargs):
_issue_deprecated_warning_with_class(
cls, stacklevel=3, deprecated_date=deprecated_date, new_class_name=new_class_name
)
_issue_deprecated_warning_with_class(cls, stacklevel=3, deprecated_date=deprecated_date, new_class_name=new_class_name)
return function(*args, **kwargs)

return wrapped

cls.__init__ = decorator(cls.__init__) # type: ignore
cls.__init__ = decorator(cls.__init__)
return cls


def _process_enum_class(cls, deprecated_date: str, new_class_name: Optional[str] = None):
def getattribute(self, name):
_issue_deprecated_warning_with_class(
cls, stacklevel=4, deprecated_date=deprecated_date, new_class_name=new_class_name
)
def _process_enum_class(cls, deprecated_date: str, new_class_name: Optional[str] = None): # noqa: ANN001
def getattribute(self, name): # noqa: ANN001
_issue_deprecated_warning_with_class(cls, stacklevel=4, deprecated_date=deprecated_date, new_class_name=new_class_name)
return super(type(self), self).__getattribute__(name)

cls.__getattribute__ = getattribute
return cls


def deprecated_class(_cls=None, *, deprecated_date: str, new_class_name: Optional[str] = None):
def deprecated_class(_cls=None, *, deprecated_date: str, new_class_name: Optional[str] = None): # noqa: ANN001
"""クラスを非推奨にします。"""

def wrap(cls):
def wrap(cls): # noqa: ANN001
if issubclass(cls, enum.Enum):
return _process_enum_class(cls, deprecated_date=deprecated_date, new_class_name=new_class_name)
else:
Expand Down
Loading