Skip to content

v0.3.0

@blarghmatey blarghmatey tagged this 29 May 13:18
Adds PackageAttributor — a five-strategy engine that attributes each
settings field to the Python package that owns it:

1. Django core: django.conf.global_settings is imported directly;
   every UPPERCASE name it defines is attributed to 'django'.

2. Callable inspection: for function/method-valued settings,
   inspect.getmodule() correctly returns the actual defining module
   (unlike the 'inspect.getmodule(lambda: value)' pattern suggested
   by AI, which always returns the calling module). The module is
   mapped to its PyPI distribution name via importlib.metadata.

3. Known package APIs:
   - Celery: celery.app.defaults._OLD_SETTING_KEYS is the authoritative
     list of all 194 Django-style (CELERY_*/BROKER_*) setting names.
   - DRF: rest_framework.settings is imported to confirm availability;
     REST_FRAMEWORK itself is the only top-level setting.

4. AST scan: each installed package's source files are scanned for
   getattr(settings, 'SETTING_NAME') and settings.SETTING_NAME
   patterns. Priority files (settings.py, conf.py, apps.py, etc.)
   are scanned first. Test/migration directories are excluded.

5. Static prefix/name table: CELERY_, CORS_, OAUTH2_, SOCIAL_AUTH_,
   JWT_, AWS_, PUSH_NOTIFICATIONS_, etc. as a final fallback.

With --attribute-packages on the LMS settings (892 fields), 32
distinct package groups are produced: 'django' first, 'project'
last (692 fields), with all installed packages in between.

## Changes

- discovery/package_attributor.py: new module with PackageAttributor
- discovery/base.py: add owning_package: str = '' to DiscoveredField
- codegen/generator.py: group by owning_package when set; order is
  django first, third-party alphabetically, project last
- codegen/schema_generator.py: emit x-aqueduct-package extension
- management/commands/generate_aqueduct_settings.py: --attribute-packages
- tests/test_package_attributor.py: 40 new tests (210 total, 1 skipped)

## Version: 0.2.0 -> 0.3.0
Assets 2
Loading