Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.build
/Packages
/Package.resolved
/*.xcodeproj
.ipynb_checkpoints
29 changes: 25 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
FROM jupyter/minimal-notebook:latest
FROM jupyter/minimal-notebook:1af3089901bb
#FROM jupyter/tensorflow-notebook:1af3089901bb

USER root

# Set WORKDIR
WORKDIR /root

# These apt-get packages are the only unpinned dependencies, so they are presumably
# the only elements in the image build process that introduce the risk of
# non-reproducibility. That is, they could in theory change in a way that
# broke backward compatibility, and caused subsequent builds of the docker image
# to function differently.

# Install related packages and set LLVM 3.8 as the compiler
RUN apt-get -q update && \
apt-get -q install -y \
Expand Down Expand Up @@ -77,13 +84,27 @@ RUN cd /tmp/ \
&& make install \
&& ldconfig

RUN mkdir -p /kernels
COPY . /kernels/iSwift
# Build swift kernel executable as root in /kernels/iSwift
RUN mkdir -p /kernels/iSwift
# copy only the Swift package itself and iSwiftKernel, so that we don't
# trigger image rebuilds when we edit docs or pieces of the Dockerfile
# itself which are irrelevant to the image
COPY Includes /kernels/iSwift/Includes/
COPY Package.swift /kernels/iSwift/
COPY Sources iSwiftKernel /kernels/iSwift/Sources/
COPY iSwiftKernel /kernels/iSwift/iSwiftKernel/
WORKDIR /kernels/iSwift
RUN swift package update
RUN swift build
RUN jupyter kernelspec install iSwiftKernel

# But install the kernelspec into jupyter as the NB_USER
USER ${NB_USER}
RUN jupyter kernelspec install --user /kernels/iSwift/iSwiftKernel

# Change the Swift kernel executable to be onwed by NB_USER, so we can run it
USER root
RUN chown -R ${NB_USER} /kernels/iSwift
USER $NB_USER

USER ${NB_USER}
WORKDIR /home/${NB_USER}
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,31 @@ This project is based off [KelvinJin/iSwift](https://github.com/KelvinJin/iSwift
+ Updates to support Swift 4.1
+ Base the docker image off jupyter/minimal-notebook

Note: This is rough work-in-progress. What you're looking at is
unlikely to be the latest and greatest. I'd suggest checking the
[Swift for TensorFlow google
group](https://groups.google.com/a/tensorflow.org/forum/?utm_source=digest&utm_medium=email/#!topic/swift/5fr5h1SWzzE),
and the [fork tree](https://github.com/KelvinJin/iSwift/network) from
KelvinJin's original verison, to understand what is the best version of this.

## Quick Start

The preferred way of using this is via the [docker image](https://hub.docker.com/r/rayh/swift-notebook/), either locally or in jupyterhub/binderhub
The easiest way of using this is via the [docker image](https://hub.docker.com/r/algalgal/swift-notebook/), which is already built and hosted on docker hub. Assuming you have docker installed on your machine, all you need to do is run:

```bash
$ docker run -t -i -p 8888:8888 --privileged rayh/swift-notebook
$ docker run -t -i -p 8888:8888 --privileged algalgal/swift-notebook:b767ba373ced
```

And open the link you see in the console, which will start Jupyter, from there you can select `New` -> `Swift`
This will download the image if needed, and then run it, starting Jupyter. (FYI, this runs an image based roughly on the github repo commit `6a08a20`.)

## Demo
Then copy and paste the URL from the console into your browser to access the notebook. From there you can select `New` -> `Swift`.

You can demo a version of this on binderhub here:
To build and run images locally, you can use the helper scripts `build-jupyter-swift-notebook.sh` and `run-jupyter-swift-notebook.sh`.

## Requirements

These are requirement if you do not want to use docker:

+ macOS/Linux
+ Swift 4.1
+ ZMQ
Expand Down
16 changes: 9 additions & 7 deletions Sources/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ struct Regex {


extension String {

/// NSRange of the full string.
private var fullRange: NSRange {
return NSRange(self.startIndex..<self.endIndex, in: self)
}

func matchRegex(_ pattern: Regex) -> Bool {
let range: NSRange = NSMakeRange(0, utf8.count)
if let regex = pattern.regex {
let matches = regex.matches(in: self, options: pattern.matchingOptions, range: range)
let matches = regex.matches(in: self, options: pattern.matchingOptions, range: self.fullRange)
return matches.count > 0
}
return false
Expand All @@ -53,11 +58,8 @@ extension String {
}

func replaceRegex(_ pattern: Regex, template: String) -> String {
if self.matchRegex(pattern) {
let range: NSRange = NSMakeRange(0, utf8.count)
if let regex = pattern.regex {
return regex.stringByReplacingMatches(in: self, options: pattern.matchingOptions, range: range, withTemplate: template)
}
if self.matchRegex(pattern), let regex = pattern.regex {
return regex.stringByReplacingMatches(in: self, options: pattern.matchingOptions, range: self.fullRange, withTemplate: template)
}
return self
}
Expand Down
2 changes: 2 additions & 0 deletions build-jupyter-swift-notebook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec docker build -t algalgal/swift-notebook .
2 changes: 2 additions & 0 deletions run-jupyter-swift-notebook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec docker run --rm --privileged -p 8888:8888 algalgal/swift-notebook
24 changes: 24 additions & 0 deletions worklog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# TODO

## Segregate Swift project dir from the repo root

This will stop the build process from mistakenly capturing all changes
in this repo

## Integrate tensorflow

Plan:

1. base Dockerfile on tensorflow-notebook
2. Use instructions at
https://github.com/tensorflow/swift/blob/master/Installation.md to
grab swift-tensorflow instead of plain old swift
3. etc

# Log

## 2018-05-01T0609 packaging for dockerhub