Skip to content

Commit

Permalink
issue #291: don't attempt mitogen import until sys.path modified.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dw committed Jul 28, 2018
1 parent 3b10920 commit 6c03b83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions ansible_mitogen/plugins/strategy/mitogen.py
Expand Up @@ -44,12 +44,12 @@
# debuggers and isinstance() work predictably.
#

try:
import ansible_mitogen
except ImportError:
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..')))
del base_dir
BASE_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../..')
)

if BASE_DIR not in sys.path:
sys.path.insert(0, BASE_DIR)

import ansible_mitogen.strategy
import ansible.plugins.strategy.linear
Expand Down
12 changes: 6 additions & 6 deletions ansible_mitogen/plugins/strategy/mitogen_free.py
Expand Up @@ -44,12 +44,12 @@
# debuggers and isinstance() work predictably.
#

try:
import ansible_mitogen
except ImportError:
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..')))
del base_dir
BASE_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../..')
)

if BASE_DIR not in sys.path:
sys.path.insert(0, BASE_DIR)

import ansible_mitogen.loaders
import ansible_mitogen.strategy
Expand Down
12 changes: 6 additions & 6 deletions ansible_mitogen/plugins/strategy/mitogen_linear.py
Expand Up @@ -44,12 +44,12 @@
# debuggers and isinstance() work predictably.
#

try:
import ansible_mitogen
except ImportError:
base_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.abspath(os.path.join(base_dir, '../../..')))
del base_dir
BASE_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../..')
)

if BASE_DIR not in sys.path:
sys.path.insert(0, BASE_DIR)

import ansible_mitogen.loaders
import ansible_mitogen.strategy
Expand Down

0 comments on commit 6c03b83

Please sign in to comment.