Changes between Version 1 and Version 2 of Ticket #1380, comment 2


Ignore:
Timestamp:
Nov 1, 2018, 12:51:45 PM (7 years ago)
Author:
Greg Couch

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #1380, comment 2

    v1 v2  
    11I'm not so sure how doable this would be.  Finding the function for a command is:
    2 
    3     func = chimerax.core.commands.command_function("save")
    4     print('%s.%s' % (func.!__module__, func.!__qualname__))
    5 
     2{{{
     3func = chimerax.core.commands.command_function("save")
     4print('%s.%s' % (func.!__module__, func.!__qualname__))
     5}}}
    66But that function location might not match the supported location given in the documentation.  That is, the function location above is just a clue as to where the supported function is.  And, there is no public API to get the registered argument types for the function (the CmdDesc instance).  help(func) gives some information, but it may be incomplete (especially with the open and save commands where bundles can register additional keyword arguments for their file types).
    77
    88Thinking about how to implement the parse_atom_spec function:
    9 
    10     def parse_atom_spec(session, spec):
    11         from chimerax.core.commands import AtomSpecArg
    12         value, _, rest = AtomSpecArg.parse(spec, session)
    13         if rest:
    14             raise RuntimeError("extra characters at end of atom specification")
    15         return value
    16 
     9{{{
     10def parse_atom_spec(session, spec):
     11    from chimerax.core.commands import AtomSpecArg
     12    value, _, rest = AtomSpecArg.parse(spec, session)
     13    if rest:
     14        raise RuntimeError("extra characters at end of atom specification")
     15    return value
     16}}}
    1717That could be generalized to function that wrapped annotations into simple parse function:
    18 
    19      parse_atom_spec = as_parser(AtomSpecArg)
    20         
     18{{{
     19parse_atom_spec = as_parser(AtomSpecArg)
     20}}}