Search code examples
pythonpyxb

Is there any way to workaround import version conflict ion issue caused by Pyxb


I have 3 python projects. Project A, project B and project C. Project C depends on Porject A and B

Project C --- depends ---> Project A
Project C --- depends ---> Project B

And project A and project B all depends on PyXB, they use some generated schema module. Unfortunately, project A uses PyXB 1.2.2, and project B uses PyXB 1.2.3

Project A --- depends ---> PyXB 1.2.2
Project B --- depends ---> PyXB 1.2.3

If you read these modules, you will see

# Version of PyXB used to generate the bindings
_PyXBVersion = '1.2.3'
# Generated bindings are not compatible across PyXB versions
if pyxb.__version__ != _PyXBVersion:
    raise pyxb.PyXBVersionError(_PyXBVersion)

and

# Version of PyXB used to generate the bindings
_PyXBVersion = '1.2.2'
# Generated bindings are not compatible across PyXB versions
if pyxb.__version__ != _PyXBVersion:
    raise pyxb.PyXBVersionError(_PyXBVersion)

So, for now, Project C has a version conflict issue

Project C --- depends ---> PyXB 1.2.2
                                ^
                                |
                                X conflict
                                |
                                v
Project C --- depends ---> PyXB 1.2.3

And since these schema modules were manually modified. It's hard to regenerate them and apply the same modifications. So I am wondering is it possible to import the same module with different version in Python. For example, I envision that could be something like

with import_routing('pyxb', '..packages.pyxb1_2_3'):
    import project_a

is there a tool like this? or is there other workaround I can use in this situation?


Solution

  • Not easily. The bindings really do make assumptions about the underlying API presented by a specific version of PyXB. There's probably some magic you could do with modifying the module metadata to allow two versions to co-exist, as long as no document referenced bindings from both namespaces.

    It's unfortunate that the generated bindings were manually modified. In many cases, use of PyXB's customization infrastructure would eliminate that tight coupling, in which case you could re-generate the bindings and re-use the customizations that overlay them.