Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Karthi Mahadevan
Karthi Mahadevan

Posted on

     

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, usepre-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 modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Engineering Lead
  • Education
    Maters - Computer Science
  • Joined

More fromKarthi Mahadevan

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp