Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in docs for grouping has no output #240

Open
MSAdministrator opened this issue Apr 6, 2020 · 5 comments
Open

example in docs for grouping has no output #240

MSAdministrator opened this issue Apr 6, 2020 · 5 comments
Labels

Comments

@MSAdministrator
Copy link

@MSAdministrator MSAdministrator commented Apr 6, 2020

Hello, following the docs here: https://github.com/google/python-fire/blob/master/docs/guide.md#grouping-commands

I am unable to get this to run when calling

example.py run

It currently returns no output.

If I run either of the digestion run or ingestion run commands they work flawlessly just not the grouped command

Heres the code:

import fire

class IngestionStage(object):

  def run(self):
    return 'Ingesting! Nom nom nom...'

class DigestionStage(object):

  def run(self, volume=1):
    return ' '.join(['Burp!'] * volume)

  def status(self):
    return 'Satiated.'

class Pipeline(object):

  def __init__(self):
    self.ingestion = IngestionStage()
    self.digestion = DigestionStage()

  def run(self):
    self.ingestion.run()
    self.digestion.run()

if __name__ == '__main__':
  fire.Fire(Pipeline)
@dbieber
Copy link
Member

@dbieber dbieber commented Apr 6, 2020

Can you provide an example of a failing command? (Edit: Sorry, you did. I just missed it.)

If you run

python example.py digestion status

you should see

Satiated.

Is that not working for you, or is it something else?

@dbieber
Copy link
Member

@dbieber dbieber commented Apr 6, 2020

Oh, is it python example.py run that isn't working?

That command doesn't output anything, because it neither prints nor returns anything. We should update the docs so that it does something...

Edit: Yes, I see you did say that was your issue. Hope I've cleared it up now. Sorry for the misleading docs.

@dbieber dbieber changed the title Grouping Commands in Docs not working example in docs for grouping has no output Apr 6, 2020
@MSAdministrator
Copy link
Author

@MSAdministrator MSAdministrator commented Apr 6, 2020

@dbieber Thanks for the quick response!

So calling example.py run does not actually call the Pipeline().run() method?

@dbieber
Copy link
Member

@dbieber dbieber commented Apr 6, 2020

It does. Both ingestion.run() and digestion.run() both get called (because Pipeline().run() is called). Just nothing is displayed, since Pipeline().run() doesn't return anything (and nothing prints along the way).

If Pipeline().run() returned something, it would be displayed.

@MSAdministrator
Copy link
Author

@MSAdministrator MSAdministrator commented Apr 6, 2020

Ahh, okay I missed that those classes are returning and not printing - my bad - yep that makes sense.

Modified the example to just print and its working - derp on my part:

class Pipeline(object):

  def __init__(self):
    self.ingestion = IngestionStage()
    self.digestion = DigestionStage()

  def run(self):
    print(self.ingestion.run())
    print(self.digestion.run())

if __name__ == '__main__':
    fire.Fire(Pipeline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.