https://github.com/brianpugh/python-template

Python project and library template for clean, reliable, open-source projects.

https://github.com/brianpugh/python-template

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.1%) to scientific vocabulary

Keywords

actions cookiecutter docker github library package pre-commit project pypi python template

Keywords from Contributors

serializer interactive projection generic archival sequences ecosystem-modeling genomics observability autograding
Last synced: 5 months ago · JSON representation

Repository

Python project and library template for clean, reliable, open-source projects.

Basic Info
  • Host: GitHub
  • Owner: BrianPugh
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 850 KB
Statistics
  • Stars: 297
  • Watchers: 4
  • Forks: 17
  • Open Issues: 0
  • Releases: 0
Topics
actions cookiecutter docker github library package pre-commit project pypi python template
Created almost 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Contributing License

README.rst

|Python compat| |GHA tests|

A template to quickly get you creating an open-source python library
or project with linting, static analysis, CI, and CD to PyPI.

Usage
=====

To use this template, click the green "Use this template" button in the github web interface.
Then run:

.. code-block:: bash

   git clone YOUR_REPO
   # then cd into your local repo, and run:
   ./bootstrap

And follow the on-screen prompts. ``bootstrap`` uses some git data (like detecting your username and repository name), so cloning the repo generated from the template is necessary.

General sanity checks and best practices are performed on provided responses. To disable these, run with the ``--no-verify`` flag:

.. code-block:: bash

   ./bootstrap --no-verify

Compatibility
=============

This template's ``bootstrap`` functionality only works on MacOS/Linux/WSL, it *will not work natively on windows*.
The resulting project, however, may be windows-compatible.

Features
========

* Features dependent if project is a library or a standalone project.

* `Poetry`_ support.

  * If not installed, Poetry will automatically be installed when running ``bootstrap``.

  * `Poetry Dynamic Versioning`_ - Dynamically handles your project version based on git tags.

* Optional command line interface boilerplate using Cyclopts_.

* Optional C binding support via Cython.

* `Sphinx`_ + `ReadTheDocs`_.

  * To setup, goto `ReadTheDocs Dashboard`_ and click on "Import a Project".

  * To locally build the docs:

    .. code-block:: console

       cd docs/
       make html

    This results in html files in ``docs/build/html/``.
    Double click ``docs/build/html/index.html`` to view the docs in your web browser.

* `Pre-commit`_ linting and static analysis. The following hooks are pre-configured and will automatically run on ``git commit``:

  * `Ruff `_ - An extremely fast Python linter and formatter.

  * `Creosote `_ - Identifies unused dependencies.

  * `Codespell `_ - Checks code and documentation for common misspellings.

  * `Pyright `_ - Static type checker.

* `Docker`_ support for standalone projects.

* GitHub Actions for:

  * Running ``pre-commit`` on pull requests and commits to ``main``.

  * Running unit tests, coverage, and verify docs build on pull requests and commits to ``main``.

    * Goto your `Codecov Dashboard`_ and add your repo.

  * Build and upload wheels to PyPI on semver tags ``vX.Y.Z``.

    * Add your `PyPI API token`_ to your `GitHub secrets`_ for key ``PYPI_TOKEN``.

    * If using Cython, pre-built binary packages will be created for all major operating systems, python versions, and computer architectures.

  * Build and upload docker images to Dockerhub.

    * Add your Dockerhub username and `token`_ to your `GitHub secrets`_
      ``DOCKERHUB_USERNAME`` and ``DOCKERHUB_TOKEN``.

    * Optionally, modify the ``tags`` field in ``.github/workflows/docker.yaml``.
      By default, it assumes your docker username is the same as your github username.


Cython
======
This template has an option to add boilerplate for Cython_.
Cython is a programming language that simplifies the creation of C extensions for Python.
The `Cython documentation is quite good `_; the aim of this section is to explain what this
template sets up, and what actions will still need to be performed by you.
This explanation assumes you are familiar with C.
Replace any reference here to ``pythontemplate`` with your project name.

1. Place all C and header files in the ``pythontemplate/_c_src`` directory.
   If you don't plan on using any explicit C files, you may delete this directory.

2. Update ``pythontemplate/cpythontemplate.pxd`` with header information from the files in (1).
   Example of common definitions (functions, structs, and enums) are provided.
   Think of ``*.pxd`` as a header file that allows Cython ``.pyx`` code to access pure C ``.c`` files.
   This file will be compiled into a package of the same name that can be imported in a ``.pyx`` file via ``cimport``.
   If you don't plan on using any explicit C files, you may delete this file and the ``_c_src`` directory.

