Skip to content

Commit

Permalink
Init from serious-scaffold-python.
Browse files Browse the repository at this point in the history
  • Loading branch information
you-n-g committed Aug 14, 2024
0 parents commit 400ad4d
Show file tree
Hide file tree
Showing 60 changed files with 4,020 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
_commit: v0.0.54
_src_path: gh:serious-scaffold/ss-python
author_email: [email protected]
author_name: Xiao Yang
copyright_holder: ''
copyright_license: MIT License
copyright_year: 2022-2024
coverage_threshold: 100
default_py: '3.12'
development_status: Beta
max_py: '3.12'
min_py: '3.8'
module_name: wan
organization_name: ''
package_name: wan
platforms:
- macos
- ubuntu
- windows
project_description: 'Wait and notify conveniently'
project_name: WAN
readme_content: "\n\n# Wait And Notify(WAN)\nThis package is under development. We\
\ will release it soon in the future.\n\n\n\n# Installation\n\nYou can install\
\ wan with **one** of the following command\n\n<!-- [fzf](https://github.com/junegunn/fzf)\
\ is required -->\n```shell\n# 1)\n# pip install wan # TODO: upload this to pip\
\ source\n# 2)\npip install git+https://github.com/you-n-g/wan.git@master\n# 3)\n\
python setup.py install\n# 4)\npython setup.py develop # It is recommended if\
\ you want to develop wan\n```\n\n## config\n\nPlease config your [notifiers](https://github.com/liiight/notifiers).\n\
`wan` will read the setting in ` ~/.dotfiles/.notifers.yaml` as the arguments\
\ for notifiers.\n\nHere is a config example of telegram\n```yaml\nprovider: telegram\n\
kwargs:\n chat_id: <Your Chat id from `@myidbot` by sending `/getid`>\n \
\ token: <Your token from `@BotFather` by sending `/newbot`>\n```\n\nOther configs:\n\
```yaml\nlog_level: DEBUG # the default level is INFO\n```\n\n\n# Usage\n\n##\
\ Use in python code\n\n* Call the function in python code directly.\n```python\n\
<Your code which takes a lot of time>\nfrom wan import ntf; ntf('Finished')\n\
```\n\n* Call the function in shell directly\n```shell\n> sleep 10 ; wan ntf sleep\
\ finished\n```\n\n"
repo_name: wan
repo_namespace: you-n-g
repo_platform: github
103 changes: 103 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# syntax=docker/dockerfile:1

ARG PYTHON_VERSION=3.12

########################################################################################
# Dev image is used for development and cicd.
########################################################################################

FROM python:${PYTHON_VERSION} as dev

# NOTE: python docker image has env `PYTHON_VERSION` but with patch version.
# ARG is used here for temporary override without changing the original env.
ARG PYTHON_VERSION

# Config Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONHASHSEED=0
ENV PYTHONUNBUFFERED=1

# Config pipx
ENV PIPX_HOME=/usr/local/pipx
ENV PIPX_BIN_DIR=/usr/local/bin
ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python

# renovate: depName=debian_12/bash-completion
ARG BASH_COMPLETION_VERSION="1:2.11-6"
# renovate: depName=debian_12/pipx
ARG PIPX_VERSION="1.1.0-1"
# renovate: depName=debian_12/sudo
ARG SUDO_VERSION="1.9.13p3-1+deb12u1"
# renovate: depName=debian_12/vim
ARG VIM_VERSION="2:9.0.1378-2"

# Install system dependencies and override pipx with a newer version
RUN apt-get update && apt-get install -y --no-install-recommends \
bash-completion="${BASH_COMPLETION_VERSION}" \
pipx="${PIPX_VERSION}" \
sudo="${SUDO_VERSION}" \
vim="${VIM_VERSION}" \
&& pipx install pipx==1.6.0 \
&& apt-get purge -y --autoremove pipx \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* \
&& hash -r

# Install prerequisites
RUN --mount=source=Makefile,target=Makefile \
make prerequisites

# Create a non-root user with sudo permission
ARG USERNAME=wan
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --create-home --uid $USER_UID --gid $USER_GID $USERNAME -s /bin/bash \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Set permission for related folders
RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR

# Set default working directory
WORKDIR /workspace

########################################################################################
# Build image is an intermediate image used for building the project.
########################################################################################

FROM dev as build

# Install dependencies and project into the local packages directory.
ARG SCM_VERSION
RUN --mount=source=README.md,target=README.md \
--mount=source=pdm.lock,target=pdm.lock \
--mount=source=pyproject.toml,target=pyproject.toml \
--mount=source=src,target=src,rw \
mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_WAN=${SCM_VERSION} pdm sync --prod --no-editable

########################################################################################
# Prod image is used for deployment and distribution.
########################################################################################

FROM python:${PYTHON_VERSION}-slim as prod

# NOTE: python docker image has env `PYTHON_VERSION` but with patch version.
# ARG is used here for temporary override without changing the original env.
ARG PYTHON_VERSION

