Merge lp:~johnsca/charm-helpers/cmdline-conditional-import into lp:charm-helpers

Proposed by Cory Johns
Status: Merged
Merged at revision: 418
Proposed branch: lp:~johnsca/charm-helpers/cmdline-conditional-import
Merge into: lp:charm-helpers
Diff against target: 27 lines (+16/-1)
1 file modified
charmhelpers/core/hookenv.py (+16/-1)
To merge this branch: bzr merge lp:~johnsca/charm-helpers/cmdline-conditional-import
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review via email: mp+266616@code.launchpad.net

Description of the change

Conditional import of cmdline in hookenv so that we can still avoid duplication while gracefully dealing with charms that partially sync charmhelpers directly in (sans the cli portion).

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

+1 LGTM - expressing this into upstream as it broke OpenStack CI - if this causes an issue lets bug it and circle back.

move along, this is not the droid you are looking for.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/hookenv.py'
2--- charmhelpers/core/hookenv.py 2015-07-29 15:33:35 +0000
3+++ charmhelpers/core/hookenv.py 2015-07-31 19:46:11 +0000
4@@ -34,7 +34,22 @@
5 import tempfile
6 from subprocess import CalledProcessError
7
8-from charmhelpers.cli import cmdline
9+try:
10+ from charmhelpers.cli import cmdline
11+except ImportError as e:
12+ # due to the anti-pattern of partially synching charmhelpers directly
13+ # into charms, it's possible that charmhelpers.cli is not available;
14+ # if that's the case, they don't really care about using the cli anyway,
15+ # so mock it out
16+ if str(e) == 'No module named cli':
17+ class cmdline(object):
18+ @classmethod
19+ def subcommand(cls, *args, **kwargs):
20+ def _wrap(func):
21+ return func
22+ return _wrap
23+ else:
24+ raise
25
26 import six
27 if not six.PY3:

Subscribers

People subscribed via source and target branches