Skip to content

Commit

Permalink
Merge branch 'pythoninthegrass-nicegui'
Browse files Browse the repository at this point in the history
  • Loading branch information
pythoninthegrass committed Aug 18, 2023
2 parents ba239a1 + f944436 commit b81be22
Show file tree
Hide file tree
Showing 30 changed files with 3,460 additions and 438 deletions.
13 changes: 13 additions & 0 deletions .devcontainer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!poetry.lock
!pyproject.toml
.cache
.devcontainer
.git
.gitignore
.pytest_cache
.tool-versions
.venv
.vscode
**/__pycache__
Dockerfile*
README.md
136 changes: 136 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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
]
}
61 changes: 61 additions & 0 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
aiofiles==23.2.1 ; python_version >= "3.11" and python_version < "4.0"
aiohttp==3.8.5 ; python_version >= "3.11" and python_version < "4.0"
aiosignal==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
anyio==3.7.1 ; python_version >= "3.11" and python_version < "4.0"
async-timeout==4.0.3 ; python_version >= "3.11" and python_version < "4.0"
attrs==23.1.0 ; python_version >= "3.11" and python_version < "4.0"
bidict==0.22.1 ; python_version >= "3.11" and python_version < "4.0"
bottle==0.12.25 ; python_version >= "3.11" and python_version < "4.0"
certifi==2023.7.22 ; python_version >= "3.11" and python_version < "4.0"
charset-normalizer==3.2.0 ; python_version >= "3.11" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.11" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"
fastapi-socketio==0.0.10 ; python_version >= "3.11" and python_version < "4.0"
fastapi==0.101.1 ; python_version >= "3.11" and python_version < "4.0"
frozenlist==1.4.0 ; python_version >= "3.11" and python_version < "4.0"
greenlet==3.0.0a1 ; python_version >= "3.11" and (python_version >= "3.12" or platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64") and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.11" and python_version < "4.0"
httpcore==0.17.3 ; python_version >= "3.11" and python_version < "4.0"
httptools==0.6.0 ; python_version >= "3.11" and python_version < "4.0"
httpx==0.24.1 ; python_version >= "3.11" and python_version < "4.0"
idna==3.4 ; python_version >= "3.11" and python_version < "4.0"
inflect==7.0.0 ; python_version >= "3.11" and python_version < "4.0"
itsdangerous==2.1.2 ; python_version >= "3.11" and python_version < "4.0"
jinja2==3.1.2 ; python_version >= "3.11" and python_version < "4.0"
markdown2==2.4.10 ; python_version >= "3.11" and python_version < "4"
markupsafe==2.1.3 ; python_version >= "3.11" and python_version < "4.0"
multidict==6.0.4 ; python_version >= "3.11" and python_version < "4.0"
nicegui==1.3.11 ; python_version >= "3.11" and python_version < "4.0"
orjson==3.9.5 ; python_version >= "3.11" and python_version < "4.0" and (platform_machine != "i386" and platform_machine != "i686")
packaging==23.1 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "openbsd6"
proxy-tools==0.1.0 ; python_version >= "3.11" and python_version < "4.0"
pscript==0.7.7 ; python_version >= "3.11" and python_version < "4.0"
pycparser==2.21 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "win32"
pydantic==1.10.12 ; python_version >= "3.11" and python_version < "4.0"
pygments==2.16.1 ; python_version >= "3.11" and python_version < "4.0"
pyobjc-core==9.2 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "darwin"
pyobjc-framework-cocoa==9.2 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "darwin"
pyobjc-framework-security==9.2 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "darwin"
pyobjc-framework-webkit==9.2 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "darwin"
python-decouple==3.8 ; python_version >= "3.11" and python_version < "4.0"
python-dotenv==1.0.0 ; python_version >= "3.11" and python_version < "4.0"
python-engineio==4.5.1 ; python_version >= "3.11" and python_version < "4.0"
python-multipart==0.0.6 ; python_version >= "3.11" and python_version < "4.0"
python-socketio==5.8.0 ; python_version >= "3.11" and python_version < "4.0"
pythonnet==2.5.2 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "win32"
pywebview==4.2.2 ; python_version >= "3.11" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.11" and python_version < "4.0"
qtpy==2.3.1 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "openbsd6"
sniffio==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
sqlacodegen @ git+https://github.com/agronholm/sqlacodegen.git@HEAD ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy2-stubs==0.0.2a35 ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy==1.4.41 ; python_version >= "3.11" and python_version < "4.0"
sqlmodel==0.0.8 ; python_version >= "3.11" and python_version < "4.0"
starlette==0.27.0 ; python_version >= "3.11" and python_version < "4.0"
typing-extensions==4.7.1 ; python_version >= "3.11" and python_version < "4.0"
uvicorn[standard]==0.22.0 ; python_version >= "3.11" and python_version < "4.0"
uvloop==0.17.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.11" and python_version < "4.0"
vbuild==0.8.2 ; python_version >= "3.11" and python_version < "4.0"
watchfiles==0.19.0 ; python_version >= "3.11" and python_version < "4.0"
websockets==11.0.3 ; python_version >= "3.11" and python_version < "4.0"
yarl==1.9.2 ; python_version >= "3.11" and python_version < "4.0"
32 changes: 0 additions & 32 deletions .dockerignore

This file was deleted.

6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ insert_final_newline = true
trim_trailing_whitespace = false

# general formatting
[*.{go,sh,bash,zsh,Makefile}]
[*.{bash,go,sh,zsh,justfile,Makefile}]
indent_style = tab
indent_size = 4

Expand All @@ -28,7 +28,7 @@ charset = utf-8
indent_style = space
indent_size = 4

# webdev
[*.{html,xml,js,css}]
# webdev et al
[*.{html,xml,js,css,json,gql,lua,tf,tfvars,yml,yaml}]
indent_style = space
indent_size = 2
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ETC
.vscode/
lunch.db
scratch.py
scratch*.*
auth/
.htpasswd
.ruff_cache

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python 3.11.0
poetry 1.3.1
python 3.11.4
poetry 1.5.1
Loading

0 comments on commit b81be22

Please sign in to comment.