Merge lp:~lazypower/charm-helpers/revert-418 into lp:charm-helpers

Proposed by Charles Butler
Status: Rejected
Rejected by: Matt Bruzek
Proposed branch: lp:~lazypower/charm-helpers/revert-418
Merge into: lp:charm-helpers
Diff against target: 27 lines (+1/-16)
1 file modified
charmhelpers/core/hookenv.py (+1/-16)
To merge this branch: bzr merge lp:~lazypower/charm-helpers/revert-418
Reviewer Review Type Date Requested Status
Cory Johns (community) Approve
charmers Pending
Review via email: mp+266900@code.launchpad.net

Description of the change

It was discussed to remove the work-around all together, and leave the current behavior as is, making hookenv dependent on Cli.

To post a comment you must log in.
Revision history for this message
Cory Johns (johnsca) wrote :

+1 but it may be a good idea to send something to the mailing list or something to let people know of this new requirement.

review: Approve
Revision history for this message
Matt Bruzek (mbruzek) wrote :

Chuck made a good change here, but in my testing with a virtual environment I could not import charmhelpers.cli without first pip installing six and pyyaml. I think those should be added to the requirements file so we can install this from the directory.

Revision history for this message
Cory Johns (johnsca) wrote :
Revision history for this message
Cory Johns (johnsca) wrote :

Ok, so here's a summary of the motivation for this and discussion so far, for reference:

Last week, I added some new helpers to hookenv that I wanted exposed via the CLI. Instead of creating thin wrappers around them under charmhelpers.cli, I imported and used the @cmdline.subcommand decorator directly in hookenv. This works fine if charmhelpers is installed via pip, but can break if it is partially sync'd in via charm-helpers-sync.yaml where core is included and cli is not.

I originally tried to make a quick work-around for it by making the import conditional, which was the commit that this was reverting. I apparently got a different import error message than was seen in the Open Stack charms, so the work-around didn't work. However, they added cli to their charm-helpers-sync.yaml and everything was fine for them w/o the work-around. Hence this revert.

However, it has been noted that charm-helpers-sync.yaml is (an unfortunately) common pattern, and most people expect sync'ing just core to work, which is entirely reasonable. So, we probably either need to re-institute the work-around and handle both import error messages, or follow the existing pattern of creating thin wrappers around the helpers to expose them via the CLI.

On the one hand, I'd prefer not to require thin wrappers, because I feel that it discourages exposing helpers via the CLI (as evinced by the dearth of helpers which are exposed). On the other hand, the conditional import is a little ugly.

Probably my ideal solution would be to split the cli package into a separate module, or even better, use an existing library such as begins (https://pypi.python.org/pypi/begins) cli_tools (https://pypi.python.org/pypi/cli_tools) or pyCLI (https://pypi.python.org/pypi/pyCLI).

Revision history for this message
Matt Bruzek (mbruzek) wrote :

After some discussion on this MP we decided to fix this problem in another one. I am going to close this MP to defer to the next more complete fix.

Unmerged revisions

420. By Charles Butler

Back out #418

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-31 19:43:43 +0000
3+++ charmhelpers/core/hookenv.py 2015-08-04 15:48:21 +0000
4@@ -34,22 +34,7 @@
5 import tempfile
6 from subprocess import CalledProcessError
7
8-try:
9- from charmhelpers.cli import cmdline
10-except ImportError as e:
11- # due to the anti-pattern of partially synching charmhelpers directly
12- # into charms, it's possible that charmhelpers.cli is not available;
13- # if that's the case, they don't really care about using the cli anyway,
14- # so mock it out
15- if str(e) == 'No module named cli':
16- class cmdline(object):
17- @classmethod
18- def subcommand(cls, *args, **kwargs):
19- def _wrap(func):
20- return func
21- return _wrap
22- else:
23- raise
24+from charmhelpers.cli import cmdline
25
26 import six
27 if not six.PY3:

Subscribers

People subscribed via source and target branches