Skip to content

Create a python (package) variant #1

@thekaveman

Description

@thekaveman

Create another template repository, based on this one, with a basic setup for creating a new Python package.

Features

Running list of features to build into this template

Linting

Use flake8 for python code linting:

  • configuration in .flake8
  • add to .devcontainer/requirements.txt
  • devcontainer plugin, add to devcontainer.json
  • pre-commit hook, add to .pre-commit-config.yaml

Formatting

Use black for python code formatting:

  • configuration in pyproject.toml
  • add to .devcontainer/requirements.txt
  • devcontainer plugin, add to devcontainer.json
  • pre-commit hook, add to .pre-commit-config.yaml

Testing

Use pytest for python testing

  • tests/ dir: __init__.py, conftest.py (empty)
  • tests/requirements.txt, install in devcontainer: pytest, pytest-cov, pytest-mock
  • tests/run.sh: runs tests with coverage, (re)generates coverage report
  • Serve coverage report from docs service
  • .github/workflows/pytest.yml calls tests/run.sh on every commit

Python package setup

  • package_name/ dir: __init__.py (empty)
  • .devcontainer/postAttach.sh, install the local package into the devcontainer
  • setup.py in the root, just import and call setuptools.setup() (with no args)
  • setup.cfg in the root, most configuration info about package
  • [build-system] entry in pyproject.toml

Repository setup

  • .gitignore with at least:
__pycache__/
.pytest_cache/
.coverage
.DS_Store
.egg-info/
build/

Editor settings

  • Add the following to .vscode/settings.json
"[python]": {
  "editor.defaultFormatter": "ms-python.python"
},
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false

Docs

  • Add mkdocstrings for automatic code documentation generation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions