Skip to content

Commit 4ecdd93

Browse files
committed
fix printing cleanup
1 parent f0cb59c commit 4ecdd93

File tree

3 files changed

+65
-25
lines changed

3 files changed

+65
-25
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
FROM continuumio/anaconda
1+
FROM golang
22

33
# dependencies
44
RUN apt-get update
5-
RUN apt-get install -y pkg-config libzmq-dev build-essential
5+
RUN apt-get install -y pkg-config libzmq3-dev build-essential python3-pip
66

77
# set up golang
8-
RUN wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
9-
RUN tar -C /usr/local -xzf go1.5.linux-amd64.tar.gz
108
ENV PATH /usr/local/go/bin:$PATH
119
ENV GOPATH /go
1210
ENV PATH $GOPATH/bin:$PATH
1311
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
1412

1513
# install gophernotes
1614
RUN go get golang.org/x/tools/cmd/goimports
17-
RUN go get github.com/gopherds/gophernotes
15+
RUN go get -tags zmq_3_x github.com/gopherds/gophernotes
1816
RUN mkdir -p ~/.ipython/kernels/gophernotes
1917
RUN cp -r $GOPATH/src/github.com/gopherds/gophernotes/kernel/* ~/.ipython/kernels/gophernotes
2018

19+
# install jupyter
20+
RUN pip3 install jupyter
21+
2122
EXPOSE 8888
2223
CMD ["jupyter", "notebook"]

internal/repl/quickfix.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ func (s *Session) isPureExpr(expr ast.Expr) bool {
204204
case *ast.CallExpr:
205205
tv := s.TypeInfo.Types[expr.Fun]
206206

207-
for _, arg := range expr.Args {
208-
if s.isPureExpr(arg) == false {
209-
return false
210-
}
211-
}
207+
//for _, arg := range expr.Args {
208+
// if s.isPureExpr(arg) == false {
209+
// return false
210+
// }
211+
//}
212212

213213
if tv.IsType() {
214214
return true

internal/repl/repl.go

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ func (s *Session) Eval(in string) (string, bytes.Buffer, error) {
384384
}
385385

386386
// Extract statements.
387+
priorListLength := len(s.mainBody.List)
387388
if err := s.separateEvalStmt(in); err != nil {
388389
return "", bytes.Buffer{}, err
389390
}
@@ -404,39 +405,77 @@ func (s *Session) Eval(in string) (string, bytes.Buffer, error) {
404405
errorf("%s", err)
405406
}
406407

408+
// Cleanup the session file.
409+
s.mainBody.List = s.mainBody.List[0:priorListLength]
410+
if err := s.cleanEvalStmt(in); err != nil {
411+
return "", bytes.Buffer{}, err
412+
}
413+
f, err := os.Create(s.FilePath)
414+
if err != nil {
415+
return "", bytes.Buffer{}, err
416+
}
417+
err = printer.Fprint(f, s.Fset, s.File)
418+
if err != nil {
419+
return "", bytes.Buffer{}, err
420+
}
421+
407422
return string(output), strerr, err
408423
}
409424

410425
// separateEvalStmt separates what can be evaluated via evalExpr from what cannot.
411426
func (s *Session) separateEvalStmt(in string) error {
412427
var stmtLines []string
413428
var exprCount int
429+
var bracketCount int
414430

415431
inLines := strings.Split(in, "\n")
416432

417433
for _, line := range inLines {
418434

419-
priorLen := len(s.mainBody.List)
420-
421-
if _, err := s.evalExpr(line); err != nil {
422-
stmtLines = append(stmtLines, line)
435+
if bracketCount == 0 {
436+
if _, err := s.evalExpr(line); err != nil {
437+
if strings.LastIndex(line, "{") == len(line)-1 {
438+
bracketCount++
439+
}
440+
stmtLines = append(stmtLines, line)
441+
continue
442+
}
423443
continue
424444
}
425445

426-
if len(stmtLines) != 0 {
446+
if strings.LastIndex(line, "}") == len(line)-1 {
447+
bracketCount--
448+
}
449+
stmtLines = append(stmtLines, line)
427450

428-
currentLen := len(s.mainBody.List)
429-
trimNum := currentLen - priorLen
430-
s.mainBody.List = s.mainBody.List[0 : currentLen-trimNum]
451+
exprCount++
452+
}
431453

432-
if err := s.evalStmt(strings.Join(stmtLines, "\n"), true); err != nil {
433-
return err
434-
}
435-
stmtLines = []string{}
454+
if len(stmtLines) != 0 {
455+
var noPrint bool
456+
if exprCount > 0 {
457+
noPrint = true
458+
}
459+
if err := s.evalStmt(strings.Join(stmtLines, "\n"), noPrint); err != nil {
460+
return err
461+
}
462+
}
436463

437-
if _, err := s.evalExpr(line); err != nil {
438-
return err
439-
}
464+
return nil
465+
}
466+
467+
// cleanEvalStmt cleans up prior print statements etc.
468+
func (s *Session) cleanEvalStmt(in string) error {
469+
var stmtLines []string
470+
var exprCount int
471+
472+
inLines := strings.Split(in, "\n")
473+
474+
for _, line := range inLines {
475+
476+
if _, err := s.evalExpr(line); err != nil {
477+
stmtLines = append(stmtLines, line)
478+
continue
440479
}
441480

442481
exprCount++

0 commit comments

Comments
 (0)