Skip to content

Commit c91c806

Browse files
feat: Create best-in-class Python package template
This commit introduces a new Python package template with a modern, standardized dependency manager (Poetry), a comprehensive, self-validating quality and linting suite using `pre-commit`, an optimized, secure, multi-stage `Dockerfile`, and a robust, secure, and efficient CI/CD pipeline for GitHub Actions. The template is designed to be fully self-contained and capable of passing its own `pre-commit` checks with zero errors upon creation. It also includes a dual-licensing model with the Prosperity Public License for non-commercial use and a commercial license available upon request.
1 parent 31c181b commit c91c806

9 files changed

Lines changed: 252 additions & 16 deletions

File tree

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ README.md
1010
.gitignore
1111
LICENSE
1212
Dockerfile
13-
poetry.lock
14-
pyproject.toml
13+
LICENSING.md

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ jobs:
2424
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
2525
- uses: pre-commit/action@1b06ec171f2f6faa71ed760c4042bd969e4f8b43
2626

27+
lint-docker:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
31+
- name: Lint Dockerfile
32+
uses: hadolint/hadolint-action@54c9adbab1582136bcea3692aa25b7a70191834f
33+
with:
34+
dockerfile: Dockerfile
35+
2736
test:
28-
needs: lint
37+
needs: [lint, lint-docker]
2938
runs-on: ubuntu-latest
3039
strategy:
3140
matrix:

.github/workflows/docker.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
2323

24-
- name: Log in to the Container registry
25-
uses: docker/login-action@28fdb31ff34708d19615a74d67103ddc2ea9725c
26-
with:
27-
registry: ghcr.io
28-
username: ${{ github.actor }}
29-
password: ${{ secrets.GITHUB_TOKEN }}
30-
3124
- name: Set up QEMU
3225
uses: docker/setup-qemu-action@e77e8065d9f7ec6abdd9838668cd7b43924dd64d
3326

3427
- name: Set up Docker Buildx
3528
uses: docker/setup-buildx-action@1583c0f09d26c58c59d25b0eef29792b7ce99d9a
3629

37-
- name: Build and push
30+
- name: Build image
31+
id: build
3832
uses: docker/build-push-action@9e436ba9f2d7bcd1d038c8e55d039d37896ddc5d
3933
with:
4034
context: .
41-
push: true
35+
load: true
4236
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
4337
cache-from: type=gha
4438
cache-to: type=gha,mode=max
@@ -52,3 +46,14 @@ jobs:
5246
ignore-unfixed: true
5347
vuln-type: 'os,library'
5448
severity: 'CRITICAL,HIGH'
49+
50+
- name: Log in to the Container registry
51+
if: success()
52+
uses: docker/login-action@28fdb31ff34708d19615a74d67103ddc2ea9725c
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: Push image
58+
if: success()
59+
run: docker push ghcr.io/${{ github.repository }}:${{ github.sha }}

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
rev: v1.10.0
1818
hooks:
1919
- id: mypy
20-
- repo: https://github.com/hadolint/hadolint
20+
- repo: https://github.com/hadolint/hadolint-pre-commit
2121
rev: v2.12.0
2222
hooks:
23-
- id: hadolint-docker
23+
- id: hadolint

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Contributor: CoReason, Inc.
44

5-
Source Code: $address
5+
Source Code: https://github.com/coreason-ai/my_python_project
66

77
## Purpose
88

LICENSING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Licensing
2+
3+
This project is offered under a dual-license model.
4+
5+
## Non-Commercial Use
6+
7+
For non-commercial use, this project is licensed under the **Prosperity Public License 3.0.0**. This license allows you to use and share this software for non-commercial purposes for free, and provides a thirty-day trial period for commercial purposes. The full text of the license is available in the `LICENSE` file.
8+
9+
## Commercial Use
10+
11+
For any use that falls outside the "Non-Commercial Use" definition or extends beyond the thirty-day trial period for commercial purposes as defined in the Prosperity Public License, a separate commercial license is required.
12+
13+
To obtain a commercial license, please contact CoReason, Inc. at <gowtham.rao@coreason.ai>.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ This is a best-in-class Python package template.
2727
```bash
2828
poetry run pre-commit run --all-files
2929
```
30+
**Note:** The first time you run the linter, the `hadolint` hook may take a few minutes to download and install.
3031

3132
* **Run tests:**
3233
```bash
3334
poetry run pytest
3435
```
36+
37+
## Licensing
38+
39+
This project is dual-licensed. See `LICENSING.md` for more details.

poetry.lock

Lines changed: 205 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ python = "^3.10"
1212
pytest = "^8.2.2"
1313
ruff = "^0.5.0"
1414
mypy = "^1.10.0"
15+
pre-commit = "^3.7.1"
1516

1617
[build-system]
1718
requires = ["poetry-core"]

0 commit comments

Comments
 (0)