Poetry Workflow Framework

Professional Python Development & CI/CD Best Practices

Framework Overview

This demonstrates a professional Poetry workflow framework I follow for Python package management and CI/CD practices. This approach has proven effective for integrating complex software systems and maintaining high code quality standards in professional development environments.

Project Structure Framework:
project-name/
├── pyproject.toml
├── src/
│ ├── __init__.py
│ └── calculator.py
├── tests/
│ └── test_calculator.py
├── scripts/
│ └── demo.py
└── poetry.lock (created after first install)

1Phase 1: Initial Setup & Basic Implementation

pyproject.toml Configuration

[tool.poetry]
name = "simple-project"
version = "0.1.0"
description = "Simple calculator project"
authors = ["Developer <dev@example.com>"]
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"

[tool.poetry.scripts]
demo = "scripts.demo:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

src/calculator.py

"""Simple calculator module."""

def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

def subtract(a: float, b: float) -> float:
    """Subtract two numbers."""
    return a - b

tests/test_calculator.py

"""Tests for calculator module."""
import pytest
from src.calculator import add, subtract

def test_add():
    """Test addition function."""
    assert add(2, 3) == 5
    assert add(-1, 1) == 0
    assert add(0, 0) == 0

def test_subtract():
    """Test subtraction function."""
    assert subtract(5, 3) == 2
    assert subtract(1, 1) == 0
    assert subtract(0, 5) == -5

Initial Setup Workflow

# Clone or initialize project
git clone <repo-url> # or poetry new project-name
cd project-name
# Install dependencies (creates poetry.lock)
poetry install
# Run tests to ensure baseline functionality
poetry run pytest
# Execute demo to verify integration
poetry run demo
Output after `poetry run pytest`:
===== 4 passed in 0.12s =====
Output after `poetry run demo`:
=== Calculator Demo ===
2 + 3 = 5
5 - 2 = 3
Demo complete!

2Phase 2: Feature Enhancement & Dependency Management

Expanding functionality with scientific operations and external dependencies - demonstrating scalable development practices.

INITIAL - Basic Calculator

  • Core add/subtract functions
  • No external dependencies
  • Simple demo output
  • 4 baseline tests

ENHANCED - Scientific Calculator

  • Full mathematical operations suite
  • NumPy integration
  • Comprehensive demo showcase
  • 8 tests covering all functionality

Updated pyproject.toml (Dependency Evolution)

[tool.poetry]
name = "simple-project"
version = "0.2.0"  # Version increment
description = "Simple calculator with scientific functions"
authors = ["Developer <dev@example.com>"]
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.9"
numpy = "^1.24.0"  # NEW: Scientific computing capability

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"

[tool.poetry.scripts]
demo = "scripts.demo:main"

src/scientific.py (New Module)

"""Scientific calculator functions."""
import numpy as np

def multiply(a: float, b: float) -> float:
    """Multiply two numbers."""
    return a * b

def divide(a: float, b: float) -> float:
    """Divide two numbers."""
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

def power(base: float, exponent: float) -> float:
    """Calculate base raised to exponent."""
    return np.power(base, exponent)

def sqrt(x: float) -> float:
    """Calculate square root."""
    if x < 0:
        raise ValueError("Cannot take square root of negative number")
    return np.sqrt(x)

Enhancement Development Workflow

# 1. Install new dependencies (updates poetry.lock)
poetry install
# 2. Run comprehensive test suite
poetry run pytest
# 3. Execute enhanced demo
poetry run demo
# 4. Build distributable package
poetry build
# 5. Publish for team distribution
poetry publish
Output after `poetry install`:
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing numpy (1.24.3)
Output after `poetry run pytest`:
===== 8 passed in 0.24s =====
Output after `poetry run demo`:
=== Enhanced Calculator Demo ===
Basic Operations:
2 + 3 = 5
5 - 2 = 3

Scientific Operations:
4 * 5 = 20
10 / 2 = 5.0
2^3 = 8.0
√16 = 4.0

Demo complete!

Framework Benefits & Best Practices

  • Dependency Lock Management: poetry.lock ensures reproducible builds across environments
  • Regression Prevention: Existing tests continue to pass while new functionality is validated
  • Incremental Enhancement: Features grow organically with proper version management
  • Team Collaboration: Build/publish workflow enables seamless distribution and integration
  • CI/CD Ready: Structure supports automated testing, building, and deployment pipelines

Professional Development Impact

This workflow framework demonstrates modern Python packaging and CI/CD practices that enable rapid, reliable software development and integration. The systematic approach to dependency management, testing, and deployment has proven effective in complex, mission-critical development environments.