8000 Custom body feature by htorrence · Pull Request #14 · ShopRunner/jupyter-notify · GitHub
[go: up one dir, main page]

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

Custom body feature #14

Merged
merged 7 commits into from
Aug 25, 2017
Merged

Custom body feature #14

merged 7 commits into from
Aug 25, 2017

Conversation

htorrence
Copy link
Contributor

Changes the options attribute to be a dictionary and adds argument parsing to allow for custom notification messages.

Closes issue #13

Copy link
Contributor
@parsing-science parsing-science left a 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.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor

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? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


@magic_arguments()
@argument("message", nargs="?", default="Cell Execution Has Finished!!",
help="Custom notification message")
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@cell_magic
def notify(self, line, cell):

# custom message
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@cell_magic
def notify(self, line, cell):

# custom message
args = parse_argstring(self.notify, line)
Copy link
Contributor

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

8000
Copy link
Contributor Author

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


@magic_arguments()
@argument("message", nargs="?", default="Cell Execution Has Finished!!",
Copy link
Contributor

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?

Copy link
Contributor Author
@htorrence htorrence Aug 24, 2017

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).

Copy link
Contributor

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?

Copy link
Contributor

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),
Copy link
Contributor

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?

8000

Copy link
Contributor Author

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

Copy link
Contributor

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 ?

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'm getting this:
screen shot 2017-08-25 at 9 15 40 am

Copy link
Contributor

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.

Hanna Torrence and others added 2 commits August 24, 2017 17:13
@mdagost
Copy link
Contributor
mdagost commented Aug 25, 2017

@htorrence Can you do two more things? Can you update the CHANGELOG and bump the version number in setup.py?

Thanks!

htorrence and others added 3 commits August 25, 2017 09:43
Adds image of custom message and updates syntax for custom message call
…upyter-notify into custom_body_feature

pulling readme updates locally
Copy link
Contributor
@parsing-science parsing-science left a 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),
Copy link
Contributor

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.

@htorrence htorrence merged commit 488814d into master Aug 25, 2017
@htorrence htorrence deleted the custom_body_feature branch August 25, 2017 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0