From 175fc48d59f194ff8b1e0f2d631952b2add4e192 Mon Sep 17 00:00:00 2001 From: d-eigo-hara Date: Sat, 12 Oct 2024 00:04:22 +0000 Subject: [PATCH 1/8] fix: env --- .devcontainer/Dockerfile | 25 +++++++++---------------- .devcontainer/devcontainer.json | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index eeaeb04..6c57558 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,8 @@ FROM debian:bookworm-slim AS builder -LABEL maintainer="a5chin " +ENV CARGO_HOME="/opt/.cargo" + +SHELL [ "/bin/bash", "-o", "pipefail", "-c" ] WORKDIR /opt @@ -9,28 +11,19 @@ WORKDIR /opt RUN apt-get update && \ apt-get install -y --no-install-recommends ca-certificates curl -SHELL [ "/bin/bash", "-o", "pipefail", "-c" ] - -# Download the latest installer -ADD https://astral.sh/uv/install.sh uv-installer.sh - -# Run the installer then remove it -RUN sh uv-installer.sh +# Run uv installer +RUN curl -LsSf https://astral.sh/uv/install.sh | sh FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm -ENV CARGO_HOME="/opt/.cargo/bin" -ENV PATH="$CARGO_HOME/:$PATH" +LABEL maintainer="a5chin " +ENV CARGO_HOME="/opt/.cargo" +ENV PATH="$CARGO_HOME/bin/:$PATH" ENV PYTHONUNBUFFERED=True ENV UV_LINK_MODE=copy WORKDIR /opt -COPY --from=builder /root/.cargo/bin/uv $CARGO_HOME/uv -COPY ./.python-version ./ - -RUN uv python pin "$(cat .python-version)" - -RUN chown -R vscode $CARGO_HOME +COPY --from=builder --chown=vscode: $CARGO_HOME $CARGO_HOME diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a159c07..f3491c3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,7 +37,7 @@ } } }, - "postCreateCommand": "uv sync --dev", + "postCreateCommand": "uv python pin $(cat .python-version) && uv sync --dev", "postStartCommand": "uv run pre-commit install", "remoteUser": "vscode" } From 306f4a9d4eb06824ce74e09b6f7b84ae174aeac9 Mon Sep 17 00:00:00 2001 From: d-eigo-hara Date: Sat, 12 Oct 2024 00:06:12 +0000 Subject: [PATCH 2/8] add: Dockerfile when Rust is required --- .devcontainer/buildWithRust.Dockerfile | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .devcontainer/buildWithRust.Dockerfile diff --git a/.devcontainer/buildWithRust.Dockerfile b/.devcontainer/buildWithRust.Dockerfile new file mode 100644 index 0000000..711ca36 --- /dev/null +++ b/.devcontainer/buildWithRust.Dockerfile @@ -0,0 +1,33 @@ +FROM debian:bookworm-slim AS builder + +ENV CARGO_HOME="/opt/.cargo" +ENV RUSTUP_HOME="/opt/.rustup" + +SHELL [ "/bin/bash", "-o", "pipefail", "-c" ] + +WORKDIR /opt + +# The installer requires curl (and certificates) to download the release archive +# hadolint ignore=DL3008 +RUN apt-get update && \ + apt-get install -y --no-install-recommends ca-certificates curl + +# Run uv and rustup installer +RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + + +FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm + +LABEL maintainer="a5chin " + +ENV CARGO_HOME="/opt/.cargo" +ENV RUSTUP_HOME="/opt/.rustup" +ENV PATH="$CARGO_HOME/bin/:$PATH" +ENV PYTHONUNBUFFERED=True +ENV UV_LINK_MODE=copy + +WORKDIR /opt + +COPY --from=builder --chown=vscode: $CARGO_HOME $CARGO_HOME +COPY --from=builder $RUSTUP_HOME $RUSTUP_HOME From 2d0e97ee1cbaba64fceb80e353565d69b94848dc Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 00:25:19 +0000 Subject: [PATCH 3/8] fix: README.md --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fb25640..ecef563 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Specifically, you can solve this problem by following the steps below. - [Overview](#overview) - [Contents](#contents) - [Branches](#branches) + - [Settings](#settings) - [Dev Container](#dev-container) - [GitHub Actions](#github-actions) - [Ruff](#ruff) @@ -43,12 +44,22 @@ Specifically, you can solve this problem by following the steps below. - [jupyter](https://github.com/a5chin/python-uv/tree/jupyter) - [rye](https://github.com/a5chin/python-uv/tree/rye)(Archived) +## Settings +- files.insertFinalNewline +- files.trimTrailingWhitespace +- editor.formatOnSave + - dockercompose + - dockerfile + - github-actions-workflow + - json, jsonc + - python + - toml + - yaml + ## Dev Container - `devcontainer.json` - - settings - - formatOnSave by Ruff - features - - pre-commit + - hadolint - extentions - [charliermarsh.ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) - [codezombiech.gitignore](https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore) @@ -71,10 +82,15 @@ Specifically, you can solve this problem by following the steps below. - `pyright` - `pytest` - `ruff` +- `buildWithRust.Dockerfile` + - Use the Rust compiler when you need it! + - Fix dockerfile in `.devcontainer/devcontainer.json` ## GitHub Actions - `docker.yml` - Workflow to check if you can build with Docker +- `pyright.yml` + - Workflow to check type - `test.yml` - Workflow to check if all the described tests can be passed with pytest - `ruff.yml` @@ -112,8 +128,6 @@ hodolint Dockerfile ## Appendix ### Install libraries -Only sync based on the production lockfile (`requirements.lock`) instead of the development lockfile (`requirements-dev.lock`). - ```sh # Install also include develop dependencies uv sync @@ -129,6 +143,7 @@ uv add {libraries} ``` . ├── .devcontainer +│ ├── buildWithRust.Dockerfile │ ├── devcontainer.json │ └── Dockerfile ├── Dockerfile @@ -139,6 +154,7 @@ uv add {libraries} │ ├── dependabot.yml │ └── workflows │ ├── docker.yml +│ ├── pyright.yml │ ├── ruff.yml │ └── test.yml ├── .gitignore From 067985cc37d61d4103815faa18bde1daa94c9032 Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 00:25:40 +0000 Subject: [PATCH 4/8] fix: docker.yml --- .github/workflows/docker.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4ed8498..0a8beca 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -61,3 +61,23 @@ jobs: tags: latest cache-from: type=gha cache-to: type=gha,mode=max + + devcontainer-with-rust: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./.devcontainer/buildWithRust.Dockerfile + push: false + tags: latest + cache-from: type=gha + cache-to: type=gha,mode=max From aca33569017a49d1138eca13cb97af440f9ec396 Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 00:33:18 +0000 Subject: [PATCH 5/8] fix: docker.yml --- .github/workflows/docker.yml | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0a8beca..1ffa1da 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -19,6 +19,30 @@ jobs: with: dockerfile: Dockerfile + lint-devcontainer: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint Dockerfile + uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: .devcontainer/Dockerfile + + lint-devcontainer-with-rust: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint Dockerfile + uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: .devcontainer/Dockerfile + build: runs-on: ubuntu-latest @@ -36,7 +60,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./Dockerfile + file: Dockerfile push: false tags: latest cache-from: type=gha @@ -45,6 +69,9 @@ jobs: devcontainer: runs-on: ubuntu-latest + needs: lint-devcontainer + if: ${{ success() }} + steps: - name: Checkout uses: actions/checkout@v4 @@ -56,7 +83,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./.devcontainer/Dockerfile + file: .devcontainer/Dockerfile push: false tags: latest cache-from: type=gha @@ -65,6 +92,9 @@ jobs: devcontainer-with-rust: runs-on: ubuntu-latest + needs: lint-devcontainer-with-rust + if: ${{ success() }} + steps: - name: Checkout uses: actions/checkout@v4 @@ -76,7 +106,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./.devcontainer/buildWithRust.Dockerfile + file: .devcontainer/buildWithRust.Dockerfile push: false tags: latest cache-from: type=gha From 230438c7a7842fceaaaa5eef7936b9909d0af7ab Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 00:41:23 +0000 Subject: [PATCH 6/8] fix: docker.yml --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1ffa1da..6891721 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -66,7 +66,7 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - devcontainer: + build-devcontainer: runs-on: ubuntu-latest needs: lint-devcontainer @@ -89,7 +89,7 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - devcontainer-with-rust: + build-devcontainer-with-rust: runs-on: ubuntu-latest needs: lint-devcontainer-with-rust From 2f21dc9b64fa5b65d391729ee00b84dbdfe8070e Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 00:42:00 +0000 Subject: [PATCH 7/8] add: python version in pyright.yml --- .github/workflows/pyright.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pyright.yml b/.github/workflows/pyright.yml index c8e3651..5b58806 100644 --- a/.github/workflows/pyright.yml +++ b/.github/workflows/pyright.yml @@ -10,5 +10,11 @@ jobs: type-check: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + steps: - uses: jakebailey/pyright-action@v2 + with: + python-version: ${{ matrix.python-version }} From 4fca3998e880d4e7fdef89d86ee175a62fb638f0 Mon Sep 17 00:00:00 2001 From: a5chin Date: Sat, 12 Oct 2024 14:24:52 +0000 Subject: [PATCH 8/8] fix: ignore file --- .dockerignore | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 6 +- 2 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..53c2d95 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,186 @@ +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] +**/*$py.class + +# C extensions +**/*.so + +# Distribution / packaging +**/.Python +**/build/ +**/develop-eggs/ +**/dist/ +**/downloads/ +**/eggs/ +**/.eggs/ +**/lib/ +**/lib64/ +**/parts/ +**/sdist/ +**/var/ +**/wheels/ +**/share/python-wheels/ +**/*.egg-info/ +**/.installed.cfg +**/*.egg +**/MANIFEST + +# Docker +**/compose.yml +**/docker-compose.yml +**/*Dockerfile +.dockerignore + +# Git +.git +.github +**/.gitignore + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +**/*.manifest +**/*.spec + +# Installer logs +**/pip-log.txt +**/pip-delete-this-directory.txt + +# Unit test / coverage reports +**/htmlcov/ +**/.tox/ +**/.nox/ +**/.coverage +**/.coverage.* +**/.*cache +**/nosetests.xml +**/coverage.xml +**/*.cover +**/*.py,cover +**/.hypothesis/ +**/.pytest_cache/ +**/cover/ + +# Translations +**/*.mo +**/*.pot + +# Django stuff: +**/*.log +**/local_settings.py +**/db.sqlite3 +**/db.sqlite3-journal + +# Flask stuff: +**/instance/ +**/.webassets-cache + +# Scrapy stuff: +**/.scrapy + +# Sphinx documentation +**/docs/_build/ + +# PyBuilder +**/.pybuilder/ +**/target/ + +# Jupyter Notebook +**/.ipynb_checkpoints + +# IPython +**/profile_default/ +**/ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +**/__pypackages__/ + +# Celery stuff +**/celerybeat-schedule +**/celerybeat.pid + +# SageMath parsed files +**/*.sage.py + +# Environments +**/.env +**/.venv +**/env/ +**/venv/ +**/ENV/ +**/env.bak/ +**/venv.bak/ + +# Spyder project settings +**/.spyderproject +**/.spyproject + +# Rope project settings +**/.ropeproject + +# mkdocs documentation +**/site + +# mypy +**/.mypy_cache/ +**/.dmypy.json +**/dmypy.json + +# Pyre type checker +**/.pyre/ + +# pytype static type analyzer +**/.pytype/ + +# Cython debug symbols +**/cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# VS Code +.vscode +.devcontainer + +# Custom +.pre-commit-config.yaml +assets +LICENSE +pyrightconfig.json +README.md +ruff.toml +tests diff --git a/.gitignore b/.gitignore index 68bc17f..3b61d23 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ htmlcov/ .nox/ .coverage .coverage.* -.cache +.*cache nosetests.xml coverage.xml *.cover @@ -106,8 +106,10 @@ ipython_config.py #pdm.lock # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it # in version control. -# https://pdm.fming.dev/#use-with-ide +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control .pdm.toml +.pdm-python +.pdm-build/ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/