Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// Dev Container definition for python_package
"name": "python_package",
// Dev Container definition for python_template
"name": "python_template",
"dockerComposeFile": ["docker-compose.yaml"],
"service": "app",
"workspaceFolder": "/workspace",
Expand Down
2 changes: 0 additions & 2 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ set -euo pipefail
echo "Configuring git safe directory (idempotent)..."
git config --global --add safe.directory /workspace 2>/dev/null || true

uv sync --frozen

echo "PostStart complete"
121 changes: 121 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Build and Deploy Template

on:
push:
branches:
- template

jobs:
test-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout template branch
uses: actions/checkout@v4
with:
ref: template
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run template tests
run: make test

- name: Build template output
run: make build

- name: Get template commit SHA
id: template_sha
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Clone repository for main branch
run: |
cd ..
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git main-repo
cd main-repo
# Try to checkout main, or create orphan if it doesn't exist
git checkout main 2>/dev/null || git checkout --orphan main

- name: Apply build output to main branch
run: |
cd ../main-repo
# Remove all files except .git
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
# Copy build output
cp -r ../python_template/build_output/. .
# Remove copier answers file (shouldn't be in generated project)
rm -f .copier-answers.yml

- name: Commit and create PR
run: |
cd ../main-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A

# Check if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
echo "has_changes=false" >> $GITHUB_ENV
else
# If main doesn't exist on remote, push it first
if ! git ls-remote --heads origin main | grep -q main; then
echo "Creating main branch"
git commit -m "Initial commit from template@${{ steps.template_sha.outputs.sha }}"
git push origin main
fi

# Create and push PR branch
git checkout -b template-build
git commit -m "Build from template@${{ steps.template_sha.outputs.sha }}" --allow-empty
git push -f origin template-build
echo "has_changes=true" >> $GITHUB_ENV
fi

- name: Create Pull Request
if: env.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Try to create PR, if it fails because PR exists, update it
if ! gh pr create \
--base main \
--head template-build \
--title "Build from template@${{ steps.template_sha.outputs.sha }}" \
--body "## 🤖 Automated Template Build

This PR contains the rendered template from the latest changes on the \`template\` branch.

**Source commit:** \`${{ steps.template_sha.outputs.sha }}\`
**Build timestamp:** ${{ github.event.head_commit.timestamp }}

### ✅ Validation
- Template tests passed
- Pre-commit hooks validated" 2>&1 | tee /tmp/pr-output.txt; then
# Check if error is because PR already exists
if grep -q "already exists" /tmp/pr-output.txt; then
echo "PR already exists, updating it"
gh pr edit template-build \
--title "Build from template@${{ steps.template_sha.outputs.sha }}" \
--body "## 🤖 Automated Template Build

This PR contains the rendered template from the latest changes on the \`template\` branch.

**Source commit:** \`${{ steps.template_sha.outputs.sha }}\`
**Build timestamp:** ${{ github.event.head_commit.timestamp }}

### ✅ Validation
- Template tests passed
- Pre-commit hooks validated"
else
echo "Failed to create PR"
cat /tmp/pr-output.txt
exit 1
fi
else
echo "PR created successfully"
fi
171 changes: 16 additions & 155 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,160 +1,21 @@
# 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
# Copier template testing outputs
temp_out/
test_output/
build_output/

# 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__/
# Python cache from test runs
__pycache__/
*.pyc

# Celery stuff
celerybeat-schedule
celerybeat.pid
# OS files
.DS_Store
Thumbs.db

# SageMath parsed files
*.sage.py
# Editor files
.idea/
*.swp
*.swo
*~

# Environments
.env
# Template environment
.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/
52 changes: 0 additions & 52 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,6 @@ repos:
- id: check-added-large-files
args: ["--maxkb=500"] # Policy: reject very large blobs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.2
hooks:
- id: ruff
name: Ruff Linter (autofix)
args: [--fix, "--config=pyproject.toml"]
- id: ruff-format
name: Ruff Formatter
args: ["--config=pyproject.toml"]

############################################################
# PUSH-TIME (SLOWER / ANALYSIS) HOOKS
# These run less frequently to keep commit loop fast.
############################################################
- repo: local
hooks:
- id: pytest-check
name: Run Test Suite
entry: uv run pytest
language: system
pass_filenames: false
always_run: true
stages: [pre-push]
# Optional faster feedback: args: ["-q", "--maxfail=1"]
- id: pylint
name: Pylint (design checks)
entry: uv run pylint
language: system
types: [python]
args: ["--rcfile=pyproject.toml"]
stages: [pre-push]
- id: deptry
name: Deptry (dependency hygiene)
entry: uv run deptry python_package
language: system
pass_filenames: false
stages: [pre-push]
- id: vulture
name: Vulture (dead code)
entry: uv run vulture python_package
language: system
pass_filenames: false
stages: [pre-push]

- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
Expand All @@ -100,11 +56,3 @@ repos:
args: ["--baseline", ".secrets.baseline"]
exclude: uv.lock
stages: [pre-push]

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.8.22
hooks:
- id: uv-lock
name: Validate pyproject / lock
stages: [pre-push]
pass_filenames: false
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Python: Module",
"type": "debugpy",
"request": "launch",
"module": "python_package",
"module": "{{ package_name }}",
"justMyCode": false
}
]
Expand Down
Loading