def get_grinimports_arg_parser(parser=None):
    """ Create the command-line parser.
    """
    parser = grin.get_grin_arg_parser(parser)
    parser.set_defaults(include='*.py')
    parser.description = ("Extract, normalize and search import statements "
        "from Python files.")
    parser.epilog = """
For example, if I have a file example.py with a bunch of imports:

    $ cat example.py
    import foo
    import foo.baz as blah
    from foo import bar, baz as bat

    def somefunction():
        "Do something to foo.baz"
        import from_inside.function

We can grep for 'import' in order to get all of the import statements:

    $ grinimports.py import example.py
    example.py:
        1 : import foo
        2 : import foo.baz as blah
        3 : from foo import bar
        4 : from foo import baz as bat
        5 : import from_inside.function

If we just want to find imports of foo.baz, we can do this:

    $ grinimports.py "import foo\.baz|from foo import baz" example.py
    example.py:
        2 : import foo.baz as blah
        4 : from foo import baz as bat

A typical grep (or grin) cannot find all of these in the original files because
the import statements are not normalized.

    $ grin "foo\.baz|from foo import baz" example.py
    example.py:
        2 : import foo.baz as blah
        6 :     "Do something to foo.baz"
"""
    for action in parser._actions:
        if hasattr(action, 'version'):
            action.version = 'grinpython %s' % __version__

    return parser
dataset/ETHPy150Open while0pass/grin/examples/grinimports.py/get_grinimports_arg_parser/original