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

サポートするPythonバージョンを「3.8以上」から「3.9以上」に変更しました。 #137

Merged
merged 17 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
141 changes: 43 additions & 98 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,132 +1,77 @@
FROM ubuntu:18.04 as devcontainer

RUN set -x \
&& sed -i.bak -r 's!(deb|deb-src) \S+!\1 mirror://mirrors.ubuntu.com/mirrors.txt!' /etc/apt/sources.list

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
FROM ubuntu:22.04

# Install prerequisites
RUN set -x \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
gnupg2 \
software-properties-common \
language-pack-ja \
tzdata \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
curl \
lsb-release \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

# Set locale & timezone
RUN update-locale LANG=ja_JP.UTF-8 LANGUAGE=ja_JP:ja \
&& ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&& echo 'Asia/Tokyo' >/etc/timezone
&& echo "Asia/Tokyo" > /etc/timezone

# create vscode user
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
sudo \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
&& echo "vscode ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers.d/ALL \
&& groupadd \
--gid 5000 \
vscode \
&& useradd \
--uid 5000 \
--gid 5000 \
--home-dir /home/vscode \
--create-home \
--shell /bin/bash \
vscode
ENV LANG=ja_JP.UTF-8
ENV LC_ALL=ja_JP.UTF-8
ENV LC_CTYPE=ja_JP.UTF-8

# 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 \
&& chown -R vscode:vscode /home/vscode/.vscode-server /home/vscode/.vscode-server-insiders \
&& ln -s /home/vscode/.vscode-server/extensions /home/vscode/.vscode-server-insiders/extensions
&& sed -i.bak -r 's!(deb|deb-src) \S+!\1 http://jp.archive.ubuntu.com/ubuntu/!' /etc/apt/sources.list

# common tools
# Install Ubuntu packages
RUN set -x \
# Python3.12をインストールするために、deadsnakes PPAを追加
&& add-apt-repository ppa:deadsnakes/ppa \
# Install packages
&& apt-get update \
&& apt-get install -y --no-install-recommends \
# python
python3.12-dev \
# common tools
bash-completion \
curl \
build-essential \
git \
gnupg2 \
iputils-ping \
jq \
less \
make \
net-tools \
openssh-client \
sudo \
tar \
time \
unzip \
vim \
wget \
xz-utils \
zip \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

# docker
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common \
&& 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" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
docker-ce-cli \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
&& groupadd --gid 999 docker \
&& usermod -aG docker vscode

# docker compose
ARG COMPOSE_VERSION=1.27.4
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
&& 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 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.2/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
ENV PATH=/usr/local/devcontainer-tool/bin:${PATH}

# python3.8
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
python3.8 \
python3.8-dev \
python3-pip \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
&& ln -s $(which python3.8) /usr/local/bin/python
ENV PIP_DEFAULT_TIMEOUT=100
# Python / pip
RUN ln -s $(which python3.12) /usr/bin/python
RUN curl -sSL https://bootstrap.pypa.io/get-pip.py | python -
ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_NO_CACHE_DIR=on \
PIP_DISABLE_PIP_VERSION_CHECK=on

# poetry
RUN set -x \
&& python -m pip install -U pip setuptools \
&& pip install poetry \
&& sudo -u vscode -i poetry config virtualenvs.in-project true
&& python -m pip install "poetry<1.9"

# fix poetry issue (see: https://github.com/python-poetry/poetry/issues/221)
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
language-pack-en \
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
ENV LC_ALL=C.UTF-8
# Add user / Grant sudo privileges
RUN useradd -m -s /bin/bash -u 5000 -U vscode \
&& echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/ALL

USER vscode

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "bash", "-eux", "/entrypoint.sh" ]
RUN poetry config virtualenvs.in-project true
42 changes: 21 additions & 21 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.0/containers/docker-existing-dockerfile
{
"name": "KCI Python",
"name": "${localWorkspaceFolderBasename}",
"build": {
"dockerfile": "Dockerfile",
"context": ".",
"args": {
"COMPOSE_VERSION": "1.27.4",
},
"target": "devcontainer"
"args": {}
},
"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": [],
"runArgs": [
"--init",
"--net=host",
"--env=ANNOFAB_USER_ID",
"--env=ANNOFAB_PASSWORD"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind,consistency=cached",
"workspaceFolder": "/workspaces",
"postStartCommand": "poetry install",
"extensions": [
"bungcip.better-toml",
"jgclark.vscode-todo-highlight",
"lextudio.restructuredtext",
"mosapride.zenkaku",
"ms-python.python",
"ms-python.vscode-pylance",
"njpwerner.autodocstring",
"streetsidesoftware.code-spell-checker"
]
"customizations": {
"vscode": {
"extensions": [
"mosapride.zenkaku",
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"streetsidesoftware.code-spell-checker",
"bungcip.better-toml",
"njpwerner.autodocstring",
"mechatroner.rainbow-csv",
"lextudio.restructuredtext"
]
}
}
}
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.12"

python:
install:
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
language: python
dist: focal
dist: jammy

python:
- "3.8"
- "3.9"
- "3.10"
- "3.11-dev"
- "3.11"
- "3.12"

install:
- pip install pip --upgrade
- pip install poetry==1.1.15 setuptools==50.3.2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poetryはsetupptolsは必須としていないので、削除しました。
https://python-poetry.org/docs/configuration#virtualenvsoptionsno-setuptools

- pip install poetry==1.8
- poetry install

script:
Expand Down
33 changes: 3 additions & 30 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,21 @@
},
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
"python.pythonPath": ".venv/bin/python",
"python.languageServer": "Pylance",
"python.autoComplete.addBrackets": true,
"python.autoComplete.extraPaths": [
".venv/lib/python3.8/site-packages/"
".venv/lib/python3.12/site-packages/"
],
// "poetry run"コマンドで実行することを想定しているので、venv環境を自動的にactivateしないようにする
"python.terminal.activateEnvironment":false,

