Skip to content

Python library template for teams using GitHub, Jenkins and Artifactory

Notifications You must be signed in to change notification settings

manselmi/python-library-template

Repository files navigation

Note

This repo contains a Python library template I had developed at a previous data engineering org to promote

  • code reuse

  • consistent repository layout

  • version string management with setuptools-scm

  • code style enforecement with pre-commit

  • running tests with tox

  • avoiding distribution package (a.k.a. "artifact") name collisions with PyPI, the (public) Python Package Index

  • creating installable artifacts according to PEP 518 and PEP 517

  • automatically building, testing and deploying artifacts to a private Artifactory repo via GitHub webhooks and Jenkins

It is showcased here with permission, as-is, aside from me redacting org-specific information.

Python library template

This repo contains a Cookiecutter template to simplify and accelerate creating a new Python library repository.

First, ensure that the cookiecutter executable is available. For example, if Homebrew is installed:

brew install -- cookiecutter

Next, change to the directory where you keep Git repos. Run Cookiecutter via

cookiecutter -- ssh://git-ssh-alias/manselmi/python-library-template.git

to start creating a new Python library from this template, where git-ssh-alias is a SSH host alias in the file ~/.ssh/config.

While the command runs, you will be prompted for information required to finish creating the project. Here's what to expect:

  1. project_name: This name will be added to the README.

  2. project_short_description: Provide a short description of the project to be included in the library's package metadata.

  3. author: Provide the project author's name to be included in the library's package metadata.

  4. author_email: Provide the project author's email address to be included in the library's package metadata.

  5. github_username: This is the GitHub username that will host this project.

  6. github_code_owner: Designate a GitHub code owner. If multiple code owners are desired, they may be added to the .github/CODEOWNERS file after the project has been created.

  7. repo_name: This the name of the directory containing the project, which must match the pattern [0-9a-z]+(?:-[0-9a-z]+)*. The default values of the distribution package and import package names will be derived from this value.

  8. namespace: To avoid name collisions, the default values of the distribution package and import package names will be prefixed by this value (which must match the pattern manselmi(?:\.[a-z]+)*) followed by a dot (.).

  9. distribution_pkg_name: This is the distribution package name of the project, which must be prefixed as described previously.

  10. import_pkg_name: This is the import package name of the project, which must be prefixed as described previously.

For example:

Key Value
project_name Foo Bar
repo_name foo-bar
namespace manselmi
distribution_pkg_name manselmi.foo-bar
import_pkg_name manselmi.foo_bar

After working through all of the prompts, Cookiecutter will automatically finish creating the project.

Next, navigate to the project directory and run the following to initialize the Git repository as the code and documentation assumes that the default branch name is main:

git init --initial-branch main

Note that main is also GitHub's default branch name.

(Please see Highlights from Git 2.28 to learn how to configure Git ≥ 2.28 to make main the default name for the initial branch. Also, I recommend the article Inclusiveness in Language for Outsiders Looking In for more context.)

Add and commit the project.

Finally, create a new project on GitHub whose name matches repo_name and push the main branch to the remote repo.

About

Python library template for teams using GitHub, Jenkins and Artifactory

Resources

Stars

Watchers

Forks