Skip to content

US model import fails offline due to import-time PyPI lookup #269

@MaxGhenis

Description

@MaxGhenis

Summary

The US model performs a live PyPI metadata lookup at import time (src/policyengine/tax_benefit_models/us/model.py:52), which breaks offline, firewalled, and sandboxed environments. The UK model handles this gracefully with a try/except fallback (src/policyengine/tax_benefit_models/uk/model.py:45).

Impact

  • import policyengine.tax_benefit_models.us fails without network access
  • This cascades to test collection (tests/conftest.py imports US fixtures globally), so even unit tests that don't need US model data can't run offline
  • The paper's inline code example and the README smoke test both fail in no-network environments
  • A JOSS reviewer flagged this as a major issue when reviewing in a sandboxed environment

Suggested fix

  1. Make the US metadata lookup fault-tolerant, mirroring the UK implementation pattern
  2. Consider lazy-loading the US model metadata (fetch on first use, not at import time)
  3. Move heavyweight US imports in tests/conftest.py and tests/fixtures/filtering_fixtures.py inside test functions or fixtures so offline unit tests can still collect

References

  • UK graceful handling: src/policyengine/tax_benefit_models/uk/model.py:45
  • US import-time lookup: src/policyengine/tax_benefit_models/us/model.py:52
  • Test collection dependency: tests/conftest.py:4, tests/fixtures/filtering_fixtures.py:11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions