DEV Community

Karthi Mahadevan
Karthi Mahadevan

Posted on

1

What I use daily - python development

Best Practices I follow during python development in current project.

  • Use Virtual Environments to keep dependencies isolated.
  • vscode to develop
  • Pytest, mockito for tests
  • Document Code using MkDocs and publish it as site in gitlab pages. ( Sooner we are moving to Backstage)
  • Taskfile , designed to streamline development processes related to testing package building, and publishing for a Python project. task is responsible for creating the source distribution (sdist) and wheel packages of the application using poetry. task also publishes the built package to a specified repository (GitLab in our case).
  • Entire org using Renovate to automate the management of software dependencies, ensuring projects remain up-to-date with the latest versions and security patches.
  • We use pre-commit on every commit to enforce our linting and style, use pre-commit install --install-hooks to enable it.
  • Mypy a static type checker that helps ensure type correctness in Python code. so we can catch type-related errors before runtime.
  • Ruff , a linter and formatter that can check for style issues, potential bugs across Python code.
  • some 10+ Pre-commit hooks.
  • Strict Commitlint format
    • Gitleaks for detecting sensitive information (like API keys and passwords)
  • few more for Python project focusing on linting, testing, mutation testing, type checking, and ensuring code quality.

a sample function formatted according to Ruff's style conventions in our project would look like

def calculate_area(radius: float, pi: float = 3.14159) -> float:
    """Calculate the area of a circle.

    Args:
        radius (float): The radius of the circle.
        pi (float, optional): The value of pi. Defaults to 3.14159.

    Returns:
        float: The area of the circle.

    Raises:
        ValueError: If the radius is negative.
    """
    if radius < 0:
        raise ValueError("Radius must be non-negative.")

    return pi * (radius ** 2)

Enter fullscreen mode Exit fullscreen mode

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay