Skip to content

Commit

Permalink
Enh/improve some templates (#38)
Browse files Browse the repository at this point in the history
Closes #37

- Renamed CHANGES.rst to CHANGELOG.rst
- Remove leading '$' for commands to easy copy/pasting
- Moved 'how to release' section from CONTRIBUTING to a dedicated docs/releasing.rst
- Added 'all' dependency target to install both docs and dev dependencies
- Added pre-commit install to the 'make dev' command
  • Loading branch information
bzah authored May 13, 2024
2 parents 6b81aca + eb50c72 commit 33f63b3
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 183 deletions.
38 changes: 19 additions & 19 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ Ready to contribute? Here's how to set up `cookiecutter-pypackage` for local dev

.. code-block:: bash
$ cd path_for_the_repo
$ git clone [email protected]:YOUR_NAME/cookiecutter-pypackage.git
cd path_for_the_repo
git clone [email protected]:YOUR_NAME/cookiecutter-pypackage.git
#. Assuming you have virtualenv installed (If you have Python 3.8+ this should already be there), you can create a new environment for your local development by typing:

.. code-block:: bash
$ virtualenv cookiecutter-pypackage-env
$ source cookiecutter-pypackage-env/bin/activate
virtualenv cookiecutter-pypackage-env
source cookiecutter-pypackage-env/bin/activate
This should change the shell to look something like:

Expand All @@ -78,35 +78,35 @@ Ready to contribute? Here's how to set up `cookiecutter-pypackage` for local dev

.. code-block:: bash
$ git checkout -b name-of-your-bugfix-or-feature
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.

#. When you're done making changes, check that your changes pass flake8. Since, this package contains mostly templates the flake should be run for tests directory:

.. code-block:: bash
$ flake8 ./tests
flake8 ./tests
#. The next step would be to run the test cases. `cookiecutter-pypackage` testing uses the `pytest` framework. Before you run `pytest` you should ensure all dependencies are installed:

.. code-block:: bash
$ pip install -r requirements_dev.txt
$ pytest ./tests
pip install -r requirements_dev.txt
pytest ./tests
If you get any errors while installing cryptography package (something like `#include <openssl/aes.h>`). Please update your pip version and try again:

.. code-block:: bash
# Update pip
$ pip install -U pip
pip install -U pip
#. Before raising a pull request you should also run tox. This will run the tests across different versions of Python:

.. code-block:: bash
$ tox
tox
If you are missing flake8, pytest and/or tox, just `pip install` them into your virtualenv.

Expand All @@ -116,9 +116,9 @@ Ready to contribute? Here's how to set up `cookiecutter-pypackage` for local dev

.. code-block:: bash
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
git add .
git commit -m "Your detailed description of your changes."
git push origin name-of-your-bugfix-or-feature
#. Submit a pull request through the GitHub website.

Expand Down Expand Up @@ -146,27 +146,27 @@ To write and run your new test, follow these steps:

.. code-block:: bash
$ git stash
$ git stash list
git stash
git stash list
#. Run your test and confirm that your test fails. If your test does not fail, rewrite the test until it fails on the original code:

.. code-block:: bash
$ pytest ./tests
pytest ./tests
#. (Optional) Run the tests with tox to ensure that the code changes work with different Python versions:

.. code-block:: bash
$ tox
tox
#. Proceed work on your bug fix or new feature or restore your changes. To restore your stashed changes and confirm their restoration:

.. code-block:: bash
$ git stash pop
$ git stash list
git stash pop
git stash list
#. Rerun your test and confirm that your test passes. If it passes, congratulations!

Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
BAKE_OPTIONS=--no-input
BAKE_OPTIONS ?= --no-input
NO_CRUFT = generated_with_cruft=n

help:
@echo "bake Generate project using defaults"
@echo "help Show this help"
@echo "test Run the tests"
@echo "replay Replay last cookiecutter run and watch for changes"
@echo "watch Generate project using defaults and watch for changes"


bake: # Generate project using defaults
cookiecutter $(BAKE_OPTIONS) . --overwrite-if-exists
cookiecutter $(BAKE_OPTIONS) . --overwrite-if-exists $(NO_CRUFT)

watch: bake
watchmedo shell-command -p '*.*' -c 'make bake -e BAKE_OPTIONS=$(BAKE_OPTIONS)' -W -R -D \{{cookiecutter.project_slug}}/
watchmedo shell-command -p '*.*' -c 'make bake -e BAKE_OPTIONS=$(BAKE_OPTIONS)' -W -R -D \{{cookiecutter.project_slug}}/ $(NO_CRUFT)

replay: BAKE_OPTIONS=--replay
replay: watch
;

test:
pytest
pytest
21 changes: 20 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,24 @@
"Not open source"
],
"generated_with_cruft": "y",
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}"
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}",
"__prompts__": {
"full_name": "Your full name",
"email": "Your email address",
"github_username": "Your GitHub username (or organization)",
"project_name": "The name of your project",
"project_short_description": "A short description of your project",
"pypi_username": "Your PyPI username (or organization)",
"version": "The version of your project",
"use_pytest": "Do you want to use pytest?",
"use_black": "Do you want to use Black for code formatting?",
"use_conda": "Do you want to add configurations for Anaconda package management?",
"add_pyup_badge": "Do you want to add a pyup.io badge? (not recommended)",
"make_docs": "Do you want to generate documentation files",
"add_translations": "Do you want to add translations?",
"command_line_interface": "Which command-line interface do you want to use?",
"create_author_file": "Do you want to create an AUTHORS.rst file?",
"open_source_license": "Which open-source license do you want to use?",
"generated_with_cruft": "Was this project generated with Cruft? (Add a '.cruft.json' file)"
}
}
2 changes: 1 addition & 1 deletion tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_bake_without_author_file(cookies):
# Assert there are no spaces in the toc tree
docs_index_path = result.project_path.joinpath("docs/index.rst")
with open(str(docs_index_path)) as index_file:
assert "contributing\n changes" in index_file.read()
assert "releasing\n changes" in index_file.read()

# Check that
pyproject_path = result.project_path.joinpath("pyproject.toml")
Expand Down
27 changes: 27 additions & 0 deletions {{cookiecutter.project_slug}}/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=========
Changelog
=========

`Unreleased <https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}>`_ (latest)
{{ '-' * ('`Unreleased <https://github.com/' + cookiecutter.github_username + '/' + cookiecutter.project_slug + '>`_ (latest)')|length }}

Contributors:

Changes
^^^^^^^
* No change.

Fixes
^^^^^
* No change.

.. _changes_{{ cookiecutter.version }}:

`v{{ cookiecutter.version }} <https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/tree/{{ cookiecutter.version }}>`_
{{ '-' * ('`v' + cookiecutter.version + ' <https://github.com/' + cookiecutter.github_username + '/' + cookiecutter.project_slug + '/tree/' + cookiecutter.version + '>`_')|length }}

Contributors: {{ cookiecutter.full_name }} `{{ cookiecutter.github_username }} <https://github.com/{{ cookiecutter.github_username }}>`_

Changes
^^^^^^^
* First release on PyPI.
8 changes: 0 additions & 8 deletions {{cookiecutter.project_slug}}/CHANGES.rst

This file was deleted.

Loading

0 comments on commit 33f63b3

Please sign in to comment.