Skip to content

Commit

Permalink
Merge pull request #2 from hollanbm/poetry-devcontainer
Browse files Browse the repository at this point in the history
Add Poetry, Devcontainer, Ruff Linter
  • Loading branch information
Woahai321 authored Sep 26, 2024
2 parents 2721093 + f40ae28 commit 457b84b
Show file tree
Hide file tree
Showing 12 changed files with 1,316 additions and 153 deletions.
23 changes: 23 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG PYTHON_VERSION=3.9
FROM mcr.microsoft.com/devcontainers/python:${PYTHON_VERSION}

USER root

RUN apt-get update -y -qq && \
apt-get dist-upgrade -y -qq && \
apt-get autoremove -y -qq

# git safe directories
RUN git config --global --add safe.directory "*"

RUN apt-get -y -qq install \
fzf \
jq \
yq \
zsh

RUN pip install pipx
RUN pipx --global ensurepath
RUN pipx --global install poetry==1.8.3 ruff pre-commit

USER vscode
73 changes: 73 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.base.schema.json",
"name": "imdb-to-overseerr devContainer",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"plugins": "git poetry poetry-env zsh-autosuggestions zsh-syntax-highlighting",
"omzPlugins": "https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-autosuggestions"
},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}
},
"containerEnv": {
"POETRY_VIRTUALENVS_IN_PROJECT": "1",
"POETRY_VIRTUALENVS_CREATE": "true"
},
"mounts": [],
"postCreateCommand": "zsh .devcontainer/postCreateCommand.sh",
"customizations": {
"vscode": {
"settings": {
"editor.formatOnSave": false,
"editor.tabSize": 2,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"files": {
"eol": "\n",
"trimTrailingWhitespace": true,
"trimTrailingWhitespaceInRegexAndStrings": true,
"insertFinalNewline": true
},
"[python]": {
"editor.formatOnSave": false,
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python": {
"terminal": {
"activateEnvironment": false
},
"analysis": {
"autoFormatStrings": true,
"defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python",
"extraPaths": []
}
}
},
"extensions": [
"charliermarsh.ruff",
"KevinRose.vsc-python-indent",
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"mutantdino.resourcemonitor",
"njpwerner.autodocstring",
"njqdev.vscode-python-typehint",
"oderwat.indent-rainbow",
"redhat.vscode-yaml",
"VisualStudioExptTeam.vscodeintellicode"
]
}
}
}
11 changes: 11 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/zsh

git config --global --add safe.directory "*"

poetry install --no-interaction --no-ansi --quiet

# activate venv
source $(poetry env info --path)/bin/activate

# setup pre-commit hook
pre-commit install
59 changes: 59 additions & 0 deletions .github/workflows/python-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Python package

on:
push:
branches:
- main
pull_request:

jobs:
python-ci:
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
architecture: "x64"

#----------------------------------------------
# install & configure poetry
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
run: poetry install --no-interaction --no-root

#----------------------------------------------
# Permanent venv activation
#----------------------------------------------
- name: Activate virtualenv
run: |
source .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
#----------------------------------------------
# run test suite and output coverage file
#----------------------------------------------
# - name: Test with pytest
# run: |
# pytest --cov-branch --cov=src --cov-report=xml tests

#----------------------------------------------
# lint and formatting
#----------------------------------------------
- name: Lint with Ruff
run: |
ruff check --output-format=github .
Loading

0 comments on commit 457b84b

Please sign in to comment.