Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"name": "plox-common-dev",
"initializeCommand": "docker pull --platform=linux/amd64 docker.io/codeplox-dev/ubu2404-python-base:latest",
"image": "docker.io/codeplox-dev/ubu2404-python-base:latest",
"runArgs": [
"--init",
"--platform=linux/amd64"
],
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
},
"onCreateCommand": "./.devcontainer/setup-python.sh",
// "containerEnv": {},
// "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.languageServer": "Pylance",
"python.analysis.autoFormatStrings": true,
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.inlayHints.pytestParameters": true,
"python.analysis.inlayHints.variableTypes": true,
"ruff.configuration": "${containerWorkspaceFolder}/ruff.toml",
"ruff.organizeImports": true,
"ruff.lint.enable": true,
"ruff.fixAll": true,
"editor.formatOnSave": true,
"ruff.configurationPreference": "filesystemFirst",
"files.trimTrailingWhitespace": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": true,
"editor.guides.bracketPairsHorizontal": false,
"mypy-type-checker.ignorePatterns": [
".direnv/*",
".devcontainer-direnv/*",
".nondevcontainer-direnv/*",
"docs/*",
"*generated/*",
"*plox-common/*",
"*cache*",
"dist*",
".ruff_cache/*"
],
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.reportingScope": "workspace",
"mypy-type-checker.preferDaemon": false,
"mypy-type-checker.showNotifications": "onError",
"mypy-type-checker.args": [
"--config-file=${containerWorkspaceFolder}/mypy.ini"
],
"python.terminal.activateEnvironment": false,
"go.toolsManagement.autoUpdate": true,
"go.toolsEnvVars": {
"GO111MODULE": "on"
},
"explorer.sortOrderLexicographicOptions": "unicode",
"files.watcherExclude": {
"**/.bloop": true,
"**/.metals": true,
"**/.ammonite": true
},
"todo-tree.general.showActivityBarBadge": true,
"todo-tree.filtering.ignoreGitSubmodules": true,
"interactiveWindow.executeWithShiftEnter": true,
"makefile.configureOnOpen": false,
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash",
"args": [
"-l"
]
}
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Update python deps",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; rm poetry.lock && yes | poetry cache clear . --all; make install-deps"
},
{
"label": "Install deps",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; make install-deps"
},
{
"label": "Lint: ruff format",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; ruff format src test"
},
{
"label": "Lint: ruff rules",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; ruff check src test --fix"
},
{
"label": "make",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; VERBOSE=1 make"
},
{
"label": "Test: unit",
"type": "shell",
"command": "eval \"$(direnv export bash)\"; direnv allow .; eval \"$(direnv export bash)\"; make test-unit"
}
]
}
},
"extensions": [
"ms-python.vscode-pylance",
"ms-python.python",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"ms-python.debugpy",
"bierner.github-markdown-preview",
"bierner.markdown-checkbox",
"bierner.markdown-emoji",
"bierner.markdown-footnotes",
"bierner.markdown-preview-github-styles",
"bierner.markdown-yaml-preamble",
"christian-kohler.path-intellisense",
"davidanson.vscode-markdownlint",
"gruntfuggly.todo-tree",
"ms-vscode.makefile-tools",
"njpwerner.autodocstring",
"redhat.vscode-yaml",
"tamasfe.even-better-toml",
"usernamehw.errorlens"
]
}
},
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
]
}
8 changes: 8 additions & 0 deletions .devcontainer/setup-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -euo pipefail

eval "$(direnv export bash)"
direnv allow .
eval "$(direnv export bash)"
make install-deps
58 changes: 1 addition & 57 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,57 +1 @@
export PY_VERS=3.12.9
export SUPPORTED_PY_VERS="python3.12 python3.11 python3.13 python3.10 python3.9"

print_err(){
printf "+++ ERROR +++ %s\n" "$*" >&2;
}

print_warn(){
printf "+++ WARNING +++ %s\n" "$*" >&2;
}

get_candidate_py_vers(){
PY_VERS_NO_PATCH=$(cut -d. -f1-2 <<< "${PY_VERS}")
for py in python${PY_VERS_NO_PATCH} python3 python; do
if command -v ${py} >/dev/null 2>&1 ; then
# Check if it matches desired
py_vers=$(awk '{print $2}' <<< "$(${py} -V)")
if [[ "${py_vers}" == "${PY_VERS}" ]]; then
# found exact match
echo "$py"
return
fi
fi
done

print_warn "Did not find exact match for desired ${PY_VERS}, falling back to major.minor compat"

# python, python3, pythonX.YY either not installed or don't match exact PY_VERS,
# fallback to trying to match just major.minor
for py in $(echo $SUPPORTED_PY_VERS) python3 python; do
py_vers=""
py_vers_patchless=""
if command -v ${py} >/dev/null 2>&1 ; then
py_vers=$(awk '{print $2}' <<< "$(${py} -V)")
py_vers_patchless=$(cut -d. -f1-2 <<< "${py_vers}")

if [[ "${SUPPORTED_PY_VERS}" == *"python${py_vers_patchless}"* ]]; then
# found supported major.minor, exit early
# n.b. - prioritizes order versioning left to right in SUPPORTED_PY_VERS
echo "$py"
return
fi
fi
done

print_err "Did not detect python or python3 installed! Please install one of Python's '${SUPPORTED_PY_VERS}' (ideally $PY_VERS) and try again!"
exit 1
}

if [[ "$(which pyenv)" == "" ]]; then
layout python "$(get_candidate_py_vers)"
else
layout pyenv "${PY_VERS}"
fi

pip install --upgrade pip pre-commit &>/dev/null
pre-commit install -c ./.pre-commit-config.yaml &>/dev/null
layout uv
63 changes: 54 additions & 9 deletions .github/workflows/python-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ jobs:
with:
submodules: true
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: make
python-version-file: ".python-version"
- name: get-apt-deps
shell: bash
run: |
sudo apt-get update &>/dev/null
sudo apt-get install -yq direnv make &>/dev/null
- name: setup-uv
shell: bash
run: |
mkdir -p ${HOME}/.config/direnv || true
cat temp/direnv_support > ${HOME}/.config/direnv/direnvrc
- name: mypy-check
shell: bash
run: |
direnv allow . && eval "$(direnv export bash)"
make type-check
lint:
Expand All @@ -34,18 +44,29 @@ jobs:
with:
submodules: true
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: make
python-version-file: ".python-version"
- name: get-apt-deps
shell: bash
run: |
sudo apt-get update &>/dev/null
sudo apt-get install -yq direnv make &>/dev/null
- name: setup-uv
shell: bash
run: |
mkdir -p ${HOME}/.config/direnv || true
cat temp/direnv_support > ${HOME}/.config/direnv/direnvrc
- name: lint
shell: bash
run: |
direnv allow . && eval "$(direnv export bash)"
make lint

test-unit:
needs: [mypy, lint]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -61,20 +82,27 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: make
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ] ; then
sudo apt-get update &>/dev/null
sudo apt-get install -yq direnv make &>/dev/null
elif [ "$RUNNER_OS" == "macOS" ] ; then
brew install make direnv
brew install make direnv uv
shopt -s expand_aliases
alias make=gmake
fi
mkdir -p ${HOME}/.config/direnv || true
cat temp/direnv_support > ${HOME}/.config/direnv/direnvrc
direnv allow . && eval "$(direnv export bash)"
make test-unit
test-integration:
needs: [test-unit]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -90,17 +118,23 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: make
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ] ; then
sudo apt-get update &>/dev/null
sudo apt-get install -yq direnv git make &>/dev/null
elif [ "$RUNNER_OS" == "macOS" ] ; then
brew install make direnv git
brew install make direnv git uv
shopt -s expand_aliases
alias make=gmake
fi
mkdir -p ${HOME}/.config/direnv || true
cat temp/direnv_support > ${HOME}/.config/direnv/direnvrc
git config --global init.defaultBranch main
git config --global user.email urmom@fake.com
git config --global user.name "Your mom"
Expand All @@ -125,15 +159,22 @@ jobs:
with:
submodules: true
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
- uses: actions/setup-python@v5
with:
python-version: 3.12
python-version-file: ".python-version"
- name: Get Pull Request Number
id: pr
run: echo "pull_request_number=$(gh pr view --json number -q .number || echo "")" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Environment Variables
run: |
DEFAULT_BRANCH=${{ github.event.repository.default_branch }}
echo "DEFAULT_BRANCH=${DEFAULT_BRANCH}" >> $GITHUB_ENV
echo "DEFAULT_BRANCH_REF=refs/heads/$DEFAULT_BRANCH" >> $GITHUB_ENV
echo "DEFAULT_BRANCH=$DEFAULT_BRANCH"
- name: make
shell: bash
env:
Expand All @@ -142,6 +183,10 @@ jobs:
run: |
sudo apt-get update &>/dev/null
sudo apt-get install -yq direnv git make &>/dev/null
# enable direnv support for uv for now
mkdir -p ${HOME}/.config/direnv || true
cat temp/direnv_support > ${HOME}/.config/direnv/direnvrc
# publish (maybe)
git config --global init.defaultBranch main
git config --global user.email urmom@fake.com
git config --global user.name "Your mom"
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "plox-common"]
path = plox-common
url = ../plox-common
branch = "feat/switch-to-ruff"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.0
rev: v0.11.8
hooks:
# Run the linter.
- id: ruff
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13.3
Loading
Loading