-
Notifications
You must be signed in to change notification settings - Fork 7
gwrun argspec #30
base: master
Are you sure you want to change the base?
gwrun argspec #30
Conversation
For a sense of how this is going to be used, see: girder/girder_worker#314 |
girder_worker_utils/decorators.py
Outdated
if isinstance(doc, bytes): | ||
doc = doc.decode('utf-8') | ||
else: | ||
doc = cleandoc(doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't getdoc
do this already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not sure where that came from
girder_worker_utils/decorators.py
Outdated
return self._construct_argument( | ||
self._get_class(self._signature.parameters[key]), key) | ||
|
||
def _construct_argument(self, cls, name, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**kwargs
seems to be pointless here. Also, I would avoid the cls
parameter name because it makes the function read as a class method below.
girder_worker_utils/decorators.py
Outdated
raise TypeError('Expected argument name to be a string') | ||
|
||
data_type = kwargs.get("data_type", None) | ||
if data_type is not None and callable(data_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just if callable(data_type):
?
girder_worker_utils/decorators.py
Outdated
def description(): | ||
return getattr(func, GWFuncDesc._func_desc_attr) | ||
|
||
func.description = description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have both this and GWFuncDesc.get_description
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainly for compatibility with code that's already been written (e.g. item_tasks?) I can just drop it if nothing is actually using it
Handling instance bound variables (i.e. 'self') will have to be solved in the CLI.
I'm happy to roll 99cd62d back if we don't want to add the deprecation mechanism. It just seems like a better way to signal to downstreams that we're moving away from something. It might not make the most sense to start with girder_worker_utils, but GWU has been providing a nice test bed for stuff like this |
This allows metadata mapping for each type of argument to be defined on the consumers' (e.g. CLI) classes
This PR creates a decorator
parameter
that allows for arbitrary association of metadata with a callable's argument list.This metadata is exposed through an attribute on the callable as a
GWFuncDesc
object which has an API for accessing argument metdata. E.G.The ultimate goal is to use this metadata for automatic generation of CLI & Web UI tools from Girder Worker tasks