Permalink
Browse files

Add warning on missing notebook name

  • Loading branch information...
c-martinez committed Jan 20, 2017
1 parent c0b97ee commit 298c5273a9b0c1030ad6f7dc8d09fb597e7a97cb
Showing with 46 additions and 94 deletions.
  1. +16 −82 TestRecipyMagic.ipynb
  2. +12 −7 recipy/log.py
  3. +9 −0 recipyCommon/config.py
  4. +9 −5 recipyCommon/magic.py
View
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -36,29 +36,11 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"var kernel = IPython.notebook.kernel;\n",
"var attribs = document.body.attributes;\n",
"var command = \"recipyNotebookName = \" + \"'\"+attribs['data-notebook-name'].value+\"'\";\n",
"console.log(\"Load notebook name...\")\n",
"kernel.execute(command);"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%loadNotebookName"
]
@@ -74,49 +56,29 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No results found\r\n",
"\u001b[0m"
]
}
],
"outputs": [],
"source": [
"!./recipy-cmd search test.npy"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[RecipyMagic] this is when recipy should bet imported, not before...\n",
"[RecipyMagic] notebookName: TestRecipyMagic.ipynb\n",
"recipy run inserted, with ID 04a14e50-7447-400d-91aa-428090ae1850\n",
"recipy run inserted, with ID 12edf0d4-6b89-4645-8c37-57f5061f282b\n"
]
}
],
"outputs": [],
"source": [
"%recipyOn"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -127,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -141,27 +103,18 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No results found\n",
"\u001b[0m"
]
}
],
"outputs": [],
"source": [
"!./recipy-cmd search test.npy"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"collapsed": false
},
@@ -172,30 +125,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1mRun ID:\u001b[0m 12edf0d4-6b89-4645-8c37-57f5061f282b\r\n",
"\u001b[1mCreated by\u001b[0m neocarlitos on 2017-01-16 20:00:21 UTC\r\n",
"\u001b[1mRan\u001b[0m TestRecipyMagic.ipynb using /home/neocarlitos/workspace/Python/recipy/venv/bin/python\r\n",
"Using command-line arguments: -f /run/user/1000/jupyter/kernel-b2e338b7-9803-4eb7-bf93-3cd1f65af266.json\r\n",
"\u001b[1mEnvironment:\u001b[0m Linux-4.7.9-200.fc24.x86_64-x86_64-with-fedora-24-Twenty_Four, python 2.7.12 (default, Sep 29 2016, 13:30:34) \r\n",
"\u001b[1mLibraries:\u001b[0m recipy v0.3.0, numpy v1.11.2\r\n",
"\u001b[1mInputs:\u001b[0m none\r\n",
"\u001b[1mOutputs:\u001b[0m\r\n",
"/home/neocarlitos/workspace/Python/recipy/test.npy (377cfed96fd58963783e45607b9234584c33d551)\r\n",
"\r\n",
"\r\n",
"\u001b[0m"
]
}
],
"outputs": [],
"source": [
"!./recipy-cmd search test.npy"
]
View
@@ -16,7 +16,7 @@
from binaryornot.check import is_binary
from recipyCommon.version_control import add_git_info, add_svn_info, hash_file
from recipyCommon.config import option_set, get_db_path
from recipyCommon.config import option_set, get_db_path, get_notebook_mode
from recipyCommon.utils import open_or_create_db
from recipyCommon.libraryversions import get_version
@@ -36,18 +36,23 @@ def log_init(notebookName=None):
This is called when running `import recipy`.
"""
notebookMode = get_notebook_mode()
if notebookMode and notebookName is None:
# Avoid first call without Notebook name
return
if notebookMode:
scriptpath = notebookName
cmd_args = sys.argv[1:]
# Get the path of the script we're running
# When running python -m recipy ..., during the recipy import argument 0
# is -c (for Python 2) or -m (for Python 3) and the script is argument 1
if sys.argv[0] in ['-c', '-m']:
elif sys.argv[0] in ['-c', '-m']:
# Has the user called python -m recipy without further arguments?
if len(sys.argv) < 2:
return
scriptpath = os.path.realpath(sys.argv[1])
cmd_args = sys.argv[2:]
elif notebookName is not None:
scriptpath = notebookName
cmd_args = sys.argv[1:]
else:
scriptpath = os.path.realpath(sys.argv[0])
cmd_args = sys.argv[1:]
@@ -77,10 +82,10 @@ def log_init(notebookName=None):
"custom_values": {}
}
if not option_set('ignored metadata', 'git'):
if not notebookName and not option_set('ignored metadata', 'git'):
add_git_info(run, scriptpath)
if not option_set('ignored metadata', 'svn'):
if not notebookName and not option_set('ignored metadata', 'svn'):
add_svn_info(run, scriptpath)
View
@@ -91,3 +91,12 @@ def get_gui_port():
return int(conf.get('general', 'port'))
except Error:
return 9000
_notebookMode = False
def get_notebook_mode():
return _notebookMode
def set_notebook_mode(mode):
global _notebookMode
_notebookMode = mode
View
@@ -2,6 +2,8 @@
cell_magic, line_cell_magic)
import time
from recipyCommon.config import set_notebook_mode
# The class MUST call this class decorator at creation time
@magics_class
class RecipyMagic(Magics):
@@ -20,8 +22,6 @@ def loadNotebookName_js(self):
kernel.execute(command);
'''
r = self.shell.run_cell(cell)
# x = 1/0
#return None
return r
def getNotebookName(self):
@@ -32,6 +32,7 @@ def getNotebookName(self):
else:
retries -= 1
time.sleep(1)
return None
@@ -48,11 +49,14 @@ def recipyOn(self, line):
"my line magic"
# print("Full access to the main IPython object:", self.shell)
# print("Variables in the user namespace:", list(self.shell.user_ns.keys()))
set_notebook_mode(True)
notebookName = self.getNotebookName()
print("[RecipyMagic] this is when recipy should bet imported, not before...")
print("[RecipyMagic] notebookName: " + notebookName)
if notebookName is None:
print("[Recipy] Warning! Unable to get notebook name! Try running notebook step by step")
notebookName = "<unknown-notebook>"
import recipy
recipy.log_init(notebookName='TestRecipyMagic.ipynb')
recipy.log_init(notebookName=notebookName)
self.recipyModule = recipy
return None

0 comments on commit 298c527

Please sign in to comment.