Skip to content

Commit

Permalink
refactor(py): introduce cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 13, 2024
1 parent b38b7c3 commit d811568
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 31 deletions.
9 changes: 7 additions & 2 deletions template/py/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"project_name": "My Awesome Project",
"project_slug": "{{ cookiecutter.package_name | slugify }}",
"project_slug": "{{ cookiecutter.project_name | trim | slugify }}",
"package_name": "{{ cookiecutter.project_slug | replace('-', '_') }}",
"python_version": "3.10",
"short_description": "A nice python package",
"github_username": "your-org-or-username",
"full_name": "Firstname Lastname",
"email": "email@example.com",
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}",
"__prompts__": {
"package_name": "Select your project name",
"project_name": "Select your project name",
"project_slug": "Project slug",
"package_name": "Package name",
"python_version": "Python version",
"short_description": "Short description",
"github_username": "GitHub username or organization",
"full_name": "Author full name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
Please make sure:
- you have read the contributing guidelines:
https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/blob/main/docs/CONTRIBUTING.md
https://github.com/{{cookiecutter.__gh_slug}}/blob/main/docs/CONTRIBUTING.md
- you have updated the changelog (if needed):
https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/blob/main/CHANGELOG.md
https://github.com/{{cookiecutter.__gh_slug}}/blob/main/CHANGELOG.md
-->
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
context: .
load: true
tags: |
ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:latest
ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:${GITHUB_REF_NAME:1}
ghcr.io/{{cookiecutter.__gh_slug}}:latest
ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
-
name: Test it before Push
run: |
docker run --rm ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:latest
docker run --rm ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:${GITHUB_REF_NAME:1}
docker run --rm ghcr.io/{{cookiecutter.__gh_slug}}:latest
docker run --rm ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
-
name: Build and Push
uses: docker/build-push-action@v5
Expand All @@ -50,5 +50,5 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:latest
ghcr.io/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}:${GITHUB_REF_NAME:1}
ghcr.io/{{cookiecutter.__gh_slug}}:latest
ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
4 changes: 2 additions & 2 deletions template/py/{{cookiecutter.project_slug}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wish to make by creating a new issue before making the change.
## Reporting issues

Before reporting an issue on the
[issue tracker](https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/issues),
[issue tracker](https://github.com/{{cookiecutter.__gh_slug}}/issues),
please check that it has not already been reported by searching for some related
keywords.

Expand Down Expand Up @@ -42,7 +42,7 @@ If the required subsection does not exist yet under **Unreleased**, create it!
This is no different from other Python projects.

```shell
git clone https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}
git clone https://github.com/{{cookiecutter.__gh_slug}}
cd {{cookiecutter.project_slug}}
make test
```
Expand Down
8 changes: 4 additions & 4 deletions template/py/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:{{py_version}} AS venv
FROM python:{{cookiecutter.python_version}} AS venv

LABEL author="{{authors}}"
LABEL author="{{cookiecutter.full_name}}"

# set environment variables
# NO Cache
Expand All @@ -19,9 +19,9 @@ RUN . venv/bin/activate && \
pip install -r requirement.txt


FROM python:{{py_version}}-slim
FROM python:{{cookiecutter.python_version}}-slim

LABEL author="{{authors}}"
LABEL author="{{cookiecutter.full_name}}"

COPY --from=venv /app/venv /app/venv
ENV PATH /app/venv/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion template/py/{{cookiecutter.project_slug}}/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 {{authors}}
Copyright (c) 2021 {{cookiecutter.full_name}}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions template/py/{{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# {{project-name}}
# {{cookiecutter.project_slug}}

[![CI](https://github.com/{{cookiecutter.github_username}}/{{project-name}}/workflows/CI/badge.svg)](https://github.com/{{cookiecutter.github_username}}/{{project-name}}/actions)
[![Coverage Status](https://coveralls.io/repos/github/{{cookiecutter.github_username}}/{{project-name}}/badge.svg?branch=main)](https://coveralls.io/github/{{cookiecutter.github_username}}/{{project-name}}?branch=main)
[![PyPI version](https://badge.fury.io/py/{{project-name}}.svg)](https://badge.fury.io/py/{{project-name}})
[![Python Versions](https://img.shields.io/pypi/pyversions/{{project-name}}.svg)](https://pypi.org/project/{{project-name}}/)
[![CI](https://github.com/{{cookiecutter.__gh_slug}}/workflows/CI/badge.svg)](https://github.com/{{cookiecutter.__gh_slug}}/actions)
[![Coverage Status](https://coveralls.io/repos/github/{{cookiecutter.__gh_slug}}/badge.svg?branch=main)](https://coveralls.io/github/{{cookiecutter.__gh_slug}}?branch=main)
[![PyPI version](https://badge.fury.io/py/{{cookiecutter.project_slug}}.svg)](https://badge.fury.io/py/{{cookiecutter.project_slug}})
[![Python Versions](https://img.shields.io/pypi/pyversions/{{cookiecutter.project_slug}}.svg)](https://pypi.org/project/{{cookiecutter.project_slug}}/)

## Overview

{{project-name}} is a Python project that aims to ...
{{cookiecutter.project_slug}} is a Python project that aims to ...

## Features

Expand All @@ -23,18 +23,18 @@
## Installation

```bash
pip install {{project-name}}
pip install {{cookiecutter.project_slug}}
```

## Quick Start

Here's a simple example to get you started:

```python
import {{project-name}}
import {{cookiecutter.project_slug}}

# Example usage
result = {{project-name}}.do_something()
result = {{cookiecutter.project_slug}}.do_something()
print(result)
```

Expand Down
10 changes: 5 additions & 5 deletions template/py/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ build-backend = "hatchling.build"
[project]
name = "{{cookiecutter.project_slug}}"
version = "0.0.1"
description = "{{py_proj_desc}}"
description = "{{cookiecutter.short_description}}"
readme = "README.md"
requires-python = ">=3.11"
license = "MIT"
authors = [
{ name = "{{cookiecutter.github_username}}" },
{ name = "{{cookiecutter.full_name}}" },
]
classifiers = [
"Development Status :: 4 - Beta",
Expand All @@ -31,9 +31,9 @@ dev = [
]

[project.urls]
Documentation = "https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}#readme"
Issues = "https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/issues"
Source = "https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}"
Documentation = "https://github.com/{{cookiecutter.__gh_slug}}#readme"
Issues = "https://github.com/{{cookiecutter.__gh_slug}}/issues"
Source = "https://github.com/{{cookiecutter.__gh_slug}}"

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down

0 comments on commit d811568

Please sign in to comment.