Skip to content

Commit

Permalink
🎉 init: pyproject init
Browse files Browse the repository at this point in the history
  • Loading branch information
nishide-dev committed Apr 20, 2024
0 parents commit e07d164
Show file tree
Hide file tree
Showing 16 changed files with 592 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM debian:bullseye-slim as builder

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 \
curl

SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
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

COPY ./.python-version ./pyproject.toml ./requirements* README.md ./
RUN rye pin "$(cat .python-version)" && \
rye sync


FROM mcr.microsoft.com/vscode/devcontainers/base:bullseye
COPY --from=builder /opt/rye /opt/rye

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"
ENV PYTHONUNBUFFERED True

RUN rye config --set-bool behavior.global-python=true && \
rye config --set-bool behavior.use-uv=true

RUN chown -R vscode $RYE_HOME
55 changes: 55 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "aws-lambda-python-template",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/dhoeric/features/hadolint:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"codezombiech.gitignore",
"eamodio.gitlens",
"exiasr.hadolint",
"kevinrose.vsc-python-indent",
"mosapride.zenkaku",
"ms-azuretools.vscode-docker",
"ms-python.python",
"njpwerner.autodocstring",
"oderwat.indent-rainbow",
"pkief.material-icon-theme",
"shardulm94.trailing-spaces",
"usernamehw.errorlens",
"yzhang.markdown-all-in-one",
"mhutchie.git-graph",
"GitHub.copilot",
"seatonjiang.gitmoji-vscode"
],
"settings": {
"python.defaultInterpreterPath": "/opt/rye/shims/python",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
},
"editor.formatOnSave": true
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
}
}
}
},
"postStartCommand": "pre-commit install",
"remoteUser": "vscode"
}
63 changes: 63 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile

build:
runs-on: ubuntu-latest

needs: lint
if: ${{ success() }}

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@v5
with:
context: .
file: ./Dockerfile
push: false
tags: latest
cache-from: type=gha
cache-to: type=gha,mode=max

devcontainer:
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@v5
with:
context: .
file: ./.devcontainer/Dockerfile
push: false
tags: latest
cache-from: type=gha
cache-to: type=gha,mode=max
68 changes: 68 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Ruff

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
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: 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
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
pytest:
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: Run Pytest if directory exists
run: |
if [ -d "./tests/" ]; then
rye run pytest -s
fi
Loading

0 comments on commit e07d164

Please sign in to comment.