3. Add Cython code to ``pythontemplate/_c_extension.pyx``. Some class starter code is provided.
   This is where a good pythonic interface (functions and classes) should be written.

4. If adding type hints, update ``pythontemplate/_c_extension.pyi`` to reflect your ``.pyx`` implementation.

5. Optionally tweak ``build.py`` (runs at setup/installation) with compiler options.
   The default ``build.py`` offers a good, working starting point for most projects and performs the following:

   a. Recursively searches for all C files in ``pythontemplate/_c_src/``.
      To change this action, modify the variable ``c_files``.

   b. Compiles the code defined in ``_c_extension.pyx`` into a shared object file.

   c. Adds ``pythontemplate`` and ``pythontemplate/_c_src`` to the Include Path (python variable ``include_dirs``).

   d. If your codebase contains a slower, python implementation of your Cython code,
      we can allow building to fail by uncommenting the ``allowed_to_fail`` logic at the top.
      The logic checks for the environment variable ``CIBUILDWHEEL`` because we don't want to allow
      build failures in our CI when creating pre-built wheels that we upload to PyPI.

6. The Github Action workflow defined in ``.github/workflows/build_wheels.yaml`` will create pre-built
   binaries for all major Python versions, operating systems, and computer architectures.
   It will also create a Source Distribution (sdist).
   All of these distributions will be uploaded to the github action job page.
   On git semver tags (``vX.X.X``), they will be uploaded to PyPI.

When developing, you must re-run ``poetry-install`` to re-compile changes made in C/Cython code.
The resulting, built Cython code will be importable from ``pythontemplate._c_extension``, so it may be
good to add something like the following to your ``pythontemplate/__init__.py``:

.. code-block:: python

   __all__ = [
      "Foo",
   ]
   from pythontemplate._c_extension import Foo

Reference
=========
If you find this in the git history of a project and you like the structure, visit
this template at https://github.com/BrianPugh/python-template .


.. |GHA tests| image:: https://github.com/BrianPugh/python-template/workflows/tests/badge.svg
   :target: https://github.com/BrianPugh/python-template/actions?query=workflow%3Atests
   :alt: GHA Status
.. |Python compat| image:: https://img.shields.io/badge/>=python-3.9-blue.svg

.. _Codecov Dashboard: https://app.codecov.io/gh
.. _Docker: https://www.docker.com
.. _GitHub secrets: https://docs.github.com/en/actions/security-guides/encrypted-secrets
.. _Poetry: https://python-poetry.org
.. _Pre-commit: https://pre-commit.com
.. _PyPI API token: https://pypi.org/help/#apitoken
.. _ReadTheDocs Dashboard: https://readthedocs.org/dashboard/
.. _ReadTheDocs: https://readthedocs.org
.. _Sphinx: https://www.sphinx-doc.org/en/master/
.. _token: https://docs.docker.com/docker-hub/access-tokens/
.. _Cython: https://cython.readthedocs.io/en/latest/
.. _Poetry Dynamic Versioning: https://github.com/mtkennerly/poetry-dynamic-versioning
.. _Cyclopts: https://github.com/BrianPugh/cyclopts

Owner

  • Name: Brian Pugh
  • Login: BrianPugh
  • Kind: user
  • Location: Washington D.C.

Deep Learning Scientist and blockchain enthusiast

GitHub Events

Total
  • Watch event: 33
  • Delete event: 57
  • Issue comment event: 3
  • Push event: 70
  • Pull request event: 128
  • Fork event: 2
  • Create event: 60
Last Year
  • Watch event: 33
  • Delete event: 57
  • Issue comment event: 3
  • Push event: 70
  • Pull request event: 128
  • Fork event: 2
  • Create event: 60

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 297
  • Total Committers: 3
  • Avg Commits per committer: 99.0
  • Development Distribution Score (DDS): 0.495
Past Year
  • Commits: 98
  • Committers: 2
  • Avg Commits per committer: 49.0
  • Development Distribution Score (DDS): 0.235
Top Committers
Name Email Commits
Brian Pugh b****7@g****m 150
dependabot[bot] 4****] 146
Jack McIvor j****r@g****m 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 13
  • Total pull requests: 262
  • Average time to close issues: 1 day
  • Average time to close pull requests: about 13 hours
  • Total issue authors: 9
  • Total pull request authors: 4
  • Average comments per issue: 2.15
  • Average comments per pull request: 0.3
  • Merged pull requests: 232
  • Bot issues: 1
  • Bot pull requests: 205
