Skip to content

Commit

Permalink
Added prettier pre-commit hook and formatted files (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenibrewer authored Oct 23, 2023
1 parent 9c49026 commit 41d853b
Show file tree
Hide file tree
Showing 27 changed files with 348 additions and 349 deletions.
48 changes: 22 additions & 26 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Cookiecutter Poetry",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/cookiecutter:2": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},
"name": "Cookiecutter Poetry",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/cookiecutter:2": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"ms-python.python"
],
"settings": {
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.defaultInterpreterPath": "/workspaces/cookiecutter-poetry/.venv/bin/python",
"python.testing.pytestPath": "/workspaces/cookiecutter-poetry/.venv/bin/pytest"
}
}
}
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": ["ms-python.python", "editorconfig.editorconfig"],
"settings": {
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.defaultInterpreterPath": "/workspaces/cookiecutter-poetry/.venv/bin/python",
"python.testing.pytestPath": "/workspaces/cookiecutter-poetry/.venv/bin/pytest"
}
}
}
}
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
max_line_length = 120

[*.json]
indent_style = space
indent_size = 4
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Steps to reproduce the behavior:

**System [please complete the following information]:**

- OS: e.g. [Ubuntu 18.04]
- Language Version: [e.g. Python 3.8]
- Virtual environment: [e.g. Poetry 1.1.13]
- OS: e.g. [Ubuntu 18.04]
- Language Version: [e.g. Python 3.8]
- Virtual environment: [e.g. Poetry 1.1.13]

**Additional context**

Expand Down
8 changes: 4 additions & 4 deletions .github/actions/setup-poetry-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "setup-poetry-env"
description: "Composite action to setup the Python and poetry environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.11"
python-version:
required: false
description: "The python version to use"
default: "3.11"

runs:
using: "composite"
Expand Down
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
**PR Checklist**

- [ ] A description of the changes is added to the description of this PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [ ] If you've fixed a bug or added code that should be tested, add tests!
- [ ] Documentation in `docs` is updated
- [ ] A description of the changes is added to the description of this PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [ ] If you've fixed a bug or added code that should be tested, add tests!
- [ ] Documentation in `docs` is updated

**Description of changes**

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ["3.8", "3.9", "3.10", "3.11"]
fail-fast: false
steps:
- name: Check out
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ repos:
hooks:
- id: black
exclude: ^{{cookiecutter.project_name}}

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: prettier
exclude: ^{{cookiecutter.project_name}}
99 changes: 42 additions & 57 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing

Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
Contributions are welcome, and they are greatly appreciated!
Every little bit helps, and credit will always be given.

You can contribute in many ways:

Expand All @@ -13,128 +13,114 @@ Report bugs at <https://github.com/fpgmaas/cookiecutter-poetry/issues

If you are reporting a bug, please include:

- Your operating system name and version.
- Any details about your local setup that might be helpful in
troubleshooting.
- Detailed steps to reproduce the bug.
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.

## Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with "bug"
and "help wanted" is open to whoever wants to implement a fix for it.
Look through the GitHub issues for bugs.
Anything tagged with "bug" and "help wanted" is open to whoever wants to implement a fix for it.

## Implement Features

Look through the GitHub issues for features. Anything tagged with
"enhancement" and "help wanted" is open to whoever wants to
implement it.
Look through the GitHub issues for features.
Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it.

## Write Documentation

Cookiecutter PyPackage could always use more documentation, whether as
part of the official docs, in docstrings, or even on the web in blog
posts, articles, and such.
Cookiecutter PyPackage could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.

## Submit Feedback

The best way to send feedback is to file an issue at
<https://github.com/fpgmaas/cookiecutter-poetry/issues.
The best way to send feedback is to file an issue at <https://github.com/fpgmaas/cookiecutter-poetry/issues.

If you are proposing a new feature:

- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to
implement.
- Remember that this is a volunteer-driven project, and that
contributions are welcome :)
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)

# Get Started!

Ready to contribute? Here\'s how to set up
`cookiecutter-poetry` for local development. Please note
this documentation assumes you already have `poetry` and
`git` installed and ready to go.
Ready to contribute? Here\'s how to set up `cookiecutter-poetry` for local development.
Please note this documentation assumes you already have `poetry` and `git` installed and ready to go.

1. Fork the `cookiecutter-poetry` repo on GitHub.

2. Clone your fork locally:

``` bash
cd <directory_in_which_repo_should_be_created
git clone [email protected]:YOUR_NAME/cookiecutter-poetry.git
```
```bash
cd <directory_in_which_repo_should_be_created
git clone [email protected]:YOUR_NAME/cookiecutter-poetry.git
```

3. Now we need to install the environment. Navigate into the project directory:
3. Now we need to install the environment.
Navigate into the project directory:

``` bash
```bash
cd cookiecutter-poetry
```

If you are using `pyenv`, select a version to use locally. (See
installed versions with `pyenv versions`)
If you are using `pyenv`, select a version to use locally.
(See installed versions with `pyenv versions`)

``` bash
```bash
pyenv local <x.y.z
```

