This is not a duplicate of the question:
Import python packages with different versions installed
Nor can it be solved by virtualenv/pipenv: packages that share the same name/path but has different code/version must be installed under the same environment for the program to function properly
Considering the following classic diamond dependency problem:
Assuming we have full access over the sourcecode of packages 'program', 'feature_A', and 'feature_B', and both feature_A and feature_B has the following code:
import library.*
In a conventional package manager like virtualenv, pip and conda, The above situation will preclude feature_A and feature_B from being used in the same project. However since python is an interpretive language, and we can use the source code of feature_A and feature_B. It should be possible to do the following things:
ingest the package source/byte codes of both library (v1.0) and library (v2.0), generate 2 cryptographic hash for each, and install them under 2 different paths that depends on their respective hashes.
use a code generator to rewrite feature_A and feature_B such that they import from new paths that depends on cryptographic hashes, and install the rewritten versions.
use the code generator to rewrite program such that it imports from the new paths where the rewritten feature_A and feature_B are installed.
Now my question is: how difficult it is to fully automate this process? Is a weak artificial intelligence required? Or it can be accomplished using pure functional logic?
I would install the different package versions in different PYTHONPATH, e.g.
PYTHONPATH=insertherepath1 ; python setup.py install --prefix=insertherepath1
or
PYTHONPATH=insertherepath1 ; pip install --install-option="--prefix=insertherepath1" package==v1
and the same for the other version of the package to be installed in another path insertherepath2. The two installations in different PYTHONPATHs still can access other commonly installed packages in the main python path.
To use the different packages within python:
import sys
sys.path.insert(0, 'insertherepath1')
import package #gets version 1
#maybe (depends on further dependencies) : sys.path.pop(0)
and equivalently to use the other version:
import sys
sys.path.insert(0, 'insertherepath2')
import package #gets version 2
#maybe (depends on further dependencies) : sys.path.pop(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With