Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

hrshdhgd/sphintoxetry-cookiecutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sphintoxetry-cookiecutter

A Cookiecutter template for projects using Sphinx + tox + poetry. This template was developed thanks to the tutorials by the cookiecutter project along with the instructions provided in HelloCookieCutter1 by Bruce Eckel. The tox configuration is partly accreditted to Charles Tapley Hoyt's cookiecutter implementation.

Getting started

First, install the cruft package. Cruft enables keeping projects up-to-date with future updates made to this original template.

pip install cruft

Next, create a project using the sphintoxetry-cookiecutter template.

cruft create https://github.com/hrshdhgd/sphintoxetry-cookiecutter

This kickstarts an interactive session where you declare the following:

  • project_name: Name of the project. [defaults to: Project_X]
  • project_description: Description of the project. [defaults to: This is the project description.].
  • file_name: The name of the main python file. [defaults to: main for main.py]
  • greeting_recipient: Just a string that will be displayed when the boilerplate code is invoked. [defaults to: World as in Hello, World!]
  • full_name: Your name [defaults to: Harshad Hegde]
  • email: your email [defaults to: [email protected]]
  • license: Choose one from [MIT, BSD-3, GNU GPL v3.0, Apache Software License 2.0] [defaults to: MIT]
  • ⚠️github_token_variable_name_for_doc_deployment: The github token variable name for document deployment using Sphinx. [defaults to: GH_TOKEN]
  • ⚠️github_token_variable_name_for_pypi_deployment: The github token variable name which aligns with your autogenerated PyPI token for making releases. [defaults to: PYPI_TOKEN]

⚠️ Do NOT enter actual token here, this is just the variable name that holds the token value in the project repository's Secrets.

This will generate the project folder abiding by the template configuration specified by sphintoxetry-cookiecutter in the cookiecutter.json file.

What does this do?

The following files and directories are autogenerated in the project:

  • Github wokflows:
    • For code quality checks (qc.yml)
    • Documentation deployment (deploy-docs.yml)
    • PyPI deployment (pypi-publish.yml)
  • docs directory with Sphinx configuration files and an index.rstfile.
  • src directory structure with the project_name directory within it.
    • Within the project_name directory, there are 2 python files:
      • main_file.py
      • cli.py for click commands.
  • tests directory with a very basic test.
  • poetry compatible pyproject.toml file containing minimal package requirements.
  • tox.ini file containing configuration for:
    • coverage-clean
    • lint
    • flake8
    • mypy
    • docstr-coverage
    • pytest
  • LICENSE file based on the choice made during setup.
  • README.md file containing project_description value entered during setup.

Further setup

Install poetry

Install poetry if you haven't already.

pip install poetry

Install dependencies

poetry install

Add poetry-dynamic-versioning as a plugin

poetry self add "poetry-dynamic-versioning[plugin]"

Note: If you are using a Linux system and the above doesn't work giving you the following error Invalid PEP 440 version: ..., you could alternatively run:

poetry add poetry-dynamic-versioning

Run tox to see if the setup works

poetry run tox

This should run all the bullets mentioned above under the tox configuration and ideally you should see the following at the end of the run:

  coverage-clean: commands succeeded
  lint: commands succeeded
  flake8: commands succeeded
  mypy: commands succeeded
  docstr-coverage: commands succeeded
  py: commands succeeded
  congratulations :)

And as the last line says: congratulations :)!! Your project is ready to evolve!

Final test to see everything is wired properly

On the command line, type the project_name. In this example, ABCD:

ABCD run

Should return Hello, **greeting_recipient value chosen during setup**

Future updates to the project's boilerplate code

In order to be up-to-date with the template, first check if there is a mismatch between the project's boilerplate code and the template by running:

cruft check

This indicates if there is a difference between the current project's boilerplate code and the latest version of the project template. If the project is up-to-date with the template:

SUCCESS: Good work! Project's cruft is up to date and as clean as possible :).

Otherwise, it will indicate that the project's boilerplate code is not up-to-date by the following:

FAILURE: Project's cruft is out of date! Run `cruft update` to clean this mess up.

For viewing the difference, run cruft diff. This shows the difference between the project's boilerplate code and the template's latest version.

After running cruft update, the project's boilerplate code will be updated to the latest version of the template.

Setting up PyPI release

For the first time, you'll need to just run the following commands:

poetry build
poetry publish -u YOUR_PYPI_USERNAME -p YOUR_PYPI_PASSWORD

This will release a 0.0.0 version of your project on PyPI.

Automating this via Github Release

Go to the PyPI account settings and select "Add API token". Create an API token and choose its scope: this token could either upload all the projects maintained or owned, its scope can be limited to just one project (preferred).

Copy this token to your project's 'secrets' in the 'Settings' section of your github project.

Settings -> Secrets -> Actions -> New Repository Secret

Paste the copied token from PyPI into the new secret and call it PYPI_TOKEN.

Now on releasing via Github, the project will automatically be released to PyPI as well.

About

A Cookiecutter template for BBOP work

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published