Then, install and activate the environment with:

``` bash
```bash
poetry install
poetry shell
```


4. Install pre-commit to run linters/formatters at commit time:

poetry run pre-commit install
poetry run pre-commit install

5. Create a branch for local development:

``` bash
```bash
git checkout -b name-of-your-bugfix-or-feature
```

Now you can make your changes locally.

6. Don\'t forget to add test cases for your added functionality to the
`tests` directory.
6. Don\'t forget to add test cases for your added functionality to the `tests` directory.

7. When you\'re done making changes, check that your changes pass the
formatting tests.
7. When you\'re done making changes, check that your changes pass the formatting tests.

``` bash
```bash
make check
```

8. Now, validate that all unit tests are passing:

``` bash
```bash
make test
```

9. Before raising a pull request you should also run tox. This will
run the tests across different versions of Python:
9. Before raising a pull request you should also run tox. This will run the tests across different versions of Python:

``` bash
```bash
tox
```

This requires you to have multiple versions of Python installed. This
step is also triggered in the CI/CD pipeline, so you could also choose
to skip this step locally.
This requires you to have multiple versions of Python installed.
This step is also triggered in the CI/CD pipeline, so you could also choose to skip this step locally.

10. Reflect your changes in the documentation. Update relevant files in
the `docs` directory, and potentially the `README`. You can check the
updated documentation with
10. Reflect your changes in the documentation. Update relevant files in the `docs` directory, and potentially the `README`.
You can check the updated documentation with:

``` bash
```bash
make docs
```

11. Commit your changes and push your branch to GitHub:

``` bash
```bash
git add .
git commit -m "Your detailed description of your changes."
git push origin name-of-your-bugfix-or-feature
Expand All @@ -148,5 +134,4 @@ Before you submit a pull request, check that it meets these guidelines:

1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated.
Put your new functionality into a function with a docstring, and add
the feature to the list in README.rst.
Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


<p align="center">
<img width="600" src="https://raw.githubusercontent.com/fpgmaas/cookiecutter-poetry/main/docs/static/cookiecutter.svg">
</p style = "margin-bottom: 2rem;">
Expand All @@ -12,52 +10,54 @@
[![Docs](https://img.shields.io/badge/docs-gh--pages-blue)](https://fpgmaas.github.io/cookiecutter-poetry/)
[![License](https://img.shields.io/github/license/fpgmaas/cookiecutter-poetry)](https://img.shields.io/github/license/fpgmaas/cookiecutter-poetry)


This is a modern Cookiecutter template that can be used to initiate a Python project with all the necessary tools for development, testing, and deployment. It supports the following features:

- [Poetry](https://python-poetry.org/) for dependency management
- CI/CD with [GitHub Actions](https://github.com/features/actions)
- Pre-commit hooks with [pre-commit](https://pre-commit.com/)
- Code quality with [black](https://pypi.org/project/black/), [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/), and [deptry](https://github.com/fpgmaas/deptry/)
- Code quality with:
- [black](https://pypi.org/project/black/)
- [ruff](https://github.com/charliermarsh/ruff)
- [mypy](https://mypy.readthedocs.io/en/stable/)
- [deptry](https://github.com/fpgmaas/deptry/)
- [prettier](https://prettier.io/)
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing and coverage with [pytest](https://docs.pytest.org/en/7.1.x/) and [codecov](https://about.codecov.io/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
- Compatibility testing for multiple versions of Python with [Tox](https://tox.wiki/en/latest/)
- Containerization with [Docker](https://www.docker.com/)

---

<p align="center">
<a href="https://fpgmaas.github.io/cookiecutter-poetry/">Documentation</a> - <a href="https://github.com/fpgmaas/cookiecutter-poetry-example">Example</a> -
<a href="https://pypi.org/project/cookiecutter-poetry/">PyPi</a>
</p>

---




## Quickstart

On your local machine, navigate to the directory in which you want to
create a project directory, and run the following two commands:

``` bash
```bash
pip install cookiecutter-poetry
ccp
```

Alternatively, install `cookiecutter` and directly pass the URL to this
Github repository to the `cookiecutter` command:

``` bash
```bash
pip install cookiecutter
cookiecutter https://github.com/fpgmaas/cookiecutter-poetry.git
```

Create a repository on GitHub, and then run the following commands, replacing `<project-name>`, with the name that you gave the Github repository and
`<github_author_handle>` with your Github username.

``` bash
```bash
cd <project_name>
git init -b main
git add .
Expand All @@ -68,9 +68,9 @@ git push -u origin main

Finally, install the environment and the pre-commit hooks with

```bash
make install
```
```bash
make install
```

You are now ready to start development on your project! The CI/CD
pipeline will be triggered when you open a pull request, merge to main,
Expand Down
Loading

0 comments on commit 41d853b

Please sign in to comment.