Past Year
  • Issues: 0
  • Pull requests: 110
  • Average time to close issues: N/A
  • Average time to close pull requests: about 7 hours
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.01
  • Merged pull requests: 91
  • Bot issues: 0
  • Bot pull requests: 103
Top Authors
Issue Authors
  • jymchng (5)
  • dependabot[bot] (2)
  • ArianeDucellier (1)
  • BrianPugh (1)
  • jheintz (1)
  • YisusChrist (1)
  • mgorfer (1)
  • smy20011 (1)
  • pyup-bot (1)
  • tueboesen (1)
Pull Request Authors
  • dependabot[bot] (216)
  • BrianPugh (59)
  • jack-mcivor (1)
  • pyup-bot (1)
Top Labels
Issue Labels
dependencies (2)
Pull Request Labels
dependencies (216) python (55)

Dependencies

pyproject.toml pypi
  • python ^3.8
.github/workflows/deploy.yaml actions
  • JRubics/poetry-publish v1.13 composite
  • actions/checkout v2 composite
.github/workflows/docker.yaml actions
  • docker/build-push-action v3 composite
  • docker/login-action v2 composite
  • docker/setup-buildx-action v2 composite
  • docker/setup-qemu-action v2 composite
.github/workflows/tests.yaml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • andstor/file-existence-action v2 composite
  • codecov/codecov-action v3 composite
  • snok/install-poetry v1 composite
Dockerfile docker
  • ubuntu 20.04 build
poetry.lock pypi
  • Babel 2.11.0 develop
  • Jinja2 3.1.2 develop
  • MarkupSafe 2.1.1 develop
  • PyYAML 6.0 develop
  • Pygments 2.13.0 develop
  • Sphinx 4.5.0 develop
  • alabaster 0.7.12 develop
  • appnope 0.1.3 develop
  • asttokens 2.2.1 develop
  • attrs 22.1.0 develop
  • backcall 0.2.0 develop
  • certifi 2022.12.7 develop
  • cfgv 3.3.1 develop
  • charset-normalizer 2.1.1 develop
  • colorama 0.4.6 develop
  • coverage 5.5 develop
  • decorator 5.1.1 develop
  • distlib 0.3.6 develop
  • docutils 0.17.1 develop
  • dunamai 1.15.0 develop
  • exceptiongroup 1.0.4 develop
  • executing 1.2.0 develop
  • filelock 3.8.2 develop
  • flake8 4.0.1 develop
  • identify 2.5.9 develop
  • idna 3.4 develop
  • imagesize 1.4.1 develop
  • importlib-metadata 5.1.0 develop
  • iniconfig 1.1.1 develop
  • ipdb 0.13.9 develop
  • ipython 8.7.0 develop
  • jedi 0.18.2 develop
  • line-profiler 3.5.1 develop
  • matplotlib-inline 0.1.6 develop
  • mccabe 0.6.1 develop
  • nodeenv 1.7.0 develop
  • packaging 21.3 develop
  • parso 0.8.3 develop
  • pexpect 4.8.0 develop
  • pickleshare 0.7.5 develop
  • platformdirs 2.6.0 develop
  • pluggy 1.0.0 develop
  • poetry-dynamic-versioning 0.16.0 develop
  • pre-commit 2.20.0 develop
  • prompt-toolkit 3.0.36 develop
  • ptyprocess 0.7.0 develop
  • pure-eval 0.2.2 develop
  • pycodestyle 2.8.0 develop
  • pyflakes 2.4.0 develop
  • pyparsing 3.0.9 develop
  • pytest 7.2.0 develop
  • pytest-cov 3.0.0 develop
  • pytest-mock 3.10.0 develop
  • pytz 2022.6 develop
  • requests 2.28.1 develop
  • setuptools 65.6.3 develop
  • six 1.16.0 develop
  • snowballstemmer 2.2.0 develop
  • sphinx-rtd-theme 1.0.0 develop
  • sphinxcontrib-applehelp 1.0.2 develop
  • sphinxcontrib-devhelp 1.0.2 develop
  • sphinxcontrib-htmlhelp 2.0.0 develop
  • sphinxcontrib-jsmath 1.0.1 develop
  • sphinxcontrib-qthelp 1.0.3 develop
  • sphinxcontrib-serializinghtml 1.1.5 develop
  • stack-data 0.6.2 develop
  • toml 0.10.2 develop
  • tomli 2.0.1 develop
  • tomlkit 0.11.6 develop
  • traitlets 5.6.0 develop
  • urllib3 1.26.13 develop
  • virtualenv 20.17.1 develop
  • wcwidth 0.2.5 develop
  • zipp 3.11.0 develop