Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
erp5 erp5
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Labels
    • Labels
  • Merge requests 139
    • Merge requests 139
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedi
  • erp5erp5
  • Merge requests
  • !1130

Open
Created May 25, 2020 by Arnaud Fontaine@arnauDeveloper
  • Report abuse
Report abuse

WIP: ZODB Components: Filesystem modules imports compatibility

  • Overview 5
  • Commits 3
  • Changes 73

@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:

  1. 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() and install_products() of OFS.Application.
  2. In ERP5Site.__of__() (AFAIK, the earliest place where site.portal_components is accessible): 1. Create a mapping between the old filesystem imports stored in source_reference and the new ZODB Component imports, used in import hooks. 2. Import and install all remaining Products (ERP5, CMFActivity, ERP5Catalog...). Products with modules importing Products.ERP5.Document.Foo will go through ZODB Components import hooks and return erp5.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 and BaseCategory.py. But these would have had to be moved eventually to ERP5Type 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, currently fix_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!

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: arnau-RD-Components-Products-import-compat
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7