Skip to content

Commit

Permalink
feat: remove CI/CD, add PostgreSQL + Adminer options (#1)
Browse files Browse the repository at this point in the history
* feat: removed CI/CD, added PostgreSQL and Adminer options

* fix(LICENSE): typo in name

* chore: documented new cookiecutter options
  • Loading branch information
vanolucas authored May 25, 2024
1 parent aa2e59e commit 3eec709
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 419 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
],
"settings": {
"editor.formatOnSave": true,
"[json]": {
"editor.formatOnSave": false
},
"[markdown]": {
"editor.formatOnSave": false
},
"[toml]": {
"editor.formatOnSave": false
},
Expand Down
13 changes: 0 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,14 @@ reports/
# cruft
*.rej

# Data
*.csv*
*.dat*
*.pickle*
*.xls*
*.zip*
data/

# direnv
.envrc

# dotenv
.env

# Hypothesis
.hypothesis/

# Jupyter
*.ipynb
.ipynb_checkpoints/
notebooks/

# macOS
.DS_Store
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/radix-ai/poetry-cookiecutter) [![Open in GitHub Codespaces](https://img.shields.io/static/v1?label=GitHub%20Codespaces&message=Open&color=blue&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=444870763)
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/vanolucas/cookiecutter-poetry)

# 🍪 Poetry Cookiecutter

A modern [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for scaffolding Python packages and apps.

## 🍿 Demo

See 👖 [Conformal Tights](https://github.com/radix-ai/conformal-tights) for an example of a Python package that is scaffolded with this template. Contributing to this package can be done with a single click by [starting a GitHub Codespace](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=765698489&skip_quickstart=true) or [starting a Dev Container](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/radix-ai/conformal-tights).

## 🎁 Features

- 🧑‍💻 Quick and reproducible development environments with VS Code's [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers), PyCharm's [Docker Compose interpreter](https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html#docker-compose-remote), and [GitHub Codespaces](https://github.com/features/codespaces)
Expand All @@ -20,10 +16,10 @@ See 👖 [Conformal Tights](https://github.com/radix-ai/conformal-tights) for an
- ✅ Code linting with [Pre-commit](https://pre-commit.com/), [Mypy](https://github.com/python/mypy), and [Ruff](https://github.com/charliermarsh/ruff)
- 🏷 Optionally follows the [Conventional Commits](https://www.conventionalcommits.org/) standard to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/) with [Commitizen](https://github.com/commitizen-tools/commitizen)
- 💌 Verified commits with [GPG](https://gnupg.org/)
- ♻️ Continuous integration with [GitHub Actions](https://docs.github.com/en/actions) or [GitLab CI/CD](https://docs.gitlab.com/ee/ci/)
- 🧪 Test coverage with [Coverage.py](https://github.com/nedbat/coveragepy)
- 🏗 Scaffolding updates with [Cookiecutter](https://github.com/cookiecutter/cookiecutter) and [Cruft](https://github.com/cruft/cruft)
- 🧰 Dependency updates with [Dependabot](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates)
- 🗄️ Option to deploy a [PostgreSQL](https://www.postgresql.org/) SQL database Docker container and the [Adminer](https://www.adminer.org/) Web interface to manage it.

## ✨ Using

Expand All @@ -41,14 +37,14 @@ To create a new Python project with this template:
3. Run the following command in the parent directory of the cloned repository to apply the Poetry Cookiecutter template:

```sh
cruft create -f https://github.com/radix-ai/poetry-cookiecutter
cruft create -f https://github.com/vanolucas/cookiecutter-poetry
```

<details>

<summary>⚠️ If your repository name ≠ the project's slugified name</summary>

If your repository name differs from your project's slugified name (see `project_name` in the [Template parameters](https://github.com/radix-ai/poetry-cookiecutter#-template-parameters) below), you will need to copy the scaffolded project into the repository with:
If your repository name differs from your project's slugified name (see `project_name` in the [Template parameters](https://github.com/vanolucas/cookiecutter-poetry#-template-parameters) below), you will need to copy the scaffolded project into the repository with:

```sh
cp -r {project-name}/ {repository-name}/
Expand Down Expand Up @@ -78,11 +74,18 @@ To update your Python project to the latest template version:
| `project_url` <br> "<https://github.com/user/spline-reticulator>" | The URL to the project's repository. |
| `author_name` <br> "John Smith" | The full name of the primary author of the project. |
| `author_email` <br> "<john@example.com>" | The email address of the primary author of the project. |
| `python_version` <br> "3.10" | The minimum Python version that the project requires. |
| `python_version` <br> "3.12" | The minimum Python version that the project requires. |
| `development_environment` <br> ["simple", "strict"] | Whether to configure the development environment with a focus on simplicity or with a focus on strictness. In strict mode, additional [Ruff rules](https://beta.ruff.rs/docs/rules/) are added, and tools such as [Mypy](https://github.com/python/mypy) and [Pytest](https://github.com/pytest-dev/pytest) are set to strict mode. |
| `with_conventional_commits` <br> ["0", "1"] | If "1", [Commitizen](https://github.com/commitizen-tools/commitizen) will verify that your commits follow the [Conventional Commits](https://www.conventionalcommits.org/) standard. In return, `cz bump` may be used to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/). |
| `with_fastapi_api` <br> ["0", "1"] | If "1", [FastAPI](https://github.com/tiangolo/fastapi) is added as a run time dependency, FastAPI API stubs and tests are added, a `poe api` command for serving the API is added. |
| `with_typer_cli` <br> ["0", "1"] | If "1", [Typer](https://github.com/tiangolo/typer) is added as a run time dependency, Typer CLI stubs and tests are added, the package itself is registered as a CLI. |
| `continuous_integration` <br> ["GitHub", "GitLab"] | Whether to include a [GitHub Actions](https://docs.github.com/en/actions) or a [GitLab CI/CD](https://docs.gitlab.com/ee/ci/) continuous integration workflow for testing the project, and publishing the package or deploying the app. |
| `private_package_repository_name` <br> "Private Package Repository" | Optional name of a private package repository to install packages from and publish this package to. |
| `private_package_repository_url` <br> "<https://pypi.example.com/simple>" | Optional URL of a private package repository to install packages from and publish this package to. Make sure to include the `/simple` suffix. For instance, when using a GitLab Package Registry this value should be of the form `https://gitlab.com/api/v4/projects/` `{project_id}` `/packages/pypi/simple`. |
| `with_postgresql` <br> "false" | Enable a Docker container with PostgreSQL running. The PostgreSQL data will be stored in a Docker volume. |
| `postgresql_server` <br> "db" | PostgreSQL server name. (Only used if `with_postgresql` is `true`.) |
| `postgresql_user` <br> "db" | PostgreSQL admin username. (Only used if `with_postgresql` is `true`.) |
| `postgresql_password` <br> "db" | PostgreSQL admin user password. (Only used if `with_postgresql` is `true`.) |
| `postgresql_db_name` <br> "db" | Name of the database to create in the PostgreSQL server. (Only used if `with_postgresql` is `true`.) |
| `postgresql_forward_port` <br> "5432" | Port to expose the PostgreSQL server. (Only used if `with_postgresql` is `true`.) |
| `with_adminer` <br> "false" | Enable a Docker container with the Adminer SQL database management Web interface. |
| `adminer_forward_port` <br> "51003" | Port to expose the HTTP server for the Adminer database management Web interface. (Only used if `with_adminer` is `true`.) |
14 changes: 9 additions & 5 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
"project_url": "https://github.com/user/my-{{ cookiecutter.project_type }}",
"author_name": "John Smith",
"author_email": "john@example.com",
"python_version": "{% if cookiecutter.project_type == 'app' %}3.12{% else %}3.10{% endif %}",
"python_version": "3.12",
"development_environment": [
"simple",
"strict"
],
"with_conventional_commits": "{% if cookiecutter.development_environment == 'simple' %}0{% else %}1{% endif %}",
"with_fastapi_api": "0",
"with_typer_cli": "0",
"continuous_integration": [
"GitHub",
"GitLab"
],
"private_package_repository_name": "",
"private_package_repository_url": "",
"with_postgresql": false,
"postgresql_server": "db",
"postgresql_user": "{{ cookiecutter.postgresql_server }}",
"postgresql_password": "{{ cookiecutter.postgresql_user }}",
"postgresql_db_name": "db",
"postgresql_forward_port": "5432",
"with_adminer": false,
"adminer_forward_port": "51003",
"__docker_image": "python:$PYTHON_VERSION-slim",
"__docstring_style": "NumPy",
"__project_name_kebab_case": "{{ cookiecutter.project_name|slugify }}",
Expand Down
14 changes: 0 additions & 14 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
development_environment = "{{ cookiecutter.development_environment }}"
with_fastapi_api = int("{{ cookiecutter.with_fastapi_api }}")
with_typer_cli = int("{{ cookiecutter.with_typer_cli }}")
continuous_integration = "{{ cookiecutter.continuous_integration }}"
is_application = "{{ cookiecutter.project_type == 'app' }}" == "True"

# Remove py.typed and Dependabot if not in strict mode.
Expand All @@ -23,16 +22,3 @@
if not with_typer_cli:
os.remove(f"src/{project_name}/cli.py")
os.remove("tests/test_cli.py")

# Remove the continuous integration provider that is not selected.
if continuous_integration != "GitHub":
shutil.rmtree(".github/")
elif continuous_integration != "GitLab":
os.remove(".gitlab-ci.yml")

# Remove unused GitHub Actions workflows.
if continuous_integration == "GitHub":
if is_application:
os.remove(".github/workflows/publish.yml")
else:
os.remove(".github/workflows/deploy.yml")
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
"customizations": {
"vscode": {
"extensions": [
"bierner.markdown-mermaid",
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"charliermarsh.ruff",
{%- if cookiecutter.continuous_integration == "GitHub" %}
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
{%- elif cookiecutter.continuous_integration == "GitLab" %}
"GitLab.gitlab-workflow",
{%- endif %}
"DavidAnson.vscode-markdownlint",
"mechatroner.rainbow-csv",
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-toolsai.jupyter",
"ryanluker.vscode-coverage-gutters",
"tamasfe.even-better-toml",
"visualstudioexptteam.vscodeintellicode"
"visualstudioexptteam.vscodeintellicode",
"yzhang.markdown-all-in-one"
],
"settings": {
"coverage-gutters.coverageFileNames": [
Expand All @@ -42,7 +41,9 @@
100
],
"files.autoSave": "onFocusChange",
"jupyter.kernels.excludePythonEnvironments": ["/usr/local/bin/python"],
"jupyter.kernels.excludePythonEnvironments": [
"/usr/local/bin/python"
],
"mypy-type-checker.importStrategy": "fromEnvironment",
"notebook.codeActionsOnSave": {
"notebook.source.fixAll": "explicit",
Expand Down
7 changes: 7 additions & 0 deletions {{ cookiecutter.__project_name_kebab_case }}/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{%- if cookiecutter.with_postgresql %}
# PostgreSQL database.
POSTGRESQL_SERVER={{ cookiecutter.postgresql_server }}
POSTGRESQL_USER={{ cookiecutter.postgresql_user }}
POSTGRESQL_PASSWORD={{ cookiecutter.postgresql_password }}
POSTGRESQL_DB_NAME={{ cookiecutter.postgresql_db_name }}
{%- endif %}
7 changes: 7 additions & 0 deletions {{ cookiecutter.__project_name_kebab_case }}/.env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{%- if cookiecutter.with_postgresql %}
# PostgreSQL database.
POSTGRESQL_SERVER=db
POSTGRESQL_USER=db
POSTGRESQL_PASSWORD=db
POSTGRESQL_DB_NAME=db
{%- endif %}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3eec709

Please sign in to comment.