Add tooling

This commit is contained in:
pythoninthegrass 2023-08-11 07:08:12 +00:00
parent 6264667aff
commit a786689fcd
11 changed files with 526 additions and 0 deletions

View File

@ -0,0 +1,13 @@
!poetry.lock
!pyproject.toml
.cache
.devcontainer
.git
.gitignore
.pytest_cache
.tool-versions
.venv
.vscode
**/__pycache__
Dockerfile*
README.md

136
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,136 @@
# syntax=docker/dockerfile:1.6
# full semver just for python base image
ARG PYTHON_VERSION=3.11.4
FROM python:${PYTHON_VERSION}-slim-bullseye AS builder
# avoid stuck build due to user prompt
ARG DEBIAN_FRONTEND=noninteractive
# update apt repos and install dependencies
RUN apt -qq update && apt -qq install \
--no-install-recommends -y \
curl \
gcc \
libpq-dev \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# pip env vars
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
# poetry env vars
ENV POETRY_HOME="/opt/poetry"
ENV POETRY_VERSION=1.5.1
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV POETRY_NO_INTERACTION=1
# path
ENV VENV="/opt/venv"
ENV PATH="$POETRY_HOME/bin:$VENV/bin:$PATH"
COPY requirements.txt requirements.txt
RUN python -m venv $VENV \
&& . "${VENV}/bin/activate"\
&& python -m pip install "poetry==${POETRY_VERSION}" \
&& python -m pip install -r requirements.txt
FROM python:${PYTHON_VERSION}-slim-bullseye AS runner
# setup standard non-root user for use downstream
ENV USER_NAME=appuser
ENV USER_GROUP=appuser
ENV HOME="/home/${USER_NAME}"
ENV HOSTNAME="${HOST:-localhost}"
ENV VENV="/opt/venv"
ENV PATH="${VENV}/bin:${VENV}/lib/python${PYTHON_VERSION}/site-packages:/usr/local/bin:${HOME}/.local/bin:/bin:/usr/bin:/usr/share/doc:$PATH"
# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
# workers per core
# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/blob/master/README.md#web_concurrency
ENV WEB_CONCURRENCY=2
# avoid stuck build due to user prompt
ARG DEBIAN_FRONTEND=noninteractive
# install dependencies
RUN apt -qq update && apt -qq install \
--no-install-recommends -y \
bat \
curl \
dpkg \
git \
iputils-ping \
lsof \
p7zip \
perl \
shellcheck \
tldr \
tree \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd $USER_NAME \
&& useradd -m $USER_NAME -g $USER_GROUP
# create read/write dirs
RUN <<EOF
#!/usr/bin/env bash
mkdir -p /app/{certs,staticfiles}
chown -R "${USER_NAME}:${USER_GROUP}" /app/
EOF
USER $USER_NAME
WORKDIR $HOME
COPY --from=builder --chown=${USER_NAME}:${USER_GROUP} $VENV $VENV
# qol: tooling
RUN <<EOF
#!/usr/bin/env bash
# gh
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
apt update && apt install gh -y
apt remove dpkg -y
rm -rf /var/lib/apt/lists/*
# fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
yes | ~/.fzf/install
EOF
# qol: .bashrc
RUN tee -a $HOME/.bashrc <<EOF
# shared history
HISTFILE=/var/tmp/.bash_history
HISTFILESIZE=100
HISTSIZE=100
stty -ixon
[ -f ~/.fzf.bash ] && . ~/.fzf.bash
# aliases
alias ..='cd ../'
alias ...='cd ../../'
alias ll='ls -la --color=auto'
EOF
# $PATH
ENV PATH=$VENV_PATH/bin:$HOME/.local/bin:$PATH
# port needed by app
EXPOSE 8000
CMD ["sleep", "infinity"]

View File

@ -0,0 +1,32 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Dev Environment",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"aaron-bond.better-comments",
"codezombiech.gitignore",
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"GitHub.copilot-chat",
"GitHub.copilot",
"mads-hartmann.bash-ide-vscode",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.atom-keybindings",
"ms-vsliveshare.vsliveshare",
"redhat.vscode-yaml",
"timonwong.shellcheck",
"yzhang.markdown-all-in-one"
]
}
},
// "forwardPorts": [
// 8080,
// 8081
// ]
}

View File

@ -0,0 +1,21 @@
asttokens==2.2.1
backcall==0.2.0
decorator==5.1.1
executing==1.2.0
ipython==8.14.0
jedi==0.19.0
markdown-it-py==3.0.0
matplotlib-inline==0.1.6
mdurl==0.1.2
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.39
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.16.1
rich==13.5.2
six==1.16.0
stack-data==0.6.2
traitlets==5.9.0
wcwidth==0.2.6

34
.editorconfig Normal file
View File

@ -0,0 +1,34 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines and whitespace cleanup
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
insert_final_newline = true
# Protect whitespace in markdown files
[*.md]
trim_trailing_whitespace = false
# general formatting
[*.{bash,go,sh,zsh,justfile,Makefile}]
indent_style = tab
indent_size = 4
# Set default charset
[*.{html,xml,js,css,py}]
charset = utf-8
# python
[*.py]
indent_style = space
indent_size = 4
# webdev et al
[*.{html,xml,js,css,json,gql,lua,tf,tfvars,yml,yaml}]
indent_style = space
indent_size = 2

18
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,18 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#directory
version: 2
updates:
- package-ecosystem: "pip" # package manager
directory: "/" # Files stored in repository root
schedule:
interval: "weekly"
day: "saturday"
time: "10:00"
timezone: "America/Chicago"
open-pull-requests-limit: 5
versioning-strategy: increase-if-necessary

163
.gitignore vendored Normal file
View File

@ -0,0 +1,163 @@
# ETC
*.out
# 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
# 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/#use-with-ide
.pdm.toml
# 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/

1
.shellcheckrc Normal file
View File

@ -0,0 +1 @@
disable=SC2153,SC2155,SC2046,SC1073,SC1078,SC1079,SC2016,SC1091,SC2034,SC2086,SC2153,SC2155,SC2236,SC2317,SC3037,SC3045,SC2046

2
.tool-versions Normal file
View File

@ -0,0 +1,2 @@
python 3.11.4
poetry 1.5.1

92
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,92 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
// pytest: https://stackoverflow.com/questions/70259564/how-to-debug-the-current-python-test-file-with-pytest-in-vs-code
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}",
"pythonArgs": [
"-Xfrozen_modules=off"
],
"env": {
"PYDEVD_DISABLE_FILE_VALIDATION": "1"
}
// "args": ["-i", "response.xml", "-o", "response.csv"],
// "args": ["-d", "/Volumes/Data"],
// "args": ["-f", "menubar.dmg"],
// "args": ["-h"],
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/.venv/bin/flask",
"console": "integratedTerminal",
"args": [
"run",
"--host",
"0.0.0.0",
"--port",
"8000"
],
"justMyCode": true
},
{
"name": "Python: Flet",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/.venv/bin/flet",
"console": "integratedTerminal",
"args": [
"run",
"main.py",
"-d"
],
"env": {
"PYDEVD_DISABLE_FILE_VALIDATION": "1",
},
"justMyCode": true
},
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"${file}"
],
"console": "integratedTerminal"
},
{
"name": "Node: Current File",
"type": "node",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
// "runtimeExecutable": "${env:HOME}/.n/bin/node"
}
],
"ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python"
}

14
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4,
},
"python.testing.pytestArgs": [
"."
],
// ! only disable analysis (pylance) if ruff is installed
// https://github.com/astral-sh/ruff-vscode
// "python.analysis.ignore": [
// "*"
// ],
}