Create a new python projects contribute

When creating a new Python repository, some guidelines help keep our code standardized.

Development & testing

  • pytest: Primary testing framework for writing and running tests.
  • pytest-cov: Test coverage reporting plugin for pytest.
  • black: Opinionated code formatter that ensures consistent code style.
  • flake8: Linter for style enforcement.
  • pylint: Comprehensive linter for error detection and quality enforcement.
  • mypy: Static type checker.
  • isort: Utility to sort imports.

Package manager & build system

  • poetry: Modern packaging and dependency management.

Common utilities

  • typer: Library for building CLI applications.
  • python-dotenv: Environment variable management.
  • pydantic: Data validation and settings management using Python type annotations.
  • fastapi: Modern, high-performance web framework for building APIs.
  • structlog: Structured logging library.
  • httpx: Asynchronous and performant HTTP client.
  • rich: Terminal formatting library for rich text.
  • sqlmodel: Intuitive and robust ORM.
  • tqdm: Fast, extensible progress bar for CLI.

Depending on the type of project, for example, API service, CLI application or library, the folder structure can be varied. The following structure is for a standard CLI application.

Copy to clipboard
project_name/
├── .gitlab/                     # GitLab-specific configuration
│   ├── issue_templates/         # Issue templates
│   └── merge_request_templates/ # MR templates
├── .gitlab-ci.yml               # CI/CD configuration
├── project_name/                # Main package directory
│   ├── __init__.py              # Package initialization
│   ├── cli.py                   # Command-line interface entry points
│   ├── config.py                # Configuration handling
│   └── core/                    # Core functionality
│       └── __init__.py
├── tests/                       # Test directory
│   ├── __init__.py
│   ├── conftest.py              # pytest fixtures and configuration
│   └── test_*.py                # Test modules
├── docs/                        # Documentation
├── scripts/                     # Utility scripts
├── README.md                    # Project overview
├── CONTRIBUTING.md              # Contribution guidelines
├── LICENSE                      # License information
├── pyproject.toml               # Project metadata and dependencies (Poetry)

Linter configuration

We should consolidate configurations into pyproject.toml as much as possible.

pyproject.toml

TOML Copy to clipboard
[tool.black]
line-length = 120

[tool.isort]
profile = "black"

[tool.mypy]
python_version = 3.12
ignore_missing_imports = true

[tool.pylint.main]
jobs = 0
load-plugins = [
  # custom plugins
]

[tool.pylint.messages_control]
enable = [
  # custom plugins
]

[tool.pylint.reports]
score = "no"

setup.cfg

INI Copy to clipboard
[flake8]
extend-ignore = E203,E501
extend-exclude = **/__init__.py,.venv,tests
indent-size = 4
max-line-length = 120

Adding reviewer roulette

We recommend reviewer roulette to distribute review workload across reviewers and maintainers.

  1. Follow the GitLab Dangerfiles instructions to add the configuration to your project.

  2. Implement the Danger Reviewer component in your GitLab CI pipeline to automatically trigger the roulette.