-
Notifications
You must be signed in to change notification settings - Fork 40
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
Custom body feature #14
Conversation
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.
@htorrence: This looks really good! I'm excited to see this feature added.
I have a few suggestions to clean up the code.
Two other things:
- Can you update the README with an example of how to use this?
- When I put in a string, the quotation marks are also included in the pop-up message. Can you see if there's a way to avoid that? You might have to strip the quotation marks or perhaps there's some other way.
jupyternotify/jupyternotify.py
Outdated
@@ -5,6 +5,7 @@ | |||
|
|||
from IPython.core.getipython import get_ipython | |||
from IPython.core.magic import Magics, magics_class, cell_magic | |||
from IPython.core.magic_arguments import magic_arguments, argument, parse_argstring |
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.
As @mdagost can tell you, I'm super into alphabetization so can you alphabetize these imports please?
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.
And while you're there, my errant non-alphabetization in the line above so that @parsing-science doesn't yell at me? :)
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.
fixed
jupyternotify/jupyternotify.py
Outdated
|
||
@magic_arguments() | ||
@argument("message", nargs="?", default="Cell Execution Has Finished!!", | ||
help="Custom notification message") |
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.
I think your line is short enough that you can have this argument on the same line as the other ones.
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.
fixed
jupyternotify/jupyternotify.py
Outdated
@cell_magic | ||
def notify(self, line, cell): | ||
|
||
# custom message |
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.
Looks like this comment needs to be over one space.
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.
fixed
jupyternotify/jupyternotify.py
Outdated
@cell_magic | ||
def notify(self, line, cell): | ||
|
||
# custom message | ||
args = parse_argstring(self.notify, line) |
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.
Did you do this in two separate lines in case we have multiple arguments in the future?
Would this work:
self.options["body"] = parse_argstring(self.notify, line).message
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.
changed - this is just argparse habit on my part, no real reason here
jupyternotify/jupyternotify.py
Outdated
|
||
@magic_arguments() | ||
@argument("message", nargs="?", default="Cell Execution Has Finished!!", |
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.
I think we probably want to have the arguments be called with dashes as you would in the command line. What do you think?
So something more like:
@argument("-m", "--message", nargs="?", default="Cell Execution Has Finished!!", help="Custom notification message")
Also, what is nargs?
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.
I followed the suggested format from the issue here - it feels a little more natural to me for a magic function to have the call be %%notify "cell finished"
than %%notify -m "cell finished"
, but it's an easy switch if you think command line notation is better.
nargs just specifies that some number of arguments should be gathered into a list, the question mark sets it so that if no argument is present then the default value is used. Argparse has weird notation for optional arguments (unless there's a better way of doing this I don't know about).
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.
I agree that with one argument, not having the -m
makes sense. I guess it depends on whether we think we're likely to have more arguments in the future. What do you think @mdagost, @htorrence?
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.
@htorrence: I removed nargs
from my code, and it seems to use the default correctly without it.
@@ -35,7 +43,7 @@ def notify(self, line, cell): | |||
jsString = jsFile.read() | |||
display(Javascript(jsString % { | |||
"notification_uuid": notification_uuid, | |||
"options": self.options, | |||
"options": json.dumps(self.options), |
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.
What's the purpose of the json.dumps? It seems like it would work even if you didn't do this?
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.
You get a javascript error without it - I don't think the Javascript conversion can handle being given a python dictionary
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.
Hmm, I tested removing that part, and it worked for me. What error were you seeing, @htorrence ?
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.
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.
As discussed in person, json.dumps is necessary.
adding custom message note
@htorrence Can you do two more things? Can you update the CHANGELOG and bump the version number in Thanks! |
Adds image of custom message and updates syntax for custom message call
…upyter-notify into custom_body_feature pulling readme updates locally
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.
Great work @htorrence! Merge away.
@@ -35,7 +43,7 @@ def notify(self, line, cell): | |||
jsString = jsFile.read() | |||
display(Javascript(jsString % { | |||
"notification_uuid": notification_uuid, | |||
"options": self.options, | |||
"options": json.dumps(self.options), |
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.
As discussed in person, json.dumps is necessary.
Changes the options attribute to be a dictionary and adds argument parsing to allow for custom notification messages.
Closes issue #13