"python.formatting.blackPath": ".venv/bin/black",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode 1.91.1で警告が出るので削除しました。

"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": ".venv/bin/pylint",
"python.linting.pylintArgs": [
"--rcfile setup.cfg",
],
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": ".venv/bin/flake8",
"python.linting.flake8Args": [],
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": ".venv/bin/mypy",
"python.linting.mypyArgs": [],
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.prospectorEnabled": false,
"python.linting.pydocstyleEnabled": false,
"python.linting.pycodestyleEnabled": false,
"python.linting.ignorePatterns": [
".vscode/*.py",
"**/site-packages/**/*.py",
"docs/**/*.py"
],
"python.analysis.extraPaths": [
".venv/lib/python3.8/site-packages/"
".venv/lib/python3.12/site-packages/"
],
"python.analysis.completeFunctionParens": true,
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode 1.91.1の警告に従い修正しました。

},
},
"python.testing.autoTestDiscoverOnSaveEnabled": false,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ annofab-3dpc-editor-cli 0.2.2a1
## 開発環境

* poetry
* Poetry version 1.0.5
* python 3.8
* Poetry version 1.8.3
* python 3.12


### 開発環境初期化
Expand All @@ -54,7 +54,7 @@ python 3.8 および poetry の導入がなされた `docker/Dockerfile` を用

### pyenv

システムにpython 3.8を直接インストールして使うなら`pyenv`は要らない
システムにpython 3.12を直接インストールして使うなら`pyenv`は要らない

#### 前提ライブラリなどのインストール

Expand Down Expand Up @@ -102,8 +102,8 @@ eval "$(pyenv virtualenv-init -)"
```

```
pyenv install 3.8.3
pyenv global 3.8.3
pyenv install 3.12.4
pyenv global 3.12.4
```


Expand Down
2 changes: 1 addition & 1 deletion anno3d/annofab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def open_resource(self) -> Generator[Resource, None, None]:
endpoint = (
self._annofab_endpoint if self._annofab_endpoint is not None else annofabapi.resource.DEFAULT_ENDPOINT_URL
)
resource = annofabapi.build(self._annofab_id, self._annofab_pass, endpoint)
resource = annofabapi.build(self._annofab_id, self._annofab_pass, endpoint_url=endpoint)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新の annofabapi 0.74.0でエラーが出ないように修正しました。

try:
yield resource
finally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def zoom_out_segment_field_values(label: LabelV3, values: Optional[SegmentFieldV
return replace(
# encode_jsonがTrueの時、Valueを全てJsonに直接変換可能な型に変換しようとする
label,
field_values=values.to_dict(encode_json=True),
field_values=values.to_dict(encode_json=True), # type: ignore[arg-type]
)
else:
return label
Expand All @@ -43,7 +43,7 @@ def zoom_out_cuboid_field_values(label: LabelV3, values: Optional[CuboidFieldVal
return replace(
# encode_jsonがTrueの時、Valueを全てJsonに直接変換可能な型に変換しようとする
label,
field_values=values.to_dict(encode_json=True),
field_values=values.to_dict(encode_json=True), # type: ignore[arg-type]
)
else:
return label
Expand Down
2 changes: 1 addition & 1 deletion anno3d/annofab/specifiers/project_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def zoom_out(anno: AS, labels: List[LabelV3]) -> AS:

@classmethod
def label(cls, label_id: str) -> DataSpecifier[AS, Optional[LabelV3]]:
predicate: Callable[[LabelV3], bool] = lambda l: l.label_id == label_id
predicate: Callable[[LabelV3], bool] = lambda l: l.label_id == label_id # noqa: E741
return cls.labels.zoom(GenList.gen_zoom_in(predicate), GenList.gen_zoom_out(predicate))

class Additionals:
Expand Down
2 changes: 1 addition & 1 deletion anno3d/annofab/specifiers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GenList:
@staticmethod
def gen_zoom_in(pred: Callable[[A], bool]) -> Callable[[List[A]], Optional[A]]:
"""Listの要素のうち最初に条件を満たす値を取得するzoom_inを生成する"""
return lambda l: more_itertools.first_true(l, pred=pred)
return lambda l: more_itertools.first_true(l, pred=pred) # noqa: E741

@staticmethod
def gen_zoom_out(pred: Callable[[A], bool]) -> Callable[[List[A], Optional[A]], List[A]]:
Expand Down
Loading