From 39621f1a6641cb2ba0232e9997275886f27db2a1 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 00:22:11 +0000 Subject: [PATCH 01/27] fix: workflows --- .github/workflows/ruff.yml | 7 ++++++- .github/workflows/test.yml | 11 ++++++++--- Dockerfile | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index fcac7c3..629b73b 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -18,8 +18,13 @@ jobs: uses: actions/checkout@v4 - name: Install Rye + run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash + + - name: Add to Path + run: source "$HOME/.rye/env" + + - name: Set Rye Config run: | - curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash rye config --set-bool behavior.global-python=true rye config --set-bool behavior.use-uv=true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eff4992..4862776 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Ruff +name: Test on: push: @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - ci: + pytest: runs-on: ubuntu-latest strategy: matrix: @@ -18,8 +18,13 @@ jobs: uses: actions/checkout@v4 - name: Install Rye + run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash + + - name: Add to Path + run: source "$HOME/.rye/env" + + - name: Set Rye Config run: | - curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash rye config --set-bool behavior.global-python=true rye config --set-bool behavior.use-uv=true diff --git a/Dockerfile b/Dockerfile index e2c9cc1..9080af2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV RYE_HOME="/opt/rye" ENV PATH="$RYE_HOME/shims:$PATH" RUN apt-get update && \ - apt-get install -y --no-install-recommends curl \ + apt-get install -y --no-install-recommends \ ca-certificates \ curl From 6a86564ff7d6f8b2a91981eb62eaf595dd58bc93 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 00:23:24 +0000 Subject: [PATCH 02/27] delete: main.py --- main.py | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index 92f1d68..0000000 --- a/main.py +++ /dev/null @@ -1,18 +0,0 @@ -def another_test_function(tmp: str = 1) -> str: - """_summary_. - - Args: - ---- - tmp (int, optional): _description_. Defaults to 1. - - Returns: - ------- - 1: _description_ - - """ - return tmp - - -if __name__ == "__main__": - another_test_function() - a = ("kljsg",) From 7282ba3bd71d86987b0e02582a5ca1841651242e Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 00:32:22 +0000 Subject: [PATCH 03/27] fix: path --- .github/workflows/ruff.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 629b73b..dd2f559 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -21,7 +21,7 @@ jobs: run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - name: Add to Path - run: source "$HOME/.rye/env" + run: echo 'source "$HOME/.rye/env"' >> ~/.bashrc - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4862776..43d3b49 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - name: Add to Path - run: source "$HOME/.rye/env" + run: echo 'source "$HOME/.rye/env"' >> ~/.bashrc - name: Set Rye Config run: | From b51696169dbc0e4c7871ad51817531c279f13cd9 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 00:44:49 +0000 Subject: [PATCH 04/27] fix: dir for rye --- .github/workflows/ruff.yml | 6 ++++-- .github/workflows/test.yml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index dd2f559..0ef9b8b 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -18,10 +18,12 @@ jobs: uses: actions/checkout@v4 - name: Install Rye - run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash + run: | + cd /opt + curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - name: Add to Path - run: echo 'source "$HOME/.rye/env"' >> ~/.bashrc + run: echo 'source "/opt/rye/shims"' >> ~/.bashrc - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43d3b49..90ae14b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,12 @@ jobs: uses: actions/checkout@v4 - name: Install Rye - run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash + run: | + cd /opt + curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - name: Add to Path - run: echo 'source "$HOME/.rye/env"' >> ~/.bashrc + run: echo 'source "/opt/rye/shims"' >> ~/.bashrc - name: Set Rye Config run: | From b86185eaa2c731105f047206165a810a95d051b4 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:01:29 +0000 Subject: [PATCH 05/27] fix: env --- .github/workflows/ruff.yml | 4 +--- .github/workflows/test.yml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 0ef9b8b..e3f51ac 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -21,9 +21,7 @@ jobs: run: | cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - - - name: Add to Path - run: echo 'source "/opt/rye/shims"' >> ~/.bashrc + echo 'source "/opt/rye/shims"' >> $GITHUB_ENV - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90ae14b..25ac7ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,7 @@ jobs: run: | cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - - - name: Add to Path - run: echo 'source "/opt/rye/shims"' >> ~/.bashrc + echo 'source "/opt/rye/shims"' >> $GITHUB_ENV - name: Set Rye Config run: | From 38245ad1e63571caa5cb2789987dfa2be3994ddd Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:12:57 +0000 Subject: [PATCH 06/27] fix: source --- .github/workflows/ruff.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index e3f51ac..ebf762f 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -21,7 +21,7 @@ jobs: run: | cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - echo 'source "/opt/rye/shims"' >> $GITHUB_ENV + source "/opt/rye/env" - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25ac7ec..8aff34e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: run: | cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - echo 'source "/opt/rye/shims"' >> $GITHUB_ENV + source "/opt/rye/env" - name: Set Rye Config run: | From e91801aa66fe5d4425eac5c3043a3682ddcac4b8 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:16:32 +0000 Subject: [PATCH 07/27] fix: source --- .github/workflows/ruff.yml | 3 +-- .github/workflows/test.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index ebf762f..2cc04ef 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -19,9 +19,8 @@ jobs: - name: Install Rye run: | - cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "/opt/rye/env" + source "$HOME/.rye/env" - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8aff34e..f1888d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,9 +19,8 @@ jobs: - name: Install Rye run: | - cd /opt curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "/opt/rye/env" + source "$HOME/.rye/env" - name: Set Rye Config run: | From ea0dbaaeb61c316375ab62b3192bfe43275e90d7 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:33:09 +0000 Subject: [PATCH 08/27] add: export --- .github/workflows/ruff.yml | 4 +++- .github/workflows/test.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 2cc04ef..e33532c 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -20,7 +20,8 @@ jobs: - name: Install Rye run: | curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "$HOME/.rye/env" + export RYE_HOME="$HOME/.rye" + export PATH="$RYE_HOME/shims:$PATH" - name: Set Rye Config run: | @@ -29,6 +30,7 @@ jobs: - name: Set up Python ${{ matrix.python-version }} run: | + export PYTHONUNBUFFERED=1 rye pin ${{ matrix.python-version }} rye sync diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1888d0..6254b7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,8 @@ jobs: - name: Install Rye run: | curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "$HOME/.rye/env" + export RYE_HOME="$HOME/.rye" + export PATH="$RYE_HOME/shims:$PATH" - name: Set Rye Config run: | @@ -29,6 +30,7 @@ jobs: - name: Set up Python ${{ matrix.python-version }} run: | + export PYTHONUNBUFFERED=1 rye pin ${{ matrix.python-version }} rye sync From b973b08b4dcccbe7326985c4a32ba5f167b2bdb4 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:35:41 +0000 Subject: [PATCH 09/27] fix: source --- .github/workflows/ruff.yml | 3 +-- .github/workflows/test.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index e33532c..4a9a49b 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -20,8 +20,7 @@ jobs: - name: Install Rye run: | curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - export RYE_HOME="$HOME/.rye" - export PATH="$RYE_HOME/shims:$PATH" + source "$HOME/.rye/env" - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6254b7f..bfd2ac0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,8 +20,7 @@ jobs: - name: Install Rye run: | curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - export RYE_HOME="$HOME/.rye" - export PATH="$RYE_HOME/shims:$PATH" + source "$HOME/.rye/env" - name: Set Rye Config run: | From ce5b7ccf1dd9d6d5cb8eedcd0e5ba5da72da321e Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 01:45:37 +0000 Subject: [PATCH 10/27] fix: uses --- .github/workflows/ruff.yml | 6 +++--- .github/workflows/test.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 4a9a49b..9e37e19 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -18,9 +18,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rye - run: | - curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "$HOME/.rye/env" + uses: eifinger/setup-rye@v2 + with: + enable-cache: true - name: Set Rye Config run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfd2ac0..96fdb12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,9 +18,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rye - run: | - curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash - source "$HOME/.rye/env" + uses: eifinger/setup-rye@v2 + with: + enable-cache: true - name: Set Rye Config run: | From 7a428704b90374ad1ddb519b48899b605f057467 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 02:27:28 +0000 Subject: [PATCH 11/27] fix: pytest --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96fdb12..705ba0c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,5 +33,8 @@ jobs: rye pin ${{ matrix.python-version }} rye sync - - name: Pytest - run: rye run pytest -s + - name: Run Pytest if directory exists + run: | + if [ -d "./tests/" ]: then + rye run pytest -s + fi From 8d410f467302f8c4836b4d1c88dd440c0de16bc3 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 02:32:56 +0000 Subject: [PATCH 12/27] fix: if in test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 705ba0c..3299a06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,6 @@ jobs: - name: Run Pytest if directory exists run: | - if [ -d "./tests/" ]: then + if [ -d "./tests/" ]; then rye run pytest -s fi From 92f401e36b71aec97a1ebf2dedfbe003aeefa058 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:21:03 +0000 Subject: [PATCH 13/27] fix: ruff check --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9baef66..0ea1b68 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: hooks: - id: ruff name: ruff - description: "Run 'ruff' for extremely fast Python linting" + description: "Run 'ruff check' for extremely fast Python linting" args: [ --fix ] - id: ruff-format From 033e493447b40bf95c22d5882a2d198f9701338c Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:21:33 +0000 Subject: [PATCH 14/27] add: extension for markdown --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d14e1c1..7dfee08 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,7 +20,8 @@ "oderwat.indent-rainbow", "pkief.material-icon-theme", "shardulm94.trailing-spaces", - "usernamehw.errorlens" + "usernamehw.errorlens", + "yzhang.markdown-all-in-one" ], "settings": { "python.defaultInterpreterPath": "/opt/rye/shims/python", From af931252b21284f23df3a074e20beebbafb3c09d Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:21:55 +0000 Subject: [PATCH 15/27] update: version --- .github/workflows/build.yml | 4 ++++ .github/workflows/ruff.yml | 3 ++- .github/workflows/test.yml | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index afdca60..f1c1472 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,10 @@ jobs: docker: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 9e37e19..7b7da6c 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -9,9 +9,10 @@ on: jobs: ci: runs-on: ubuntu-latest + strategy: matrix: - python-version: ['3.10', '3.11', '3.12'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3299a06..c1d26b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,9 +9,10 @@ on: jobs: pytest: runs-on: ubuntu-latest + strategy: matrix: - python-version: ['3.10', '3.11', '3.12'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout From 5f560781a4651f5ca2f1ae8605687b393a6d10e1 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:22:18 +0000 Subject: [PATCH 16/27] update: README.md --- README.md | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/README.md b/README.md index e69de29..67a7f04 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,111 @@ +# Python Development Environment Setup with VSCode Dev Container + +
+ +[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://github.com/astral-sh/rye) +[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) + +[![Versions](https://img.shields.io/pypi/pyversions/ruff.svg)]() + +[![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml) +[![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml) +[![Docker](https://github.com/a5chin/python-rye/actions/workflows/build.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/build.yml) + +
+ +## Overview +This repository contains configurations to set up a Python development environment using VSCode's Dev Container feature. +The environment includes Rye, uv, and Ruff. + +## Contents + +### Dev Container +- `devcontainer.json` + - settings + - formatOnSave by Ruff + - features + - pre-commit + - extentions + - charliermarsh.ruff + - codezombiech.gitignore + - eamodio.gitlens + - kevinrose.vsc-python-indent + - mosapride.zenkaku + - ms-python.python + - njpwerner.autodocstring + - oderwat.indent-rainbow + - pkief.material-icon-theme + - shardulm94.trailing-spaces + - usernamehw.errorlens + - yzhang.markdown-all-in-one +- `Dockerfile` + - Rye + - `rye config --set-bool behavior.global-python=true` + - `rye config --set-bool behavior.use-uv=true` + - Ruff + +### GitHub Actions +- `build.yml` + - Workflow to check if you can build with Docker +- `test.yml` + - Workflow to check if all the described tests can be passed with pytest +- `ruff.yml` + - Workflow to check if you can go through Formatter and Linter with Ruff + +### Ruff +Ruff can be used to replace Flake8, Black, isort, pydocstyle, pyupgrade, autoflake, etc., and yet run tens to hundreds of times faster than the individual tools. + +To change the configuration, it is necessary to rewrite ruff.toml, and [it is recommended](https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules) to set it to ignore conflicts such as the following: +```toml +ignore = [ + "COM812", "COM819", + "D100", "D203", "D213", "D300", + "E111", "E114", "E117", + "ISC001", "ISC002", + "Q000", "Q001", "Q002", "Q003", + "W191", +] +``` + +### pre-commit +- `.pre-commit-config.yaml` + - Linter: `ruff check .` + - Formatter: `ruff format .` + +### Install +Only sync based on the production lockfile (`requirements.lock`) instead of the development lockfile (`requirements-dev.lock`). + +```sh +# Install also include develop dependencies +rye sync + +# If you do not want dev dependencies to be installed +rye sync --no-dev +``` + +## Appendix +### The structure of this repository +``` +. +├── .devcontainer +│ ├── devcontainer.json +│ └── Dockerfile +├── Dockerfile +├── .github +│ └── workflows +│ ├── build.yml +│ ├── ruff.yml +│ └── pytest.yml +├── .gitignore +├── LICENSE +├── .pre-commit-config.yaml +├── pyproject.toml +├── .python-version +├── README.md +├── requirements-dev.lock +├── requirements.lock +├── ruff.toml +└── .vscode + └── settings.json +``` From 051d6106ff638c8ddd4797bbb1ea887aeb568d10 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:56:04 +0000 Subject: [PATCH 17/27] fix: python version --- .github/workflows/build.yml | 2 +- .github/workflows/ruff.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1c1472..67ee0f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 7b7da6c..b711d14 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1d26b7..07fc171 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout From 6162955ac22f6cd6bdc7c41ebec8fee4e08c328b Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 09:56:25 +0000 Subject: [PATCH 18/27] update: README.md --- README.md | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 67a7f04..92cd87f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python Development Environment Setup with VSCode Dev Container +# VSCode Dev Container: Python Development with Rye, uv, and Ruff
@@ -6,7 +6,7 @@ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) -[![Versions](https://img.shields.io/pypi/pyversions/ruff.svg)]() +[![Versions](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20-green.svg)](https://github.com/a5chin/python-rye) [![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml) [![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml) @@ -19,6 +19,7 @@ This repository contains configurations to set up a Python development environme The environment includes Rye, uv, and Ruff. ## Contents +The following are the features. ### Dev Container - `devcontainer.json` @@ -27,18 +28,18 @@ The environment includes Rye, uv, and Ruff. - features - pre-commit - extentions - - charliermarsh.ruff - - codezombiech.gitignore - - eamodio.gitlens - - kevinrose.vsc-python-indent - - mosapride.zenkaku - - ms-python.python - - njpwerner.autodocstring - - oderwat.indent-rainbow - - pkief.material-icon-theme - - shardulm94.trailing-spaces - - usernamehw.errorlens - - yzhang.markdown-all-in-one + - [charliermarsh.ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) + - [codezombiech.gitignore](https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore) + - [eamodio.gitlens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) + - [kevinrose.vsc-python-indent](https://marketplace.visualstudio.com/items?itemName=kevinrose.vsc-python-indent) + - [mosapride.zenkaku](https://marketplace.visualstudio.com/items?itemName=mosapride.zenkaku) + - [ms-python.python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) + - [njpwerner.autodocstring](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring) + - [oderwat.indent-rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow) + - [pkief.material-icon-theme](https://marketplace.visualstudio.com/items?itemName=pkief.material-icon-theme) + - [shardulm94.trailing-spaces](https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces) + - [usernamehw.errorlens](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens) + - [yzhang.markdown-all-in-one](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - `Dockerfile` - Rye - `rye config --set-bool behavior.global-python=true` @@ -69,9 +70,15 @@ ignore = [ ``` ### pre-commit -- `.pre-commit-config.yaml` - - Linter: `ruff check .` - - Formatter: `ruff format .` +The `.pre-commit-config.yaml` file can contain scripts to be executed before commit. + +```sh +# Linter +ruff check . --fix + +# Formatter +ruff format . +``` ### Install Only sync based on the production lockfile (`requirements.lock`) instead of the development lockfile (`requirements-dev.lock`). From 5c755fd6e0cad1a5ae0cc6910786552f061c1552 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 10:37:43 +0000 Subject: [PATCH 19/27] update: pre-commit for Docker --- .pre-commit-config.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ea1b68..06b93b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,12 @@ repos: - id: ruff-format name: ruff-format description: "Run 'ruff format' for extremely fast Python formatting" + + - repo: https://github.com/hadolint/hadolint + hooks: + - id: hadolint + name: Lint Dockerfiles + description: Runs hadolint to lint Dockerfiles + language: system + types: ["Dockerfile", ".devcontainer/Dockerfile"] + entry: hadolint From 80d43a524bf4db21524a5ab816fc3132b860a0d0 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 10:38:11 +0000 Subject: [PATCH 20/27] update: README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 92cd87f..3381f81 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,10 @@ The following are the features. - Rye - `rye config --set-bool behavior.global-python=true` - `rye config --set-bool behavior.use-uv=true` - - Ruff + - Only Dev dependencies + - `pre-commit` + - `pytest` + - `ruff` ### GitHub Actions - `build.yml` From bd6929f132fb7180d7c7d2f7015e6a20d07fa85d Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:19:00 +0000 Subject: [PATCH 21/27] add: Lint for Dockerfile --- .github/workflows/{build.yml => docker.yml} | 0 .pre-commit-config.yaml | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) rename .github/workflows/{build.yml => docker.yml} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/docker.yml similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/docker.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06b93b5..c6e706a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,19 +4,21 @@ repos: rev: v0.3.5 hooks: - id: ruff - name: ruff + name: Ruff check description: "Run 'ruff check' for extremely fast Python linting" args: [ --fix ] - id: ruff-format - name: ruff-format + name: Ruff format description: "Run 'ruff format' for extremely fast Python formatting" - repo: https://github.com/hadolint/hadolint + rev: v2.12.0 hooks: - id: hadolint name: Lint Dockerfiles description: Runs hadolint to lint Dockerfiles language: system - types: ["Dockerfile", ".devcontainer/Dockerfile"] + files: ["Dockerfile", ".devcontainer/Dockerfile"] + types: ["dockerfile"] entry: hadolint From f16c48d413c7d93cb37f68b63aa2c1a54d227c94 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:19:33 +0000 Subject: [PATCH 22/27] update: Dockerfile --- .devcontainer/Dockerfile | 1 + Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 387dd85..931cafa 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /opt ENV RYE_HOME="/opt/rye" ENV PATH="$RYE_HOME/shims:$PATH" +# hadolint ignore=DL3008 RUN apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates \ diff --git a/Dockerfile b/Dockerfile index 9080af2..30f5af3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /opt ENV RYE_HOME="/opt/rye" ENV PATH="$RYE_HOME/shims:$PATH" +# hadolint ignore=DL3008 RUN apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates \ From 17f2faf81c40e39f8bd11c167e6c4a34fdfbad0f Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:20:11 +0000 Subject: [PATCH 23/27] update: Actions for Docker --- .github/workflows/docker.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 67ee0f0..038dc8c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,12 +7,20 @@ on: branches: [ main ] jobs: - docker: + lint-prod: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.9', '3.10', '3.11', '3.12'] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint Dockerfile + uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: Dockerfile + + build-prod: + runs-on: ubuntu-latest steps: - name: Checkout From ce4b822d71955f69fb701e8afaa7d6255f74655c Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:29:42 +0000 Subject: [PATCH 24/27] fix: workflows --- .github/workflows/docker.yml | 7 +++++-- .github/workflows/ruff.yml | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 038dc8c..88f6649 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - lint-prod: + lint: runs-on: ubuntu-latest steps: @@ -19,9 +19,12 @@ jobs: with: dockerfile: Dockerfile - build-prod: + build: runs-on: ubuntu-latest + needs: lint-prod + if: ${{ success() }} + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index b711d14..073281f 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - ci: + lint: runs-on: ubuntu-latest strategy: @@ -37,5 +37,32 @@ jobs: - name: Lint run: rye run ruff check --output-format=github . + format: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11', '3.12'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rye + uses: eifinger/setup-rye@v2 + with: + enable-cache: true + + - name: Set Rye Config + run: | + rye config --set-bool behavior.global-python=true + rye config --set-bool behavior.use-uv=true + + - name: Set up Python ${{ matrix.python-version }} + run: | + export PYTHONUNBUFFERED=1 + rye pin ${{ matrix.python-version }} + rye sync + - name: Format run: rye run ruff format . --check --diff From aeeac350547ac3e2650f2a94f768b658bec4c8fe Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:32:49 +0000 Subject: [PATCH 25/27] fix: name for job --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 88f6649..a5de20d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,7 +22,7 @@ jobs: build: runs-on: ubuntu-latest - needs: lint-prod + needs: lint if: ${{ success() }} steps: From e35a221c0982f734d90a26d580dc5961faf84162 Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:41:08 +0000 Subject: [PATCH 26/27] fix: link for docker --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3381f81..3f0c9f6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml) [![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml) -[![Docker](https://github.com/a5chin/python-rye/actions/workflows/build.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/build.yml) +[![Docker](https://github.com/a5chin/python-rye/actions/workflows/build.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/docker.yml)
From a939c6700fad6b7d3f8442bf6f3f75acbe49ab3f Mon Sep 17 00:00:00 2001 From: a5chin Date: Mon, 8 Apr 2024 11:44:20 +0000 Subject: [PATCH 27/27] fix: docker.yml --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f0c9f6..db7bbfa 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml) [![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml) -[![Docker](https://github.com/a5chin/python-rye/actions/workflows/build.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/docker.yml) +[![Docker](https://github.com/a5chin/python-rye/actions/workflows/docker.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/docker.yml) @@ -50,7 +50,7 @@ The following are the features. - `ruff` ### GitHub Actions -- `build.yml` +- `docker.yml` - Workflow to check if you can build with Docker - `test.yml` - Workflow to check if all the described tests can be passed with pytest @@ -104,7 +104,7 @@ rye sync --no-dev ├── Dockerfile ├── .github │ └── workflows -│ ├── build.yml +│ ├── docker.yml │ ├── ruff.yml │ └── pytest.yml ├── .gitignore