Skip to content

Commit

Permalink
Merge pull request #8 from duarteocarmo/cookiecutter
Browse files Browse the repository at this point in the history
Make this a cookiecutter
  • Loading branch information
duarteocarmo authored Apr 13, 2024
2 parents 1733216 + ab054c4 commit a506073
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 211 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Predictor: An example project
# Duarte's boilerplate

## Development
This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template I use to kickstart python projects.

1. Make sure you are running in a virtual environment (e.g., `python3 -m venv .env`)
2. Activate it (e.g. `source .env/bin/activate`)
'Cause writing boilerplate is boring.

```shell
(.env) $ make install-dev
```
## Installation

3. Run the tests
Make sure you have cookiecutter installed:

```shell
(.env) $ make test
$ pipx install cookiecutter
```

4. For more help:
Then create your project:

```shell
(.env) $ make help
$ pipx run cookiecutter gh:duarteocarmo/boilerplate
```

Enjoy.
6 changes: 6 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"project_slug": "myproject",
"project_title": "My project",
"project_description": "A nice description",
"project_version": "24.4.13"
}
4 changes: 4 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import subprocess

print('Initializing git repository...')
subprocess.call(['git', 'init'])
49 changes: 0 additions & 49 deletions pyproject.toml

This file was deleted.

78 changes: 0 additions & 78 deletions requirements-dev.txt

This file was deleted.

36 changes: 0 additions & 36 deletions requirements.txt

This file was deleted.

6 changes: 0 additions & 6 deletions src/boilerplate/common/main.py

This file was deleted.

6 changes: 0 additions & 6 deletions tests/test_boilerplate.py

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore → {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
.DS_Store
File renamed without changes.
38 changes: 17 additions & 21 deletions Makefile → {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.PHONY: install clean lint format
.PHONY: install install-dev clean check format test api build docker

## Install for production
install:
@echo ">> Installing dependencies"
@python -m pip install --upgrade pip
@python -m pip install -e .
@uv pip install --upgrade pip
@uv pip install -e .

## Install for development
install-dev: install
@python -m pip install -e ".[dev]"
@uv pip install -e ".[dev]"

## Delete all temporary files
clean:
Expand All @@ -21,38 +21,34 @@ clean:
@rm -rf build
@rm -rf dist

## Lint using ruff
ruff:
@ruff .
## Run checks (ruff + test)
check:
@python -m ruff check .
@python -m ruff format --check .

## Format files using black
format:
@ruff . --fix
@ruff format .
@python -m ruff check . --fix
@python -m ruff format .

## Run tests
test:
@pytest --cov=src --cov-report xml --log-level=WARNING --disable-pytest-warnings

## Run checks (ruff + test)
check:
@ruff check .
@ruff format --check .
@python -m pytest --cov=src --cov-report xml --log-level=WARNING --disable-pytest-warnings

## Run api
api:
@python -m uvicorn src.boilerplate.api.main:app --reload
@python -m uvicorn src.{{cookiecutter.project_slug}}.api.main:app --reload

## Build using pip-tools
build:
@python -m pip install --upgrade pip
@python -m pip install --upgrade pip-tools
@pip-compile --output-file=requirements.txt pyproject.toml
@pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml
@uv pip install --upgrade pip
@uv pip install --upgrade pip-tools
@uv pip compile pyproject.toml -o requirements.txt
@uv pip compile pyproject.toml --extra dev -o requirements-dev.txt

## Build the docker image
docker:
docker build -f Dockerfile -t boilerplate .
docker build -f Dockerfile -t {{cookiecutter.project_slug}} .

#################################################################################
# Self Documenting Commands #
Expand Down
31 changes: 31 additions & 0 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# {{cookiecutter.project_title}}

{{cookiecutter.project_description}}

## Development

Note: We use [uv](https://github.com/astral-sh/uv?tab=readme-ov-file#getting-started) for installing things, make sure you have it.

1. Make sure you are running in a virtual environment (e.g., `python3 -m venv .env`)
2. Activate it (e.g. `source .env/bin/activate`)

```shell
(.env) $ make install-dev
```

3. Run the tests

```shell
(.env) $ make test
```

4. Run the API

```shell
(.env) $ make api
```

5. For more help:
```shell
(.env) $ make help
```
File renamed without changes.
30 changes: 30 additions & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[project]
name = "{{cookiecutter.project_slug}}"
version = "{{cookiecutter.project_version}}"
description = "{{cookiecutter.project_description}}"
readme = "README.md"
requires-python = ">=3.10"
dependencies = ["fastapi", "uvicorn"]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov", "ruff", "watchdog", "httpx"]

[tool.ruff]
exclude = [".env", ".venv", "venv", "notebooks"]
line-length = 79

[tool.ruff.lint]
ignore = ["E501"]
select = ["E", "F", "I", "W"]
fixable = ["I"]

[tool.coverage.paths]
source = ["src"]

[tool.coverage.run]
branch = true
relative_files = true

[tool.coverage.report]
show_missing = true
fail_under = 80
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from fastapi import FastAPI
from fastapi.responses import RedirectResponse

from boilerplate.common.main import hello_world
from {{cookiecutter.project_slug}}.common.main import hello_world

app = FastAPI(
title="Boilerplate API",
version=pkg_resources.get_distribution("boilerplate").version,
title="{{cookiecutter.project_slug}} API",
version=pkg_resources.get_distribution("{{cookiecutter.project_slug}}").version,
)


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from {{cookiecutter.project_slug}}.api.something import a_cool_function


def hello_world():
a_cool_function()
return "We are here"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from boilerplate.api.main import app
from {{cookiecutter.project_slug}}.api.main import app
from fastapi.testclient import TestClient

client = TestClient(app)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from {{cookiecutter.project_slug}}.common.main import hello_world


class TestPackage:
def test_hello_world(self):
assert hello_world() == "We are here"

0 comments on commit a506073

Please sign in to comment.