From e01c60aa80362edae82b7faf9d70af42f79eb8aa Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 23 Jan 2019 16:20:03 +0300 Subject: [PATCH 1/5] #44 Display build information --- Makefile | 26 ++++++++++++++++++++++++++ main.go | 2 +- repl/cli/cli.go | 9 ++++++--- version.go | 7 +++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 Makefile create mode 100644 version.go diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..05aba708 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# This how we want to name the binary output +BINARY=gpython + +# These are the values we want to pass for VERSION and BUILD +# git tag 1.0.1 +# git commit -am "One more change after the tags" +VERSION=`git describe --abbrev=0 --tags` +DATE=`date +%FT%T%z` +COMMIT=`git rev-parse --verify HEAD` + +# Setup the -ldflags option for go build here, interpolate the variable values +LDFLAGS=-ldflags "-w -s -X main.version=${VERSION} -X main.date=${DATE} -X main.commit=${COMMIT}" + +# Builds the project +build: + go build ${LDFLAGS} -o ${BINARY} + +# Installs our project: copies binaries +install: + go install ${LDFLAGS} + +# Cleans our project: deletes binaries +clean: + if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi + +.PHONY: clean install diff --git a/main.go b/main.go index 06cba663..d2b86020 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func main() { args := flag.Args() py.MustGetModule("sys").Globals["argv"] = pysys.MakeArgv(args) if len(args) == 0 { - cli.RunREPL() + cli.RunREPL(version, commit, date) return } prog := args[0] diff --git a/repl/cli/cli.go b/repl/cli/cli.go index 1affc2c5..84d7d186 100644 --- a/repl/cli/cli.go +++ b/repl/cli/cli.go @@ -11,6 +11,7 @@ import ( "os" "os/user" "path/filepath" + "runtime" "github.com/go-python/gpython/py" "github.com/go-python/gpython/repl" @@ -119,7 +120,7 @@ func (rl *readline) Print(out string) { } // RunREPL starts the REPL loop -func RunREPL() { +func RunREPL(version, commit, date string) { repl := repl.New() rl := newReadline(repl) repl.SetUI(rl) @@ -129,8 +130,10 @@ func RunREPL() { fmt.Printf("Failed to open history: %v\n", err) } - fmt.Printf("Gpython 3.4.0\n") - + fmt.Printf("Python 3.4.0 (%s, %s)\n", commit, date) + fmt.Printf("[Gpython %s]\n", version) + fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + fmt.Printf("- go version: %s\n", runtime.Version()) for { line, err := rl.Prompt(rl.prompt) if err != nil { diff --git a/version.go b/version.go new file mode 100644 index 00000000..9e849145 --- /dev/null +++ b/version.go @@ -0,0 +1,7 @@ +package main + +var ( + version = "dev" + commit = "none" + date = "unknown" +) \ No newline at end of file From fbb5a6a6f365e55d7c675d0d7d60b70045518c2c Mon Sep 17 00:00:00 2001 From: Artem Date: Thu, 24 Jan 2019 13:58:37 +0300 Subject: [PATCH 2/5] #44 Display build information (makefile was deleted) --- Makefile | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 05aba708..00000000 --- a/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# This how we want to name the binary output -BINARY=gpython - -# These are the values we want to pass for VERSION and BUILD -# git tag 1.0.1 -# git commit -am "One more change after the tags" -VERSION=`git describe --abbrev=0 --tags` -DATE=`date +%FT%T%z` -COMMIT=`git rev-parse --verify HEAD` - -# Setup the -ldflags option for go build here, interpolate the variable values -LDFLAGS=-ldflags "-w -s -X main.version=${VERSION} -X main.date=${DATE} -X main.commit=${COMMIT}" - -# Builds the project -build: - go build ${LDFLAGS} -o ${BINARY} - -# Installs our project: copies binaries -install: - go install ${LDFLAGS} - -# Cleans our project: deletes binaries -clean: - if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi - -.PHONY: clean install From 940ec220454eae5888a93a6a9f807debcc482c02 Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 2 Mar 2019 14:59:20 +0300 Subject: [PATCH 3/5] #44 copyright header was added --- version.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/version.go b/version.go index 9e849145..857ae35d 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,7 @@ +// Copyright 2018 The go-python Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main var ( From 13a7387ba3081e20d4b5715548e7cdc87c9cbd0e Mon Sep 17 00:00:00 2001 From: Artem Date: Sun, 3 Mar 2019 03:06:30 +0300 Subject: [PATCH 4/5] #44 move out print from cli.go --- main.go | 9 ++++++++- repl/cli/cli.go | 14 ++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index d2b86020..8148056b 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ package main import ( "flag" "fmt" + "runtime" "runtime/pprof" _ "github.com/go-python/gpython/builtin" @@ -63,7 +64,13 @@ func main() { args := flag.Args() py.MustGetModule("sys").Globals["argv"] = pysys.MakeArgv(args) if len(args) == 0 { - cli.RunREPL(version, commit, date) + + fmt.Printf("Python 3.4.0 (%s, %s)\n", commit, date) + fmt.Printf("[Gpython %s]\n", version) + fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + fmt.Printf("- go version: %s\n", runtime.Version()) + + cli.RunREPL() return } prog := args[0] diff --git a/repl/cli/cli.go b/repl/cli/cli.go index 84d7d186..c33d315f 100644 --- a/repl/cli/cli.go +++ b/repl/cli/cli.go @@ -7,15 +7,13 @@ package cli import ( "fmt" + "github.com/go-python/gpython/py" + "github.com/go-python/gpython/repl" + "github.com/peterh/liner" "io" "os" "os/user" "path/filepath" - "runtime" - - "github.com/go-python/gpython/py" - "github.com/go-python/gpython/repl" - "github.com/peterh/liner" ) const HistoryFileName = ".gpyhistory" @@ -120,7 +118,7 @@ func (rl *readline) Print(out string) { } // RunREPL starts the REPL loop -func RunREPL(version, commit, date string) { +func RunREPL() { repl := repl.New() rl := newReadline(repl) repl.SetUI(rl) @@ -130,10 +128,6 @@ func RunREPL(version, commit, date string) { fmt.Printf("Failed to open history: %v\n", err) } - fmt.Printf("Python 3.4.0 (%s, %s)\n", commit, date) - fmt.Printf("[Gpython %s]\n", version) - fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) - fmt.Printf("- go version: %s\n", runtime.Version()) for { line, err := rl.Prompt(rl.prompt) if err != nil { From 86379dee98f630695ba1916b4ba404a04b93e3f6 Mon Sep 17 00:00:00 2001 From: Artem Date: Sun, 3 Mar 2019 05:03:38 +0300 Subject: [PATCH 5/5] #44 import order in cli.go --- repl/cli/cli.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/repl/cli/cli.go b/repl/cli/cli.go index c33d315f..f7618ea9 100644 --- a/repl/cli/cli.go +++ b/repl/cli/cli.go @@ -7,13 +7,14 @@ package cli import ( "fmt" - "github.com/go-python/gpython/py" - "github.com/go-python/gpython/repl" - "github.com/peterh/liner" "io" "os" "os/user" "path/filepath" + + "github.com/go-python/gpython/py" + "github.com/go-python/gpython/repl" + "github.com/peterh/liner" ) const HistoryFileName = ".gpyhistory"