Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update activity #12: help defining an activity that executes a program #20

Merged
merged 4 commits into from
Mar 26, 2015

Conversation

ggreg
Copy link
Contributor

@ggreg ggreg commented Aug 8, 2014

Please review. Fix #20.

These changes adds the ability to define an activity that executes an external program and a helper to execute a function with another Python interpreter in a sub-process.

"""
Examples:

>>> with_named_arguments('a', 'b', c=1, d=2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just forbid the mix of positional arguments and named arguments? What I mean is that if the task has chosen with_named_arguments, then all its arguments should be passed as named arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the name is ambiguous. We could only keep the behavior of with_named_arguments but change the name of the function.

@darkjh
Copy link

darkjh commented Aug 8, 2014

Maybe a workflow test with mixture of different kinds of tasks?

@ggreg
Copy link
Contributor Author

ggreg commented Aug 8, 2014

Yes, I'm improving it by adding some validation based on the signature of the decorated function:

  • def cmd(*args, **kwargs) accepts variable arguments and keyword arguments.
  • def cmd(*args) does not accept any keyword argument.
  • def cmd(**kwargs) only accepts keyword arguments.
  • def cmd(a='', *args) accepts the keyword argument (with default value '') a and variable arguments.
  • def cmd(a, b) only accepts two positional arguments.
  • def cmd(a='', b='blah') only accepts two keyword arguments.

Each kind will have at least a test as an example.

@darkjh
Copy link

darkjh commented Aug 8, 2014

Ok that will be cool.

@ggreg
Copy link
Contributor Author

ggreg commented Feb 10, 2015

Most tasks have arguments of builtin types (string or int). When the values come from the command line they will be strings. If the task is an actual program, it expects strings. When the task is a program that wraps a callable, the program should know how to convert the command line arguments into the types expected by the callable. Hence we need a way to declare the type of each argument of a task.

@darkjh
Copy link

darkjh commented Feb 10, 2015

@ggreg would protocols like protobuf or thrift useful here?
The tasks can be declared with a language-independent way.

@ggreg
Copy link
Contributor Author

ggreg commented Feb 10, 2015

I find protocol buffers and thrift too heavy in this context. The way to serialize and define arguments should be flexible and allow such methods. However, I prefer that we start with a simple method such as telling the type in the decorator. The main limitation here would come from nested types for example a list of integers. In this case telling xs=list is not enough.

We could use xs=json.loads to load dynamic types but it does not document the expected type. Should it be a concern? We use Python and can't ensure the type of a function's arguments. So, it's fine. As JSON is still ubiquitous in simpleflow, let parse arguments from the command line as JSON values.

@ggreg ggreg force-pushed the feature/activity-execute-program branch 2 times, most recently from 85213ce to 6d864ef Compare February 18, 2015 10:25
@ggreg
Copy link
Contributor Author

ggreg commented Feb 26, 2015

The Travis build with pypy is failing. Python2.7 build is fine.

I'm figuring out how to fix the pypy build.

@ampelmann @jbbarth please review.

@ampelmann
Copy link
Member

LGTM ! 😎

except:
raise ValueError('cannot load arguments from {}'.format(
raw_arguments))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we have 4 arguments on the command line, we continue and will get obscure errors later, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Even with such simple interface I should have use argparse to document how the command behave. Note that it's not excuse for this lack of rigor 😉. At first I only thought of this as a private interface to run functions as programs but it could also be used directly from the command line.

@ggreg ggreg force-pushed the feature/activity-execute-program branch from 6d864ef to ccc469e Compare February 27, 2015 13:54
@ggreg ggreg force-pushed the feature/activity-execute-program branch 4 times, most recently from 90e167a to 490bd75 Compare March 23, 2015 17:31
@ggreg
Copy link
Contributor Author

ggreg commented Mar 24, 2015

Parsing the history with the pypy and CPython versions led to different event types and states for child workflows. It comes from the way simple-workflow lookups the name of event types. It iterates of the keys of the EVENTS dict. There is no guaranty in the order of keys in a Python dict, that's why there is a collections.OrderedDict class. See botify-labs/python-simple-workflow#45.

@ggreg ggreg force-pushed the feature/activity-execute-program branch from 490bd75 to c5f5ba1 Compare March 24, 2015 15:43
@ggreg ggreg force-pushed the feature/activity-execute-program branch from 2e6d8c7 to ec29758 Compare March 24, 2015 22:00
@ggreg
Copy link
Contributor Author

ggreg commented Mar 25, 2015

Green, at last!

@ggreg ggreg force-pushed the feature/activity-execute-program branch from ec29758 to ae8ea60 Compare March 25, 2015 10:45
@ggreg ggreg force-pushed the feature/activity-execute-program branch from ae8ea60 to 807cad1 Compare March 25, 2015 10:57
@ggreg
Copy link
Contributor Author

ggreg commented Mar 25, 2015

Added a very short document in docs/. Last review before merging.

ggreg added a commit that referenced this pull request Mar 26, 2015
Update activity #12: help defining an activity that executes a program
@ggreg ggreg merged commit cef0d3b into master Mar 26, 2015
@ggreg ggreg deleted the feature/activity-execute-program branch March 26, 2015 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants