Skip to content

Commit

Permalink
dev: update copier (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Feb 22, 2024
2 parents edbc286 + 785894d commit 35106cd
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 1c42097
_commit: 3bc5a3e
_src_path: https://github.com/MartinBernstorff/nimble-python-template
email: martinbernstorff@gmail.com
full_name: Martin Bernstorff
Expand Down
26 changes: 14 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line to run commands after the container is created.
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
"postCreateCommand": ".devcontainer/post_create.sh",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"GitHub.copilot",
"GitHub.vscode-pull-request-github",
"tamasfe.even-better-toml",
"MichaelCurrin.auto-commit-msg",
"SeeLog.python-init-generator",
"charliermarsh.ruff",
]
}
}
}
33 changes: 33 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set -e

# Zsh as default terminal
chsh -s $(which zsh)

# Github CLI
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

# Node
export NVM_DIR="$HOME/.nvm"
mkdir -p $NVM_DIR
export NODE_VERSION="18.2.0"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

export NODE_PATH=$NVM_DIR/v$NODE_VERSION/lib/node_modules
export PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
echo 'export PATH="$PATH:$HOME/.nvm/versions/node/v18.2.0/bin:PATH"' >> ~/.zshrc

# Graphite
npm install -g @withgraphite/graphite-cli@stable

# Lefthook
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | bash
apt install lefthook
lefthook install
5 changes: 2 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Configuration: https://dependabot.com/docs/config-file/
# Docs: https://docs.github.com/en/github/administering-a-repository/keeping-your-dependencies-updated-automatically
# Docs: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
Expand All @@ -13,4 +12,4 @@ updates:
open-pull-requests-limit: 20
commit-message:
prefix: "deps:"
include: "scope"
include: "scope"
27 changes: 27 additions & 0 deletions .github/workflows/dependabot_automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: automerge-bot-prs

on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot-automerge:
runs-on: ubuntu-latest
# if actor is dependabot or pre-commit-ci[bot] then run
if: ${{ github.actor == 'dependabot[bot]' }}

steps:
# Checkout action is required for token to persist
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Auto approve dependabot PRs
if: ${{ github.actor == 'dependabot[bot]' }}
uses: hmarr/auto-approve-action@v3.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: test
on:
push:
branches: [main]
Expand All @@ -14,8 +14,4 @@ jobs:

- name: Build CI container
run: |
docker build -t iterpy:latest -f Dockerfile .
- name: Run CI
run: |
docker run iterpy make validate_ci
make docker_ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
*.whl

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
11 changes: 0 additions & 11 deletions .vscode/extensions.json

This file was deleted.

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticMode": "workspace"
"python.analysis.diagnosticMode": "workspace",
"python.defaultInterpreterPath": ".venv/bin/python"
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "PR",
"type": "shell",
"command": "lm sync --squash",
"command": "make pr",
"group": {
"kind": "build",
"isDefault": true
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ WORKDIR /app

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"
RUN curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" RYE_TOOLCHAIN_VERSION=3.9 bash
RUN curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" RYE_TOOLCHAIN="/usr/local/bin/python" bash
RUN rye config --set-bool behavior.use-uv=true
RUN rye config --set-bool behavior.global-python=true
RUN rye config --set default.dependency-operator="~="

COPY Makefile ./
COPY pyproject.toml ./
RUN make install
RUN make types # Type-check to warm the cache

COPY . /app
RUN make install
RUN make quicksync
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,45 @@ MAKEFLAGS = --no-print-directory

# Dependency management
install:
rye sync --features=dev
rye sync

quicksync:
rye sync --no-lock

test:
@rye run pytest --cov=$(SRC_PATH) $(SRC_PATH) --cov-report xml:.coverage.xml --cov-report lcov:.coverage.lcov

test-with-coverage: ## Run tests
test-with-coverage:
@echo "––– Testing –––"
@rye run diff-cover .coverage.xml --fail-under=80
@make test
@rye run diff-cover .coverage.xml
@echo "✅✅✅ Tests passed ✅✅✅"

lint: ## Format code
@echo "––– Linting –––"
@rye run ruff format .
@rye run ruff . --fix \
@rye run ruff . --fix --unsafe-fixes \
--extend-select F401 \
--extend-select F841
@echo "✅✅✅ Lint ✅✅✅"

types: ## Type-check code
@echo "––– Type-checking –––"
@rye run pyright $(SRC_PATH)
@rye run pyright .
@echo "✅✅✅ Types ✅✅✅"

validate_ci: ## Run all checks
@echo "––– Running all checks –––"
@make lint
@make types
## CI doesn't support local coverage report, so skipping full tests
## CI doesn't support local coverage report, so skipping full test
@make test

docker_ci: ## Run all checks in docker
@echo "––– Running all checks in docker –––"
@docker rm -f iterpy || true
@docker build -t iterpy:latest -f Dockerfile .
@docker run iterpy make validate_ci

pr: ## Submit a PR
@rye run lm sync --squash --automerge
5 changes: 5 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ pre-commit:
glob: "*.{py}"
run: ruff --fix --extend-select F401 --extend-select F841 --extend-select B007 {staged_files}
stage_fixed: true

post-checkout:
commands:
install:
run: make quicksync

0 comments on commit 35106cd

Please sign in to comment.