# Config Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONHASHSEED=0
ENV PYTHONUNBUFFERED=1

# Retrieve packages from build stage.
ENV PYTHONPATH=/workspace/pkgs
COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/lib /workspace/pkgs

# Retrieve executables from build stage.
COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/bin/* /usr/local/bin/

# Set command to run the cli by default.
ENTRYPOINT ["wan-cli"]
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
.*
!/Makefile
!/README.md
!/pdm.lock
!/pyproject.toml
!/src/
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"customizations": {
// Configure extensions specific to VS Code.
"vscode": {
"extensions": [
"DavidAnson.vscode-markdownlint",
"ExecutableBookProject.myst-highlight",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"ms-python.python",
"richie5um2.vscode-sort-json",
"streetsidesoftware.code-spell-checker"
]
}
},
"image": "ghcr.io/you-n-g/wan/dev:py3.12",
// Force the image update to ensure the latest version which might be a bug.
// Reference: https://github.com/microsoft/vscode-remote-release/issues/9391
"initializeCommand": "docker pull ghcr.io/you-n-g/wan/dev:py3.12",
// Use a targeted named volume for .venv folder to improve disk performance.
// Reference: https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume
"mounts": [
"source=${localWorkspaceFolderBasename}-venv,target=${containerWorkspaceFolder}/.venv,type=volume"
],
"name": "wan",
// Set proper permission for the .venv folder when the container created.
"postCreateCommand": "sudo chown wan:wan .venv",
// Prepare the development environment when the container starts.
"postStartCommand": "make dev",
// Use the non-root user in the container.
"remoteUser": "wan"
}
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github:
- Xiao Yang
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
pull_request:
push:
branches:
- main

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
ci:
if: ${{ !cancelled() && ! failure() }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Set up PDM
uses: pdm-project/setup-pdm@568ddd69406b30de1774ec0044b73ae06e716aa4 # v4
with:
cache: true
python-version: ${{ matrix.python-version }}
version: 2.16.1
- run: env | sort
- run: make prerequisites
- run: make dev
- run: make lint test doc build
strategy:
matrix:
os:
# renovate: github-runner
- macos-14
# renovate: github-runner
- ubuntu-22.04
# renovate: github-runner
- windows-2022
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
# Python 3.8 and 3.9 do not run on macos-14 which is using arm64 hardware.
exclude:
# renovate: github-runner
- os: macos-14
python-version: '3.8'
# renovate: github-runner
- os: macos-14
python-version: '3.9'
include:
- os: macos-13
python-version: '3.8'
- os: macos-13
python-version: '3.9'
27 changes: 27 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CommitLint
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
commitlint:
container:
image: commitlint/commitlint:19.3.1@sha256:02c8c31b2c61c51eadb410960648c8b370f7583609f4ca1520155eeeefd63d66
runs-on: ubuntu-22.04
steps:
- run: env | sort
- name: Validate the latest commit message with commitlint
if: github.event_name == 'push'
run: echo "${{ github.event.head_commit.message }}" | npx commitlint -x @commitlint/config-conventional
- name: Validate pull request title with commitlint
if: github.event_name == 'pull_request'
run: echo "${{ github.event.pull_request.title }}" | npx commitlint -x @commitlint/config-conventional
on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited
push:
branches:
- main
32 changes: 32 additions & 0 deletions .github/workflows/delete-untagged-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Delete Untagged Packages

on:
schedule:
- cron: "0 2 * * 0"
workflow_dispatch: null

permissions:
packages: write

jobs:
delete-untagged-packages:
runs-on: ubuntu-latest
steps:
- name: Delete untagged dev-cache packages
uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0
with:
package-name: "wan/dev-cache"
package-type: "container"
delete-only-untagged-versions: "true"
- name: Delete untagged development packages
uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0
with:
package-name: "wan/dev"
package-type: "container"
delete-only-untagged-versions: "true"
- name: Delete untagged production packages
uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0
with:
package-name: "wan"
package-type: "container"
delete-only-untagged-versions: "true"
81 changes: 81 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: DevContainer

on:
pull_request:
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
workflow_dispatch: null

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
dev-container-publish:
permissions:
packages: write
runs-on: ubuntu-22.04
steps:
- run: env | sort
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up authentication
run: docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
- name: Set up BuildKit
run: |
docker context create builder
docker buildx create builder --name container --driver docker-container --use
docker buildx inspect --bootstrap --builder container
- name: Build the dev container
run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--target dev
- name: Test the dev container
run: |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
make dev lint test doc build
- name: Build the prod container
run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }} \
--target prod
- name: Test the prod container
run: docker run --rm ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}
- name: Push the dev container
if: github.event_name != 'pull_request'
run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-to type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }},mode=max \
--file .devcontainer/Dockerfile \
--push \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--target dev
strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
Loading

0 comments on commit 400ad4d

Please sign in to comment.