Skip to content

Update python environment and dependencies - #1065

Open
natbutter wants to merge 1 commit into
jaakkopasanen:masterfrom
natbutter:python-update
Open

Update python environment and dependencies#1065
natbutter wants to merge 1 commit into
jaakkopasanen:masterfrom
natbutter:python-update

Conversation

@natbutter

Copy link
Copy Markdown

Pull Request: Update Python Environment, Dependencies, and Migrate to Pydantic v2

Description

This pull request modernizes the codebase by upgrading the minimum Python version requirement, bumping major library dependencies, upgrading FastAPI and Uvicorn, and migrating the web app validation layer from Pydantic v1 to Pydantic v2. It also fixes a minor filename casing mismatch in the test assertions to ensure the test suite runs and passes successfully.

Motivation & Context

  • Python Modernization: The previous configuration supported Python >=3.8,<3.12. By bumping the minimum requirement to >=3.10, we can take advantage of modern Python features (e.g., union type hints | instead of Union, improved performance, and cleaner syntax) and support newer versions of key scientific libraries.
  • Dependency Upgrades: Upgraded core scientific libraries (numpy, scipy, matplotlib, Pillow, etc.) to their latest compatible versions to address potential security vulnerabilities, gain performance improvements, and ensure compatibility with newer Python runtimes.
  • FastAPI & Pydantic v2 Migration: FastAPI was upgraded from ~=0.88.0 to ~=0.138.1 and Uvicorn from ~=0.20.0 to ~=0.49.0. This necessitated a migration of webapp/main.py validation models from Pydantic v1 to Pydantic v2. Pydantic v2 offers massive speedups in validation serialization and cleaner APIs, but comes with breaking changes in validator decorators and field configuration.
  • Test Fixes: Fixed a mismatch where test assertions looked for FixedBandEq.txt and ParametricEq.txt while the batch processing code actually generates FixedBandEQ.txt and ParametricEQ.txt.

Detailed Changes

1. Python Environment & Library Upgrades

In pyproject.toml:

  • Updated Python version requirement from Requires-Python = ">=3.8,<3.12" to Requires-Python = ">=3.10".
  • Bumped dependencies:
    • Pillow: ~=10.0.1~=12.2.0
    • matplotlib: ~=3.7.3~=3.11.0
    • scipy: ~=1.10.1~=1.18.0
    • numpy: ~=1.24.4~=2.5.0
    • tabulate: ~=0.9.0~=0.10.0
    • soundfile: ~=0.12.1~=0.14.0
    • pyyaml: ~=6.0~=6.0.3
    • tqdm: ~=4.66.1~=4.68.3

In webapp/requirements.txt:

  • Bumped fastapi to ~=0.138.1 and uvicorn[standard] to ~=0.49.0.

2. Pydantic v2 Migration in Web App

In webapp/main.py:

  • Replaced Pydantic v1 validator imports (validator, root_validator, confloat, conlist) with Pydantic v2 equivalents (Field, field_validator, model_validator).
  • Migrated field constraints from v1 wrappers (e.g. confloat(ge=0.0, le=0.5)) to v2 Field limits (e.g. float = Field(default=None, ge=0.0, le=0.5)).
  • Replaced @root_validator with @model_validator(mode='before') and @validator(...) with @field_validator(...).
  • Added explicit type annotations and defaults (e.g., Optional[type] = None) to satisfy Pydantic v2 strictness.

3. Test Suite Alignment

In tests/test_autoeq.py:

  • Updated test assertions to check for FixedBandEQ.txt and ParametricEQ.txt (capitalized EQ), aligning the test suite with the actual file naming convention implemented in autoeq/batch_processing.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant