Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit c9311c0

Browse files
authored
Fix README build instructions (#367)
1 parent 41b1431 commit c9311c0

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ TOOL_BINS = $(patsubst %,build/bin/%,benchcmp coverparse diffrange genmake pydep
131131
GOLINT_BIN = build/bin/golint
132132
PYLINT_BIN = build/bin/pylint
133133

134-
all: $(COMPILER) $(RUNTIME) $(TOOL_BINS)
134+
all: $(COMPILER) $(RUNNER) $(RUNTIME) $(TOOL_BINS)
135135

136136
benchmarks: $(BENCHMARK_BINS)
137137

README.md

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ There are three basic categories of incomplete functionality:
5656

5757
## Running Grumpy Programs
5858

59-
### Method 1: grumprun:
59+
### Method 1: make run:
6060

6161
The simplest way to execute a Grumpy program is to use `make run`, which wraps a
6262
shell script called grumprun that takes Python code on stdin and builds and runs
@@ -67,33 +67,62 @@ root directory of the Grumpy source code distribution:
6767
echo "print 'hello, world'" | make run
6868
```
6969

70-
### Method 2: grumpc:
70+
### Method 2: grumpc and grumprun:
7171

7272
For more complicated programs, you'll want to compile your Python source code to
7373
Go using grumpc (the Grumpy compiler) and then build the Go code using `go
74-
build`. First, write a simple .py script:
74+
build`. Since Grumpy programs are statically linked, all the modules in a
75+
program must be findable by the Grumpy toolchain on the GOPATH. Grumpy looks for
76+
Go packages corresponding to Python modules in the \_\_python\_\_ subdirectory
77+
of the GOPATH. By convention, this subdirectory is also used for staging Python
78+
source code, making it similar to the PYTHONPATH.
7579

76-
```
77-
echo 'print "hello, world"' > hello.py
78-
```
79-
80-
Next, build the toolchain and export some environment variables that make the
81-
toolchain work:
80+
The first step is to set up the shell so that the Grumpy toolchain and libraries
81+
can be found. From the root directory of the Grumpy source distribution run:
8282

8383
```
8484
make
85+
export PATH=$PWD/build/bin:$PATH
8586
export GOPATH=$PWD/build
8687
export PYTHONPATH=$PWD/build/lib/python2.7/site-packages
8788
```
8889

89-
Finally, compile the Python script and build a binary from it:
90+
You will know things are working if you see the expected output from this
91+
command:
92+
93+
```
94+
echo 'import sys; print sys.version' | grumprun
95+
```
96+
97+
Next, we will write our simple Python module into the \_\_python\_\_ directory:
98+
99+
```
100+
echo 'def hello(): print "hello, world"' > $GOPATH/src/__python__/hello.py
101+
```
102+
103+
To build a Go package from our Python script, run the following:
104+
105+
```
106+
mkdir -p $GOPATH/src/__python__/hello
107+
grumpc -modname=hello $GOPATH/src/__python__/hello.py > \
108+
$GOPATH/src/__python__/hello/module.go
109+
```
110+
111+
You should now be able to build a Go program that imports the package
112+
"\_\_python\_\_/hello". We can also import this module into Python programs
113+
that are built using grumprun:
90114

91115
```
92-
build/bin/grumpc hello.py > hello.go
93-
go build -o hello hello.go
116+
echo 'from hello import hello; hello()' | grumprun
94117
```
95118

96-
Now execute the `./hello` binary to your heart's content.
119+
grumprun is doing a few things under the hood here:
120+
121+
1. Compiles the given Python code to a dummy Go package, the same way we
122+
produced \_\_python\_\_/hello/module.go above
123+
2. Produces a main Go package that imports the Go package from step 1. and
124+
executes it as our \_\_main\_\_ Python package
125+
3. Executes `go run` on the main package generated in step 2.
97126

98127
## Developing Grumpy
99128

0 commit comments

Comments
 (0)