from hat import rabbit: Hacking your way through Python's import machinery for fun and profit
summary
Claim: make Django believe SQL-only migrations are real Python migration modules so Django can import and run them without duplicating files. Uses the import machinery: sys.meta_path, custom finder/loader and a sys.path_hooks path-entry hook, plus pkgutil.iter_modules and ModuleSpec mechanics. Builds virtual migration package and per-migration modules on the fly, registers them at runtime, and it works — used to let procrastinate expose PostgreSQL SQL migrations to Django with no disk files written.
AI-written summary · about
chapters (12)
- 0:00Start
- 0:16Joakim Jablon
- 3:03What a Sql Migration Is
- 6:49Procrastinate Sql Migrations
- 7:43Migrations
- 8:39Virtual Migration Files
- 9:55The Structure of the Import Machinery
- 10:30The Import Statement
- 15:33Sysdot Metapath
- 17:19Path Entries
- 25:09Create an Importer
- 27:55Item Modules
related talks
21mHacking the Python Import System
30mImporting Without "import": Behind the Scenes of importlib
26mWhat happens behind execution of an `import` statement?
23mHooking into the import system
29m"from where?!? import what?!?"
28mImport Deep Dive
45mWhat happens when you import a module?
23mEverything is a Python module
