Skip to content

Commit

Permalink
cookiecutter setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Aug 7, 2024
1 parent addc832 commit 218f083
Show file tree
Hide file tree
Showing 23 changed files with 1,034 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"template": "https://github.com/reef-technologies/cookiecutter-rt-pkg",
"commit": "d9240e46239f3622c739043a5e6cbf605a6244d2",
"checkout": null,
"context": {
"cookiecutter": {
"package_name": "deterministic_ml",
"repository_github_url": "https://github.com/backend-developers-ltd/deterministic-ml",
"is_django_package": "n",
"_jinja2_env_vars": {
"block_start_string": "# COOKIECUTTER{%",
"block_end_string": "%}"
},
"_template": "https://github.com/reef-technologies/cookiecutter-rt-pkg"
}
},
"directory": null
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/" # specify the directory to scan for dependency files, e.g., "/"
schedule:
interval: "daily"
open-pull-requests-limit: 0 # Only security updates will be opened as PRs
- package-ecosystem: "docker"
directory: "/" # specify the directory to scan for dependency files, e.g., "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 0 # Only security updates will be opened as PRs
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Continuous Integration

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

env:
PYTHON_DEFAULT_VERSION: "3.12"

jobs:
linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: "pip"
cache-dependency-path: 'pdm.lock'
- uses: actions/cache@v4
with:
path: ~/.cache/pdm
key: ${{ env.PYTHON_DEFAULT_VERSION }}-pdm-${{ hashFiles('pdm.lock') }}
restore-keys: ${{ env.PYTHON_DEFAULT_VERSION }}-pdm-
- name: Install dependencies
run: python -m pip install --upgrade nox 'pdm>=2.12,<3'
- name: Run linters
run: nox -vs lint
test:
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'pdm.lock'
- uses: actions/cache@v4
with:
path: ~/.cache/pdm
key: ${{ matrix.python-version }}-pdm-${{ hashFiles('pdm.lock') }}
restore-keys: ${{ matrix.python-version }}-pdm-
- name: Install dependencies
run: python -m pip install --upgrade 'nox==2024.3.2' 'pdm==2.13.2'
- name: Run unit tests
run: nox -vs test
93 changes: 93 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: "Continuous Deployment"

# This workflow requires https://docs.pypi.org/trusted-publishers/ to be enabled for the repository.
# Follow instructions from this link to enable it.
# Use this workflow (`publish.yml`) in the configuration.
# Please note this process has to be repeated for Test PyPI and PyPI separately.

on:
push:
tags:
- 'v*' # push events to matching v*, i.e. v1.0, v20.15.10
- 'draft/v*'

env:
PYTHON_DEFAULT_VERSION: "3.12"

jobs:
publish:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
id-token: write # allows publishing to PyPI
contents: write # allows uploading a GitHub release
runs-on: ubuntu-latest
steps:
- name: Get version from tag
id: get-version
run: |
if [[ ${{ github.ref }} == refs/tags/v* ]]; then
echo "draft=false" >> "$GITHUB_OUTPUT"
echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
else
echo "draft=true" >> "$GITHUB_OUTPUT"
echo "version=${GITHUB_REF#refs/tags/draft/v}" >> "$GITHUB_OUTPUT"
fi
export IS_PRERELEASE=$([[ ${{ github.ref }} =~ [^0-9]$ ]] && echo true || echo false)
echo "prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}

- name: Install dependencies
run: python -m pip install --upgrade nox 'pdm>=2.12,<3'

- name: Read the Changelog
id: read-changelog
uses: mindsers/changelog-reader-action@v2
with:
version: ${{ steps.get-version.outputs.version }}
path: ./CHANGELOG.md
continue-on-error: ${{ fromJSON(steps.get-version.outputs.draft) }}

- name: Build
run: pdm build

