Skip to content

Commit

Permalink
#37: Add additional catches in case only poetry-core is available
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jan 30, 2021
1 parent 8f68961 commit 52ba27d
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,25 @@ def alt_poetry_create(cls, *args, **kwargs):

if not _state.patched_poetry_command_run:
# Fallback if it hasn't been caught by our patched importer already.
run_mod = _state.original_import_func("poetry.console.commands.run", fromlist=[None])
_patch_poetry_command_run(run_mod)
_state.patched_poetry_command_run = True
try:
run_mod = _state.original_import_func(
"poetry.console.commands.run", fromlist=[None]
)
_patch_poetry_command_run(run_mod)
_state.patched_poetry_command_run = True
except (ImportError, AttributeError):
pass

if not _state.patched_poetry_command_shell:
# Fallback if it hasn't been caught by our patched importer already.
shell_mod = _state.original_import_func(
"poetry.console.commands.shell", fromlist=[None]
)
_patch_poetry_command_shell(shell_mod)
_state.patched_poetry_command_shell = True
try:
shell_mod = _state.original_import_func(
"poetry.console.commands.shell", fromlist=[None]
)
_patch_poetry_command_shell(shell_mod)
_state.patched_poetry_command_shell = True
except (ImportError, AttributeError):
pass

cwd = None # type: Optional[Path]
if len(args) > 0:
Expand Down Expand Up @@ -384,7 +392,7 @@ def alt_import(name, globals=None, locals=None, fromlist=(), level=0):
elif name == "poetry" and "factory" in fromlist:
_patch_poetry_create(module.factory)
_state.patched_poetry_create = True
except ImportError:
except (ImportError, AttributeError):
pass

if not _state.patched_core_poetry_create:
Expand All @@ -395,7 +403,7 @@ def alt_import(name, globals=None, locals=None, fromlist=(), level=0):
elif name == "poetry.core" and "factory" in fromlist:
_patch_poetry_create(module.factory)
_state.patched_core_poetry_create = True
except ImportError:
except (ImportError, AttributeError):
pass

if not _state.patched_poetry_command_run:
Expand All @@ -406,7 +414,7 @@ def alt_import(name, globals=None, locals=None, fromlist=(), level=0):
elif name == "poetry.console.commands" and "run" in fromlist:
_patch_poetry_command_run(module.run)
_state.patched_poetry_command_run = True
except ImportError:
except (ImportError, AttributeError):
pass

if not _state.patched_poetry_command_shell:
Expand All @@ -417,7 +425,7 @@ def alt_import(name, globals=None, locals=None, fromlist=(), level=0):
elif name == "poetry.console.commands" and "shell" in fromlist:
_patch_poetry_command_shell(module.shell)
_state.patched_poetry_command_shell = True
except ImportError:
except (ImportError, AttributeError):
pass

return module
Expand Down

0 comments on commit 52ba27d

Please sign in to comment.