Skip to content

Support à la carte dependencies - #416

Open
pawank925 wants to merge 3 commits into
openzim:mainfrom
pawank925:issue-244-full
Open

pawank925 wants to merge 3 commits into
openzim:mainfrom
pawank925:issue-244-full

Conversation

@pawank925

@pawank925 pawank925 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #244, building on the import-boundary work in #403.

changes

  • Runtime dependencies are now optional extras: zim, image, video, download, filesystem, html, rewriting, i18n, plus all.
  • A bare pip install zimscraperlib now only requires beartype.
  • all covers every runtime extra; video has no Python dependencies (FFmpeg remains a system dependency).
  • tinycss2 is declared explicitly in rewriting because rewriting/css.py imports it directly.
  • Importing a module whose extra is missing now raises an actionable ImportError naming the extra and the exact install command.
  • Cross-feature imports (filesystem, download, i18n, image) are resolved where they are used, so each extra stands on its own. Public APIs are preserved, including DEFAULT_DEV_ZIM_METADATA.
  • README maps system dependencies to extras, and CHANGELOG records the change for the 6.0 line.

Tests and CI

  • Added deterministic tests for dependency metadata, friendly errors in child interpreters, and core/video imports with every optional root blocked.
  • Added a core-only test job and a per-extra import matrix; full test/QA jobs now install all.
  • Validated locally with ruff check, ruff format --check, strict pyright, pytest, package build, and fresh virtual environments for the core install and every extra.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0f8b295) to head (540c41f).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #416    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           42        44     +2     
  Lines         2990      3093   +103     
  Branches       457       459     +2     
==========================================
+ Hits          2990      3093   +103     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Move runtime dependencies into optional extras (zim, image, video, download, filesystem, html, rewriting, i18n, all), keep beartype as the only base dependency, and raise actionable ImportErrors when an extra is missing. Resolve cross-feature imports at call time so each extra stands alone. Add metadata/import tests, a CI matrix, docs, and changelog entries.

Fixes openzim#244
@pawank925

Copy link
Copy Markdown
Contributor Author

@benoit74

@benoit74 benoit74 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have experience with Python extras, but this looks good to me.

Merging this probably means we need to make a major release, but this is already in the pipe for Python 3.15 which in turns introduce breaking changes with libzim 4.

@rgaudin any feedback to share for something I might have missed?

@rgaudin rgaudin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you ; that's great. Few things to fix. My main concern is about late ImportError which I think outweighs the benefits of the split but I'm not a scraperlib user anymore so I'll leave that choice to @benoit74.

Comment thread .github/workflows/Tests.yaml Resolved
Comment thread src/zimscraperlib/image/conversion.py Resolved
Comment thread src/zimscraperlib/video/encoding.py Resolved
Comment thread README.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread tests/conftest.py Resolved
Comment thread .github/workflows/Tests.yaml Resolved
Comment thread src/zimscraperlib/zim/creator.py Resolved
- Move to ubuntu-26.04 and drop unnecessary explicit x64 architecture.
- Move the missing_extra import into image conversion's except block.
- Make path_from dependency-free so video can import it without filesystem.
- Restore conftest imports and install download in the focused extras job.
- Mark the extras change as breaking and clarify the README download row.
- Keep DEFAULT_DEV_ZIM_METADATA explicit and eager without requiring i18n or image.
FFmpeg on ubuntu-26.04 reports the MP3 fixture bitrate about 1.9% higher than the expected value. Widen the existing test tolerance from 1% to 5%.

This branch has not been deployed

No deployments
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.

Support à la carte dependencies

3 participants