You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Function doc as a parameter to the start and subcommand decorator functions. #40
In the past week I have found myself writing small decorators to patch in the doc before begins reads the doc from my function. This proposal simply allows the developer to provide a function doc string to begins through the decorator's constructor.
In the past week I have found myself writing small decorators to patch in the doc before begins reads the doc from my function. This proposal simply allows the developer to provide a function doc string to begins through the decorator's constructor.
Currently this is what I have done to get around not having doc as a parameter: https://gist.github.com/mjdorma/6145546
A simple example of the current state:
First example is when I want the module main to appear as the doc string, this ties in really well when building a Sphinx documented module, where the module is the main or a command line interface entry point.
As a second example, I have a package that installs platform specific files and builds a database of the install state. When I print the help for the main entry point to this package I dynamically update the help depending on what the state of the install database is.
Another dummy program example:
import begin
def install_meta():
return dict(foo='blah')
def _doc_inserter(main):
main.__doc__ = "The main with %(foo)s" % install_meta()
return main
@begin.start
@_doc_inserter
def main():
pass
Here is an example of patching in the version (a cheap win to print in out in the main's help doc):
import version
import begin
def _doc_inserter(main):
main.__doc__ = "Foo blah (v%s)" % version.__version__
return main
@begin.start
@_doc_inserter
def main():
pass
Activity
aliles commentedon Feb 18, 2014
Can you explain further your use case for this? Why is the docstring not sufficient?
I'm not against this per say. More I want to be convinced before adding complexity to begins that there isn't a better solution.
On Tue, Feb 18, 2014 at 3:11 PM, Michael Dorman notifications@github.com
wrote:
mjdorma commentedon Feb 18, 2014
First example is when I want the module main to appear as the doc string, this ties in really well when building a Sphinx documented module, where the module is the main or a command line interface entry point.
As a second example, I have a package that installs platform specific files and builds a database of the install state. When I print the help for the main entry point to this package I dynamically update the help depending on what the state of the install database is.
Another dummy program example:
Here is an example of patching in the version (a cheap win to print in out in the main's help doc):