WIP: ZODB Components: Filesystem modules imports compatibility
@nexedi Until now, fix_imports
command line script was used to fix imports in existing code after migration from filesystem to ZODB Components (eg fixing from Products.ERP5.Document.Foo import ...
to erp5.component.document.Foo import ...
for example). However, @jp and @romain do not like this and so here is a PoC implementing Products imports compatibility by using existing ZODB Components import hooks. Even though this does not require much code, it is a very intrusive change so you should read carefully until the end...
Let's consider Foo
which has been migrated from Products.ERP5.Document.Foo
(this is an example with Documents
but this is not specific to Documents
) to portal_components/document.erp5.Foo
and now importable as erp5.component.document.Foo
. What we want is being able to import Products.ERP5.Document.Foo
and get erp5.component.document.Foo
module. However, this requires to access site.portal_components
. At the same time we also need to consider that Products.ERP5.Document.Foo
could have been imported by any modules of any Products.
The only solution I could come up with is:
- At Zope startup, import and install only Zope and ERP5Type Products (IOW, the minimum to get access to ERP5Site). This is done by a tiny patch (not a monkey patch) on
import_products()
andinstall_products()
ofOFS.Application
. - In
ERP5Site.__of__()
(AFAIK, the earliest place wheresite.portal_components
is accessible): 1. Create a mapping between the old filesystem imports stored insource_reference
and the new ZODB Component imports, used in import hooks. 2. Import and install all remaining Products (ERP5
,CMFActivity
,ERP5Catalog
...). Products with modules importingProducts.ERP5.Document.Foo
will go through ZODB Components import hooks and returnerp5.component.document.Foo
, just like any ZODB Component module.
Some important points:
- This means that ERP5Type must contain everything necessary to start ERP5 and use ZODB Components. Therefore, I've had to move several modules to ERP5Type, including
ERP5Site.py
andBaseCategory.py
. But these would have had to be moved eventually toERP5Type
anyway as we progressively get rid of all filesystem Products. - This won't and cannot work with
runUnitTest
so you still need to run a script to fix imports, currentlyfix_imports
command line script but this could be part of upgrader (even though I don't really like the idea of modifying source code automatically on a live instance). - This requires a patch on Zope.
Any ideas or suggestions for improvement welcome!