- name: Sign distribution
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
dist/*.tar.gz
dist/*.whl
- name: Create GitHub release
id: create-release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.get-version.outputs.version }}
body: ${{ steps.read-changelog.outputs.changes }}
draft: ${{ fromJSON(steps.get-version.outputs.draft)}}
prerelease: ${{ fromJSON(steps.get-version.outputs.prerelease) }}
files: >-
dist/*.tar.gz
dist/*.whl
dist/*.sigstore
- name: Remove signature files as pypa/gh-action-pypi-publish does not support them
run: rm -f dist/*.sigstore

- name: Publish distribution 📦 to TestPyPI
if: ${{ steps.get-version.outputs.draft == 'true' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
if: ${{ steps.get-version.outputs.draft == 'false' }}
uses: pypa/gh-action-pypi-publish@release/v1
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.pyc
*.sqlite3
*~
*.egg-info/
/.idea/
.env
.venv
venv
media/
.backups/
.envrc
.pdm-python
.terraform.lock.hcl
.terraform/
.nox/
__pycache__
2 changes: 2 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# disable errors related to cookiecutter templating:
disable=SC1054,SC1056,SC1072,SC1073,SC1083,SC1009
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the
upcoming release can be found in [changelog.d](changelog.d).

<!-- towncrier release notes start -->
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# deterministic-ml
Deterministic ML Models execution using Python frameworks
&nbsp;[![Continuous Integration](https://github.com/backend-developers-ltd/deterministic-ml/workflows/Continuous%20Integration/badge.svg)](https://github.com/backend-developers-ltd/deterministic-ml/actions?query=workflow%3A%22Continuous+Integration%22)&nbsp;[![License](https://img.shields.io/pypi/l/deterministic_ml.svg?label=License)](https://pypi.python.org/pypi/deterministic_ml)&nbsp;[![python versions](https://img.shields.io/pypi/pyversions/deterministic_ml.svg?label=python%20versions)](https://pypi.python.org/pypi/deterministic_ml)&nbsp;[![PyPI version](https://img.shields.io/pypi/v/deterministic_ml.svg?label=PyPI%20version)](https://pypi.python.org/pypi/deterministic_ml)

## Usage

> [!IMPORTANT]
> This package uses [ApiVer](#versioning), make sure to import `deterministic_ml.v1`.

## Versioning

This package uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
TL;DR you are safe to use [compatible release version specifier](https://packaging.python.org/en/latest/specifications/version-specifiers/#compatible-release) `~=MAJOR.MINOR` in your `pyproject.toml` or `requirements.txt`.

Additionally, this package uses [ApiVer](https://www.youtube.com/watch?v=FgcoAKchPjk) to further reduce the risk of breaking changes.
This means, the public API of this package is explicitly versioned, e.g. `deterministic_ml.v1`, and will not change in a backwards-incompatible way even when `deterministic_ml.v2` is released.

Internal packages, i.e. prefixed by `deterministic_ml._` do not share these guarantees and may change in a backwards-incompatible way at any time even in patch releases.


## Development


Pre-requisites:
- [pdm](https://pdm.fming.dev/)
- [nox](https://nox.thea.codes/en/stable/)
- [docker](https://www.docker.com/) and [docker compose plugin](https://docs.docker.com/compose/)


Ideally, you should run `nox -t format lint` before every commit to ensure that the code is properly formatted and linted.
Before submitting a PR, make sure that tests pass as well, you can do so using:
```
nox -t check # equivalent to `nox -t format lint test`
```

If you wish to install dependencies into `.venv` so your IDE can pick them up, you can do so using:
```
pdm install --dev
```

### Release process

Run `nox -s make_release -- X.Y.Z` where `X.Y.Z` is the version you're releasing and follow the printed instructions.
15 changes: 15 additions & 0 deletions docs/3rd_party/cookiecutter-rt-pkg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cookiecutter-rt-pkg Changelog

Main purpose of this file is to provide a changelog for the template itself.
It is not intended to be used as a changelog for the generated project.

This changelog will document any know **BREAKING** changes between versions of the template.
Please review this new entries carefully after applying `cruft update` before committing the changes.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Currently, `cookiecutter-rt-pkg` has no explicit versioning amd we purely rely on `cruft` diff.

## [Unreleased]

* **BREAKING** Introduced cookiecutter-rt-pkg template
Loading

0 comments on commit 218f083

Please sign in to comment.