Package: project-structure
This repository provides a minimal, yet opinionated baseline forPython[1]software
projects. It includes:BasicPython “distribution”/project[2]metadataCommand-line console script with subcommand boilerplateADocker[3]container image for end usersA Docker image for development, which runs testsAMakefile[4]for local development, build, test, and maintenanceA target that formats all source, includingBlack[5]for Python code styleAkitchen sink linter configuration[6]forProspector[7]that runs all available
Python code checksAtox.ini[8]configuration forTox[9]to run all tests and linters across supported
Python versions, including some checks not provided by Prospector.Version Control System (VCS) hooks[10]to enforceconventional commits[11], successful
build and test on commit and push, andTowncrier[12]end-user oriented release notes on
pushTargets that automate releasesTargets that automate dependency upgradesTargets used for both local development and on CI/CD platformsAGitLab CI/CD[13]pipeline integrating those CI/CD recipes and targetsAGitHub Actions[14]workflow integrating those CI/CD recipes and targetsOrganize source by feature[15], for example\./src/foo/(template|view|model)\..*,
rather than by source type, for example\./src/(templates|views|models)/foo\..*.Add a VCS remote for this repository to a real project. When the template adds structure
specific to certain types of projects, for example command-line tools, web services, UI
apps, the it adds branches for each variant. When the template makes changes to
structure common to different variants it can merge those changes into those
variants. Real projects can also merge those changes.Table of ContentsTemplate usageInstallationLocal InstallationDocker Container ImageUsageContributingMotivationReferencesTemplate usageThis is a rough guide for how to use this template in your project. This isn’t widely
tested. Such tests are meta and wasteful to create and support. Report any issues you
have or better yet submit a PR with corrections.Pick the branch to use:Pick the branch for your project type:py:Basic Python distribution metadata and packaging.py-cli:The preceding plus boilerplate for a command-line console script with subcommand.docker:Docker images for development and end-users or deployments.py-docker:The preceding Docker images with the Python package installed.ci:The preceding plus GitLab CI/CD pipelines that run tests and linters as CI and
publish releases fromdevelopandmainas CD.py-ci:Thepy-dockerandcibranches merged together.py-ci-cli:All the preceding combined together.It’s important to use one of the preceding branches to merge into your project andnotthedevelopormainbranches from the template. Template developers use
those branches to test the release process. They contain bumped versions, release
notes, and other release artifacts that real projects shouldn’t merge into their code
or history.Merge into your project:If starting a fresh project:$ git clone --origin "template" --branch "${TEMPLATE_BRANCH:?}" \
"https://gitlab.com/rpatterson/project-structure.git" "./foo-project"
$ cd "./foo-project"
$ git config remote.template.tagOpt --no-tags
$ git remote add "origin" "git@gitlab.com:foo-username/foo-project.git"
$ git switch -C "main" --track "origin/main"If merging into an existing project:$ git remote add "template" \
"https://gitlab.com/rpatterson/project-structure.git"
$ git config remote.template.tagOpt --no-tags
$ git merge --allow-unrelated-histories "template/${TEMPLATE_BRANCH:?}"Rename files and directories derived from the project name:$ git ls-files | grep -iE 'project.?structure'Rename project name and template creator identity strings:$ git grep -iE 'project.?structure|ross|Patterson'Make changes described in# TEMPLATE:comments:These bits need the developer’s attention and reasoning. Read the comments and follow
them with care:$ git grep "TEMPLATE"Lastly, remove thisTemplate usagesection and update the rest of this./README.rstfor your project. When the template adds fixes and features, merge them
into your project and repeat steps 3–5.This template publishes pre-releases on push to thedevelopbranch and final
releases on push to themainbranch. Project owners can decide the types of changes
that require a pre-release before final release and the types of changes that go
straight to final release. For example they can decide that:Merge public contributions intodevelop. Seethe contributing documentation[16]for
an example public contributions policy and workflow.Optionally commit fixes for bugs in final releases to a branch offmain. After
passing all tests and checks, merge back intomainto publish final releases
directly.Optionally also merge version upgrades for security updates directly tomain.InstallationInstall locally or use the Docker container image:Local InstallationInstall by using any tool for installing standard Python 3 distributions such aspip[17]:$ pip3 install --user project-structureOptional shell prompt tab completion is available by usingargcomplete[18].Docker Container ImageThe recommended way to use the container image is by usingDocker Compose[19]. Seethe
example ./docker-compose.yml file[20]. Write your configuration and run the container:$ docker compose upYou can also use the image directly. Pullthe Docker image[21]. Use it to create and run
a container:$ docker pull "registry.gitlab.com/rpatterson/project-structure"
$ docker run --rm -it "registry.gitlab.com/rpatterson/project-structure" ...Use image variant tags to control when the image updates. Releases publish tags for the
branch and for major and minor versions. For example, to keep up to date with a specific
branch, use a tag such asregistry.gitlab.com/rpatterson/project-structure:main. Releases fromdeveloppublish pre-releases. Releases frommainpublish final releases. Releases frommainalso publish tags without a branch, for exampleregistry.gitlab.com/rpatterson/project-structure. Releases frommainalso
publish tags for the major and minor version, for exampleregistry.gitlab.com/rpatterson/project-structure:v0.8.Releases publish multi-platform images for the following platforms:linux/amd64linux/arm64linux/arm/v7UsageSee the command-line help for details on options and arguments:$ project-structure --help
usage: project-structure [-h]

