EMS-TU-Ilmenau / chefkoch

A compute cluster cuisine for distributed scientific computing in python
Apache License 2.0
5 stars 1 forks source link

Investigate on detecting names of function arguments #50

Open ChristophWWagner opened 4 years ago

ChristophWWagner commented 4 years ago

FInd out how to detet names of function arguments (key-worded arguments) of python functions.

def aFunction(bla=123, blub='abc'):
    pass

By using Python's inspect capabilities, a function shall be generated that returns ['bla', 'blub'] for the given example, i.e. the names of the keyworded arguments of an arbitrary function.

Final result: A demonstration script is created that contains the function and exhibits correct functionality. Additional capabilities and interesting notes about the inspection framework are documented in the discussion to this issue.

wiebsS commented 4 years ago

The function getargspec should do the trick. It also returns the default values. If you use the Python3 interpreter you could also use getfullargspec.

wiebsS commented 4 years ago

Another interesting use of inspect could be the getmembers, if we want to know the names of certain objects of a given class. It could return all function names, for example.

ChristophWWagner commented 4 years ago

Good, the code on function name inspection should work based on the data blob of a StepPython item in the Fridge. When a StepPython Item is instantiated, we need to do the following steps:

  1. Get the resource out of the fridge that corresponds to the step code (these resources should have been generated already in the early preparation stages of a chefkoch run)
  2. Once we have that resouce item object, load the data blob of that item as a python module and check, whether we have a execute function and store a reference to this function inside the StepPython object for execution.
  3. Then we need to check the input arguments to that code. We expect to have exactly one positional argument, that will pass the chef instance to the function (let's name this guy chef for simplicity). All arguments to the step will be passed via keyworded arguments, whose names we need to extract and also store in the StepPython object as the input key list.
  4. The return value of the execute function shall always be a dictionary with name:value mappings. We'll see how we handle this guy exactly when we come to execution handling