issue #291: don't attempt mitogen import until sys.path modified.

Given an extracted download of mitogen-2.2.tar.gz, with strategy_plugins
pointing into it, if an old version of the package was pip-installed,
then the old pip-installed package would be imported and override
whatever came from the tarball.

Instead, modify sys.path before attempting any import. This still isn't
perfect, but it's better.
pull/350/head
David Wilson 6 years ago
parent 3b10920157
commit 6c03b83748

@ -44,12 +44,12 @@ import sys
# debuggers and isinstance() work predictably. # debuggers and isinstance() work predictably.
# #
try: BASE_DIR = os.path.abspath(
import ansible_mitogen os.path.join(os.path.dirname(__file__), '../../..')
except ImportError: )
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..'))) if BASE_DIR not in sys.path:
del base_dir sys.path.insert(0, BASE_DIR)
import ansible_mitogen.strategy import ansible_mitogen.strategy
import ansible.plugins.strategy.linear import ansible.plugins.strategy.linear

@ -44,12 +44,12 @@ import sys
# debuggers and isinstance() work predictably. # debuggers and isinstance() work predictably.
# #
try: BASE_DIR = os.path.abspath(
import ansible_mitogen os.path.join(os.path.dirname(__file__), '../../..')
except ImportError: )
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..'))) if BASE_DIR not in sys.path:
del base_dir sys.path.insert(0, BASE_DIR)
import ansible_mitogen.loaders import ansible_mitogen.loaders
import ansible_mitogen.strategy import ansible_mitogen.strategy

@ -44,12 +44,12 @@ import sys
# debuggers and isinstance() work predictably. # debuggers and isinstance() work predictably.
# #
try: BASE_DIR = os.path.abspath(
import ansible_mitogen os.path.join(os.path.dirname(__file__), '../../..')
except ImportError: )
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..'))) if BASE_DIR not in sys.path:
del base_dir sys.path.insert(0, BASE_DIR)
import ansible_mitogen.loaders import ansible_mitogen.loaders
import ansible_mitogen.strategy import ansible_mitogen.strategy

Loading…
Cancel
Save