Skip to content

Review Python codebase for usefulness and best practices #309

Description

@turbomam

Overview

The Python codebase has accumulated many scripts with varying quality and unclear production status. A comprehensive review is needed to ensure all code meets best practices and provides clear value.

Issues Identified

1. Hardcoded Temporary Paths

  • docs/metpo/scripts/definition_work/fetch_source_metadata.py has hardcoded /tmp/ paths
  • docs/metpo/scripts/definition_work/merge_sparql_with_metadata.py has hardcoded /tmp/ paths
  • These suggest exploratory/analysis scripts rather than production tools

2. Code Quality Issues

  • 616 remaining linting errors after automated fixes
  • Complexity warnings (functions with too many branches/statements)
  • Inconsistent use of modern Python patterns (e.g., Path vs open())

3. Unclear Script Organization

  • Scripts in docs/metpo/scripts/ - should documentation contain executable code?
  • Unclear which scripts are production tools vs. one-off analysis scripts
  • Missing Click CLI interfaces for some scripts (per CLAUDE.md requirements)
  • Missing pyproject.toml entries for scripts

4. Best Practices Compliance

According to CLAUDE.md, all production scripts MUST:

  • ✅ Use uv or poetry for environment management
  • ❌ Have Click CLI interfaces (many scripts missing this)
  • ❌ Live in metpo/scripts/ directories (some in docs/)
  • ❌ Have CLI aliases in pyproject.toml (many missing)
  • ❌ Be illustrated in Makefile (many not integrated)
  • ❌ Meet production standards (some are one-off analysis notebooks)

Proposed Review Process

Phase 1: Inventory

  • List all Python files in the repository
  • Categorize as: production tool, analysis script, test, or legacy
  • Identify scripts with hardcoded paths or other anti-patterns

Phase 2: Evaluation

For each script, determine:

  • Is it still useful?
  • Is it a production tool or analysis artifact?
  • Does it meet CLAUDE.md requirements?
  • Does it have tests?
  • Is it documented?

Phase 3: Action

  • Delete: Remove obsolete/superseded scripts
  • Upgrade: Add Click CLI, pyproject.toml entries, Makefile integration
  • Move: Relocate to appropriate directories (production → metpo/scripts/, analysis → archive)
  • Fix: Remove hardcoded paths, add proper argument parsing
  • Document: Add docstrings and usage examples

Phase 4: Standardization

  • Apply consistent linting rules across all Python code
  • Refactor complex functions to reduce branches/statements
  • Ensure all production scripts use modern Python patterns
  • Add pre-commit hooks to maintain standards

Files Needing Immediate Attention

Scripts with hardcoded /tmp/ paths:

  • docs/metpo/scripts/definition_work/fetch_source_metadata.py
  • docs/metpo/scripts/definition_work/merge_sparql_with_metadata.py

Recent additions needing review:

  • metpo/scripts/definition_work/regenerate_curator_attributions.py
  • metpo/scripts/visualize_distances.py

Success Criteria

  • All production scripts meet CLAUDE.md requirements
  • No hardcoded file paths in production code
  • All scripts have clear purpose and documentation
  • Linting errors reduced to acceptable levels
  • Clear separation between production tools and analysis artifacts
  • All scripts integrated into workflow (Makefile/pyproject.toml)

Related Context

  • Fixed 6854 quote style errors and 1224 other auto-fixable linting issues
  • 616 linting errors remain (mostly complexity and style warnings)
  • Repository cleanup identified many files needing organization

Priority: Medium
Estimated Effort: 2-3 days for comprehensive review
Assignee: TBD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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