Skip to content
This repository has been archived by the owner on Dec 29, 2017. It is now read-only.

Commit

Permalink
Merge pull request #95 from KesterTong/jinja
Browse files Browse the repository at this point in the history
Modify build system and closure dependencies
  • Loading branch information
rgbkrk committed Mar 19, 2016
2 parents 198db23 + 53e1d9d commit 1425c6e
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 95 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Some guidelines on contributing to coLaboratory:
* Pull Requests should generally be made against master

For more detailed information, see our [GitHub Workflow](https://github.com/ipython/ipython/wiki/Dev:-GitHub-workflow).

Make sure to run build_colab_deps.py before creating a pull request, to ensure that
the file colab.dep is up to date.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ CoLaboratory's collaboration model is evolving. The current model is a single co
To understand how a state mismatch can manifest, consider the scenario below. Bob and Sue are working on the same notebook at the same time. Both Bob and Sue will have their own kernel state. Bobs changes will change the notebook Sue sees, but Sue's state is unchanged. If sue tries to access the variable Bob created, she will get an error.

![Collaboration Error](https://github.com/jupyter/colaboratory/raw/master/documentation/img/collaboration-error.png)

## Development

You can simply edit JavaScript code in place and these changes will be reflected automatically. You may need to refresh the browser several times to clear the cache after making changes.

If you add new files or add/remove goog.require statements at the start of JavaScript files, you need to run the script build_colab_deps.py in order to compile the list of dependencies.
35 changes: 35 additions & 0 deletions build_colab_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess
import sys

from install_lib import COLAB_ROOT_PATH
from install_lib import pjoin

RESOURCES_DIR = pjoin(COLAB_ROOT_PATH, 'colaboratory', 'resources')

CLOSURE_DIR = pjoin(RESOURCES_DIR, 'closure-library')

CALC_DEPS_FILE = pjoin(CLOSURE_DIR, 'closure', 'bin', 'calcdeps.py')

GOOG_ROOT = CLOSURE_DIR
COLAB_ROOT = pjoin(RESOURCES_DIR, 'colab')

OUTPUT_FILE = pjoin(COLAB_ROOT, 'js', 'colab.dep')

subprocess.call([
'python',
CALC_DEPS_FILE,
'--dep',
GOOG_ROOT,
'--path',
COLAB_ROOT,
'--output_mode',
'deps',
'--output_file',
OUTPUT_FILE])

subprocess.call([
'sed',
'-i', '',
's/\.\.\/\.\.\/\.\./\.\./g',
OUTPUT_FILE])

52 changes: 7 additions & 45 deletions bundle_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,13 @@
import shutil
import urllib

COLAB_ROOT_PATH = os.path.dirname(os.path.realpath(__file__))

pjoin = os.path.join

def MakeDirectoryIfNotExist(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise

def RemoveDirectoryIfExist(path):
try:
shutil.rmtree(path)
except OSError as exception:
if exception.errno != errno.ENOENT:
raise

def RemoveFileIfExist(path):
try:
os.remove(path)
except OSError as exception:
if exception.errno != errno.ENOENT:
raise

def RemoveFileOrDirectoryIfExist(path):
try:
RemoveDirectoryIfExist(path)
except OSError as exception:
if exception.errno == errno.ENOTDIR:
RemoveFileIfExist(path)
else:
raise


def CopyTreeRecursively(src, dest):
"""Roughly equivalent to cp -r src/* dest"""
MakeDirectoryIfNotExist(dest)
for entry in os.listdir(src):
s = pjoin(src, entry)
d = pjoin(dest, entry)
if os.path.isdir(s):
CopyTreeRecursively(s, d)
else:
shutil.copy(s, d)
from install_lib import COLAB_ROOT_PATH
from install_lib import pjoin
from install_lib import CopyTreeRecursively
from install_lib import MakeDirectoryIfNotExist
from install_lib import RemoveDirectoryIfExist
from install_lib import RemoveFileIfExist
from install_lib import RemoveFileOrDirectoryIfExist

def BundleStatic(colab_root, dest):
# prepare the destination directory
Expand Down
54 changes: 54 additions & 0 deletions colaboratory/resources/colab/js/colab.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file was autogenerated by calcdeps.py
goog.addDependency("../colab/js/api_wrapper.js", ['colab.drive.ApiWrapper'], ['colab.app', 'colab.client_id', 'colab.error.GapiError', 'colab.params', 'colab.scope', 'goog.Promise', 'goog.events', 'goog.ui.Dialog']);
goog.addDependency("../colab/js/app.js", ['colab.app'], ['colab.notification', 'colab.params', 'goog.Promise']);
goog.addDependency("../colab/js/bottompane.js", ['colab.BottomPane'], ['colab.Global', 'goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.dom.ViewportSizeMonitor', 'goog.dom.classes', 'goog.events', 'goog.events.EventType', 'goog.fx.Dragger', 'goog.object', 'goog.style', 'goog.ui.Button', 'goog.ui.Component']);
goog.addDependency("../colab/js/client_id.js", ['colab.client_id', 'colab.scope'], []);
goog.addDependency("../colab/js/colabdeps.js", [], ['goog.Promise', 'goog.format.JsonPrettyPrinter', 'goog.fx.DragListGroup', 'goog.ui.Component', 'goog.ui.ToolbarButton']);
goog.addDependency("../colab/js/colabtools.js", [], []);
goog.addDependency("../colab/js/comments.js", ['colab.Comment', 'colab.CommentsWidget', 'colab.NewComment'], ['goog.date', 'goog.date.DateTime', 'goog.date.relative', 'goog.dom', 'goog.dom.forms', 'goog.style']);
goog.addDependency("../colab/js/deps.js", [], []);
goog.addDependency("../colab/js/dialog.js", ['colab.dialog'], ['goog.ui.Dialog']);
goog.addDependency("../colab/js/drive.js", ['colab.drive'], ['colab.drive.ApiWrapper', 'colab.error.GapiError', 'colab.nbformat', 'goog.array', 'goog.Uri']);
goog.addDependency("../colab/js/drive_externs.js", [], []);
goog.addDependency("../colab/js/drivehandler.js", [], ['colab.params']);
goog.addDependency("../colab/js/error.js", ['colab.Error', 'colab.ErrorEvent', 'colab.error.GapiError', 'colab.error.GapiRealtimeError'], ['goog.debug.Error', 'goog.events.Event']);
goog.addDependency("../colab/js/externs.js", [], []);
goog.addDependency("../colab/js/filepicker.js", ['colab.filepicker'], ['colab.app']);
goog.addDependency("../colab/js/global.js", ['colab.Global'], []);
goog.addDependency("../colab/js/header.js", ['colab.header'], ['colab.Global', 'colab.app', 'colab.cell.CellType', 'colab.dialog', 'colab.filepicker', 'colab.model.Notebook', 'colab.nbformat', 'colab.notification', 'colab.params', 'colab.share', 'goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.dom.classes', 'goog.events', 'goog.style', 'goog.ui.Component', 'goog.ui.Menu', 'goog.ui.MenuBarRenderer', 'goog.ui.MenuItem', 'goog.ui.Option', 'goog.ui.SelectionModel', 'goog.ui.Separator', 'goog.ui.Toolbar', 'goog.ui.ToolbarButton', 'goog.ui.ToolbarMenuButton', 'goog.ui.ToolbarRenderer', 'goog.ui.ToolbarSelect', 'goog.ui.ToolbarSeparator', 'goog.ui.ToolbarToggleButton', 'goog.ui.menuBar', 'goog.ui.menuBarDecorator']);
goog.addDependency("../colab/js/install.js", ['colab.install'], ['colab.client_id', 'colab.scope']);
goog.addDependency("../colab/js/interactive_widgets.js", [], []);
goog.addDependency("../colab/js/main.js", ['colab'], ['colab.Global', 'colab.Notebook', 'colab.PNaClKernel', 'colab.Preferences', 'colab.app', 'colab.dialog', 'colab.drive', 'colab.drive.ApiWrapper', 'colab.model.Notebook', 'colab.notification', 'colab.params', 'colab.presence', 'colab.services', 'colab.sharing.SharingState', 'goog.array', 'goog.dom', 'goog.events', 'goog.net.cookies', 'goog.style', 'goog.ui.Dialog', 'goog.ui.ScrollFloater']);
goog.addDependency("../colab/js/nbformat.js", ['colab.nbformat'], ['goog.format.JsonPrettyPrinter']);
goog.addDependency("../colab/js/notebook.js", ['colab.CellDragger', 'colab.KeyboardShortcut', 'colab.Notebook'], ['colab.BottomPane', 'colab.CommentsWidget', 'colab.Global', 'colab.Undo', 'colab.cell.AddCell', 'colab.cell.AddCellEventType', 'colab.cell.Cell', 'colab.cell.CellType', 'colab.cell.factory', 'colab.dialog', 'colab.filepicker', 'colab.header', 'colab.notification', 'goog.array', 'goog.dom', 'goog.dom.classlist', 'goog.events', 'goog.events.KeyCodes', 'goog.events.KeyHandler', 'goog.fx.DragListDirection', 'goog.fx.DragListGroup', 'goog.fx.Dragger', 'goog.fx.Transition', 'goog.fx.dom.FadeInAndShow', 'goog.fx.dom.FadeOutAndHide', 'goog.style', 'goog.ui.Component', 'goog.ui.Dialog']);
goog.addDependency("../colab/js/notification.js", ['colab.Notification', 'colab.notification'], ['goog.dom', 'goog.dom.classes', 'goog.style']);
goog.addDependency("../colab/js/params.js", ['colab.params'], []);
goog.addDependency("../colab/js/picker_externs.js", [], []);
goog.addDependency("../colab/js/pnacl_kernel.js", ['colab.PNaClKernel'], ['colab.app']);
goog.addDependency("../colab/js/presence.js", ['colab.presence'], ['colab.Global', 'goog.array', 'goog.dom']);
goog.addDependency("../colab/js/services.js", ['colab.services'], ['colab.Global', 'goog.events', 'goog.ui.Dialog']);
goog.addDependency("../colab/js/shadow.js", ['colab.Shadow'], ['goog.dom']);
goog.addDependency("../colab/js/share.js", ['colab.share'], ['colab.drive']);
goog.addDependency("../colab/js/svgbutton.js", ['colab.SvgButton'], ['goog.dom', 'goog.events', 'goog.events.EventType', 'goog.ui.ToolbarButton']);
goog.addDependency("../colab/js/undo.js", ['colab.Undo'], []);
goog.addDependency("../colab/js/v1_closure.js", ['test'], ['goog.crypt.base64']);
goog.addDependency("../colab/js/welcome.js", ['colab.welcome'], ['colab.filepicker', 'colab.install', 'colab.params', 'goog.dom', 'goog.dom.classes', 'goog.dom.forms', 'goog.style']);
goog.addDependency("../colab/js/cell/addcell.js", ['colab.cell.AddCell', 'colab.cell.AddCellEventType'], ['colab.Shadow', 'goog.dom', 'goog.events', 'goog.style', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/cell.js", ['colab.cell.Cell', 'colab.cell.CellType'], ['colab.Global', 'colab.Shadow', 'colab.SvgButton', 'colab.cell.AddCell', 'colab.presence', 'goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.dom.classlist', 'goog.events', 'goog.events.EventType', 'goog.style', 'goog.ui.Component', 'goog.ui.Container', 'goog.ui.MenuItem', 'goog.ui.Toolbar', 'goog.ui.ToolbarButton', 'goog.ui.ToolbarMenuButton']);
goog.addDependency("../colab/js/cell/cellfactory.js", ['colab.cell.factory'], ['colab.cell.CellType', 'colab.cell.CodeCell', 'colab.cell.TextCell']);
goog.addDependency("../colab/js/cell/codecell.js", ['colab.cell.CodeCell'], ['colab.Global', 'colab.cell.Cell', 'colab.cell.Editor', 'colab.cell.FormView', 'colab.cell.OutputArea', 'colab.notification', 'colab.services', 'goog.array', 'goog.date.DateTime', 'goog.dom', 'goog.dom.TagName', 'goog.dom.classlist', 'goog.events', 'goog.object', 'goog.style', 'goog.ui.Component', 'goog.ui.MenuItem', 'goog.ui.Prompt', 'goog.ui.ToolbarButton', 'goog.ui.ToolbarSelect']);
goog.addDependency("../colab/js/cell/combowidget.js", ['colab.cell.ComboBoxFormWidget', 'colab.cell.ComboBoxParams'], ['goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.string', 'goog.ui.ComboBox', 'goog.ui.Component', 'goog.ui.MenuItem']);
goog.addDependency("../colab/js/cell/editor.js", ['colab.cell.Editor'], ['colab.Global', 'colab.notification', 'colab.sharing', 'colab.tooltip.Tooltip', 'goog.dom', 'goog.dom.classlist', 'goog.events.BrowserEvent', 'goog.events.EventType', 'goog.style', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/formview.js", ['colab.cell.FormView', 'colab.cell.FormsParams'], ['colab.cell.ComboBoxFormWidget', 'colab.cell.SliderFormWidget', 'colab.cell.TextFieldFormWidget', 'colab.cell.TitleFormWidget', 'goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.dom.classes', 'goog.style', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/formview_test.js", ['colab.testing.FormViewTest'], ['colab.cell.FormView', 'goog.testing.jsunit']);
goog.addDependency("../colab/js/cell/outputarea.js", ['colab.cell.OutputArea'], ['colab.Global', 'colab.params', 'goog.date.DateTime', 'goog.dom', 'goog.events', 'goog.events.EventType', 'goog.string', 'goog.style', 'goog.ui.Zippy', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/outputframe.js", [], []);
goog.addDependency("../colab/js/cell/sliderwidget.js", ['colab.cell.SliderFormWidget', 'colab.cell.SliderParams'], ['goog.dom', 'goog.dom.TagName', 'goog.string', 'goog.ui.Component', 'goog.ui.Slider']);
goog.addDependency("../colab/js/cell/textcell.js", ['colab.cell.TextCell'], ['colab.cell.Cell', 'colab.cell.Editor', 'goog.dom', 'goog.dom.classlist', 'goog.events.EventType']);
goog.addDependency("../colab/js/cell/textfieldwidget.js", ['colab.cell.TextFieldFormWidget'], ['goog.dom', 'goog.dom.TagName', 'goog.events.EventType', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/titlewidget.js", ['colab.cell.TitleFormWidget', 'colab.cell.TitleParams'], ['goog.array', 'goog.dom', 'goog.dom.TagName', 'goog.style', 'goog.ui.Button', 'goog.ui.Component']);
goog.addDependency("../colab/js/cell/tooltip.js", ['colab.tooltip.Tooltip'], ['goog.dom', 'goog.ui.Tooltip']);
goog.addDependency("../colab/js/model/notebook.js", ['colab.model.Notebook'], ['colab.ErrorEvent', 'colab.app', 'colab.drive', 'colab.drive.ApiWrapper', 'colab.drive.Permissions', 'colab.error.GapiError', 'colab.error.GapiRealtimeError', 'colab.nbformat', 'colab.notification', 'goog.dom', 'goog.events.Event', 'goog.events.EventTarget']);
goog.addDependency("../colab/js/model/permissions.js", ['colab.drive.Permissions'], []);
goog.addDependency("../colab/js/model/preferences.js", ['colab.Preferences'], ['goog.net.cookies']);
goog.addDependency("../colab/js/model/sharingstate.js", ['colab.sharing', 'colab.sharing.SharingState'], ['colab.drive', 'colab.drive.ApiWrapper', 'goog.array', 'goog.events.EventTarget']);
1 change: 1 addition & 0 deletions colaboratory/resources/colab/js/welcome.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
goog.provide('colab.welcome');

goog.require('colab.filepicker');
goog.require('colab.install');
Expand Down
45 changes: 4 additions & 41 deletions colaboratory/resources/colab/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,10 @@
charset="utf-8">
</script>

<script src="/colab/js/colabdeps.js"></script>
<script src="/colab/js/client_id.js"></script>
<script src="/colab/js/model/preferences.js"></script>
<script src="/colab/js/notification.js"></script>
<script src="/colab/js/params.js"></script>
<script src="/colab/js/global.js"></script>
<script src="/colab/js/undo.js"></script>
<script src="/colab/js/dialog.js"></script>
<script src="/colab/js/error.js"></script>
<script src="/colab/js/app.js"></script>
<script src="/colab/js/pnacl_kernel.js"></script>
<script src="/colab/js/nbformat.js"></script>
<script src="/colab/js/api_wrapper.js"></script>
<script src="/colab/js/filepicker.js"></script>
<script src="/colab/js/model/permissions.js"></script>
<script src="/colab/js/drive.js"></script>
<script src="/colab/js/model/notebook.js"></script>
<script src="/colab/js/shadow.js"></script>
<script src="/colab/js/share.js"></script>
<script src="/colab/js/model/sharingstate.js"></script>
<script src="/colab/js/services.js"></script>
<script src="/colab/js/svgbutton.js"></script>
<script src="/colab/js/presence.js"></script>
<script src="/colab/js/cell/addcell.js"></script>
<script src="/colab/js/cell/cell.js"></script>
<script src="/colab/js/cell/tooltip.js"></script>
<script src="/colab/js/cell/editor.js"></script>
<script src="/colab/js/cell/sliderwidget.js"></script>
<script src="/colab/js/cell/textfieldwidget.js"></script>
<script src="/colab/js/cell/combowidget.js"></script>
<script src="/colab/js/cell/titlewidget.js"></script>
<script src="/colab/js/cell/formview.js"></script>
<script src="/colab/js/cell/outputarea.js"></script>
<script src="/colab/js/cell/codecell.js"></script>
<script src="/colab/js/cell/textcell.js"></script>
<script src="/colab/js/cell/cellfactory.js"></script>
<script src="/colab/js/comments.js"></script>
<script src="/colab/js/bottompane.js"></script>
<script src="/colab/js/header.js"></script>
<script src="/colab/js/notebook.js"></script>
<script src="/colab/js/main.js"></script>
<script type="text/javascript" src="/colab/js/colab.dep"></script>
<script type="text/javascript">
goog.require('colab');
</script>

<!-- Load the Markdown libraries. -->
<script type="text/javascript" src="/extern/pagedown/Markdown.Converter.js"></script><style type="text/css"></style>
Expand Down
12 changes: 4 additions & 8 deletions colaboratory/resources/colab/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
<!-- Fav icon -->
<link rel="shortcut icon" href="/colab/img/colab-black.png">

<script src="/colab/js/colabdeps.js"></script>
<script src="/colab/js/client_id.js"></script>
<script src="/colab/js/params.js"></script>
<script src="/colab/js/notification.js"></script>
<script src="/colab/js/app.js"></script>
<script src="/colab/js/filepicker.js"></script>
<script src="/colab/js/install.js"></script>
<script src="/colab/js/welcome.js"></script>
<script type="text/javascript" src="/colab/js/colab.dep"></script>
<script type="text/javascript">
goog.require('colab.welcome');
</script>

<link rel="stylesheet" href="/closure/css/common.css">
<link rel="stylesheet" href="/colab/css/header.css"/>
Expand Down
10 changes: 9 additions & 1 deletion install_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
import shutil
import subprocess
import sys
import urllib

import IPython.html

from bundle_static import *
from bundle_static import BundleStatic
from install_lib import COLAB_ROOT_PATH
from install_lib import pjoin
from install_lib import CopyTreeRecursively
from install_lib import MakeDirectoryIfNotExist
from install_lib import RemoveDirectoryIfExist
from install_lib import RemoveFileIfExist
from install_lib import RemoveFileOrDirectoryIfExist

parser = argparse.ArgumentParser(description='Installs the Chrome App.')
parser.add_argument('--release',
Expand Down
49 changes: 49 additions & 0 deletions install_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import errno
import os
import shutil

COLAB_ROOT_PATH = os.path.dirname(os.path.realpath(__file__))

pjoin = os.path.join

def MakeDirectoryIfNotExist(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise

def RemoveDirectoryIfExist(path):
try:
shutil.rmtree(path)
except OSError as exception:
if exception.errno != errno.ENOENT:
raise

def RemoveFileIfExist(path):
try:
os.remove(path)
except OSError as exception:
if exception.errno != errno.ENOENT:
raise

def RemoveFileOrDirectoryIfExist(path):
try:
RemoveDirectoryIfExist(path)
except OSError as exception:
if exception.errno == errno.ENOTDIR:
RemoveFileIfExist(path)
else:
raise


def CopyTreeRecursively(src, dest):
"""Roughly equivalent to cp -r src/* dest"""
MakeDirectoryIfNotExist(dest)
for entry in os.listdir(src):
s = pjoin(src, entry)
d = pjoin(dest, entry)
if os.path.isdir(s):
CopyTreeRecursively(s, d)
else:
shutil.copy(s, d)

0 comments on commit 1425c6e

Please sign in to comment.