project structure foundation or template, top-level package.

Pptional arguments:
  -h, --help  show this help message and exitThe Docker container image can run the command-line script as well:$ docker compose run "project-structure" project-structure --help
usage: project-structure [-h]

Project structure foundation or template, top-level package.

optional arguments:
  -h, --help  show this help message and exitContributingGitLab hosts this project[22]andmirrors it to GitHub[23]but use GitLab for reporting
issues, submitting pull or merge requests and any other development or maintenance
activity. Seethe contributing documentation[16]for more details on how to get started
with development.MotivationPlenty other project templates exists. Why make another? I’ve been a full-stack web
developer from 1998 on. I’ve had plenty of time to develop plenty of opinions of my
own. From a template I want a full tool set (for example test coverage, linting,
formatting, CI). Conversely, I want minimal dependencies, structure, and opinion beyond
a full tool set (for example some build or task system, structure for unused frameworks
or libraries). I couldn’t find a template that manages that balance and I created this
one.I also find it hard to discern from other templates why they made what choices the did.
As such, I also use this template to try out different options and learn for myself. You
can learn about my findings and the reasons the choices I’ve made in the commit history.Most importantly I’ve never found a satisfactory approach to keeping project structure
up to date over time. As such, the primary motivation is providing a template upstream
remote, merging structure updates into real projects over their lifetime.References[1]https://docs.python.org/3/library/logging.html[2]https://docs.python.org/3/distributing/index.html[3]https://docs.docker.com/[4]https://gitlab.com/rpatterson/project-structure/-/blob/main/Makefile[5]https://github.com/psf/black[6]https://gitlab.com/rpatterson/project-structure/-/blob/main/.prospector.yaml[7]https://prospector.landscape.io/en/master/[8]https://gitlab.com/rpatterson/project-structure/-/blob/main/tox.ini[9]https://tox.wiki/en/stable/[10]https://gitlab.com/rpatterson/project-structure/-/blob/main/.pre-commit-config.yaml[11]https://www.conventionalcommits.org[12]https://towncrier.readthedocs.io/en/stable/[13]https://docs.gitlab.com/ee/ci/[14]https://docs.github.com/en/actions[15]https://www.seancdavis.com/posts/organize-components-by-keeping-related-files-close/[16](1,2)https://gitlab.com/rpatterson/project-structure/-/blob/main/docs/contributing.rst[17]https://pip.pypa.io/en/stable/installation/[18]https://kislyuk.github.io/argcomplete/#installation[19]https://docs.docker.com/compose/[20]https://gitlab.com/rpatterson/project-structure/-/blob/main/docker-compose.yml[21]https://hub.docker.com/r/merpatterson/project-structure[22]https://gitlab.com/rpatterson/project-structure[23]https://github.com/rpatterson/project-structure