Skip to content

Commit fdcfd1f

Browse files
committed
Merge branch 'master' into builtin-filter
2 parents dc5c185 + 6fc336a commit fdcfd1f

File tree

335 files changed

+2382
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+2382
-740
lines changed

.bumpversion.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[bumpversion]
2+
current_version = 0.2.2
3+
commit = True
4+
tag = True
5+
6+
[bumpversion:file:grumpy-tools-src/setup.py]
7+
8+
[bumpversion:file:grumpy-tools-src/grumpy_tools/__init__.py]
9+
10+
[bumpversion:file:grumpy-runtime-src/setup.py]
11+
12+
[bumpversion:file:grumpy-runtime-src/grumpy_runtime/__init__.py]
13+

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@ build
22
errors.err
33
*.swp
44
*.pyc
5+
*.egg
6+
.eggs/
7+
8+
grumpy-tools-src/dist/
9+
grumpy-tools-src/*.egg-info
10+
grumpy-runtime-src/dist
11+
grumpy-runtime-src/*.egg-info
12+
13+
# Cache
14+
.pytest_cache/
15+
16+
# Editors
17+
.vscode/
18+

.gitlab-ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
image: golang:1.10.3-stretch
2+
3+
cache:
4+
paths:
5+
- /apt-cache
6+
- /go/src/github.com
7+
- /go/src/golang.org
8+
- /go/src/google.golang.org
9+
- /go/src/gopkg.in
10+
11+
stages:
12+
- test
13+
- build
14+
15+
before_script:
16+
- apt-get update && apt-get install -y --no-install-recommends python2.7 python2.7-dev python-setuptools
17+
- easy_install pip
18+
- pip2 install pytest pytest-cov
19+
20+
install_and_test:
21+
stage: test
22+
script:
23+
# Install the thing
24+
- cd grumpy-tools-src
25+
- pip2 install .
26+
- cd ../grumpy-runtime-src
27+
- pip2 install .
28+
# Test the thing
29+
- cd ../grumpy-tools-src
30+
- pytest
31+
- cd ../grumpy-runtime-src
32+
- make gofmt lint && make -j2 test

.travis.yml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
1-
language: go
2-
os:
3-
- linux
4-
- osx
5-
# Run gofmt and lint serially to avoid confusing output. Run tests in parallel
6-
# for speed.
7-
script: make gofmt lint && make -j2 test
1+
language: python
2+
3+
cache:
4+
directories:
5+
- $HOME/.cache/pip
6+
- $HOME/.cache/pre-commit
7+
8+
matrix:
9+
allow_failures:
10+
- python: 3.6
11+
- env: GO="stable"
12+
include:
13+
- python: 2.7
14+
env: GO=1.10.x
15+
- python: 2.7
16+
env: GO=stable # Currently 1.11
17+
- python: 3.6
18+
env: GO=1.10.x
19+
script: # To detect Python 3 syntax errors in grumpy-tools
20+
- pip install --upgrade flake8
21+
- flake8 --count --select=E901,E999,F821,F822,F823 --show-source --statistics grumpy-tools-src
22+
- os: osx
23+
language: go
24+
go: 1.10.x
25+
env: OSX_PYTHON=2.7
26+
install: brew install python@2
27+
28+
install:
29+
- |
30+
export GOPATH=~/gopath
31+
export PATH="$GOPATH/bin:$PATH"
32+
export TRAVIS_BUILD_DIR="$GOPATH/src/github.com/$TRAVIS_REPO_SLUG"
33+
mkdir -p "$TRAVIS_BUILD_DIR"
34+
rsync -az . "$TRAVIS_BUILD_DIR"
35+
cd "$TRAVIS_BUILD_DIR"
36+
# Use the current gimme because Travis gimme does not support syntax "1.10.x" and "stable"
37+
eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=${GO} bash)"
38+
39+
before_script:
40+
- go version && python --version && python -m pip --version
41+
# https://github.com/travis-ci/travis-ci/issues/8920#issuecomment-352661024
42+
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"
43+
- pip install --upgrade pip
44+
- pip install pytest pytest-cov coverage
45+
46+
script:
47+
# Install the thing
48+
- cd grumpy-tools-src
49+
- pip install .
50+
- which grumpy
51+
- cd ../grumpy-runtime-src
52+
- pip install .
53+
# Test the thing
54+
# Run gofmt and lint serially to avoid confusing output. Run tests in parallel
55+
# for speed.
56+
- cd ../grumpy-tools-src
57+
- pytest
58+
- cd ../grumpy-runtime-src
59+
- make gofmt lint && make -j2 test
60+
61+
# OSX swallows error logs: https://github.com/travis-ci/travis-ci/issues/6018
62+
after_error:
63+
- echo "== End of test log ==""

README.md

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Grumpy: Go running Python
22

3-
[![Build Status](https://travis-ci.org/google/grumpy.svg?branch=master)](https://travis-ci.org/google/grumpy)
3+
[![Build Status](https://travis-ci.org/alanjds/grumpy.svg?branch=master)](https://travis-ci.org/alanjds/grumpy)
44
[![Join the chat at https://gitter.im/grumpy-devel/Lobby](https://badges.gitter.im/grumpy-devel/Lobby.svg)](https://gitter.im/grumpy-devel/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
55

66
## Overview
@@ -56,14 +56,34 @@ There are three basic categories of incomplete functionality:
5656

5757
## Running Grumpy Programs
5858

59+
### Pre-requisites
60+
61+
The commands ahead assumes that you have Golang installed and a recent
62+
version of Python 2, `setuptools` and `pip`.
63+
64+
### Method 1: binary package
65+
66+
For convenience, a Python package is provided from the PyPI. During install,
67+
many Grumpy will be compiled and stored inside your Python installation.
68+
69+
You need Golang preinstalled anyway for the installation to be successful.
70+
71+
```
72+
pip2 install -U grumpy-runtime -I --no-cache
73+
(wait about 5 minutes)
74+
echo "print 'hello, world'" | grumpy run
75+
```
76+
5977
### Method 1: make run:
6078

6179
The simplest way to execute a Grumpy program is to use `make run`, which wraps a
6280
shell script called grumprun that takes Python code on stdin and builds and runs
63-
the code under Grumpy. All of the commands below are assumed to be run from the
64-
root directory of the Grumpy source code distribution:
81+
the code under Grumpy:
6582

6683
```
84+
cd grumpy-tools-src
85+
python2 setup.py develop
86+
cd ../grumpy-runtime-src
6787
echo "print 'hello, world'" | make run
6888
```
6989

@@ -81,6 +101,9 @@ The first step is to set up the shell so that the Grumpy toolchain and libraries
81101
can be found. From the root directory of the Grumpy source distribution run:
82102

83103
```
104+
cd grumpy-tools-src
105+
python2 setup.py develop
106+
cd ../grumpy-runtime-src
84107
make
85108
export PATH=$PWD/build/bin:$PATH
86109
export GOPATH=$PWD/build
@@ -91,18 +114,21 @@ You will know things are working if you see the expected output from this
91114
command:
92115

93116
```
117+
cd grumpy-runtime-src
94118
echo 'import sys; print sys.version' | grumprun
95119
```
96120

97121
Next, we will write our simple Python module into the \_\_python\_\_ directory:
98122

99123
```
124+
cd grumpy-runtime-src
100125
echo 'def hello(): print "hello, world"' > $GOPATH/src/__python__/hello.py
101126
```
102127

103128
To build a Go package from our Python script, run the following:
104129

105130
```
131+
cd grumpy-runtime-src
106132
mkdir -p $GOPATH/src/__python__/hello
107133
grumpc -modname=hello $GOPATH/src/__python__/hello.py > \
108134
$GOPATH/src/__python__/hello/module.go
@@ -113,6 +139,7 @@ You should now be able to build a Go program that imports the package
113139
that are built using grumprun:
114140

115141
```
142+
cd grumpy-runtime-src
116143
echo 'from hello import hello; hello()' | grumprun
117144
```
118145

@@ -129,48 +156,50 @@ grumprun is doing a few things under the hood here:
129156
There are three main components and depending on what kind of feature you're
130157
writing, you may need to change one or more of these.
131158

132-
### grumpc
159+
### Grumpy Tools
133160

134-
Grumpy converts Python programs into Go programs and `grumpc` is the tool
135-
responsible for parsing Python code and generating Go code from it. `grumpc` is
136-
written in Python and uses the [`pythonparser`](https://github.com/m-labs/pythonparser)
161+
Grumpy converts Python programs into Go programs and
162+
`grumpy transpile` is the CLI tool responsible for parsing Python code
163+
and generating Go code from it. `grumpy transpile` is written in Python
164+
and uses the [`pythonparser`](https://github.com/m-labs/pythonparser)
137165
module to accomplish parsing.
138166

139-
The grumpc script itself lives at `tools/grumpc`. It is supported by a number of
140-
Python modules in the `compiler` subdir.
167+
The CLI main entrypoint lives at `grumpy-tools-src/grumpy_tools/cli.py`.
168+
It is supported by a number of Python modules in the
169+
`grumpy-tools-src/grumpy_tools/compiler` subdir.
141170

142171
### Grumpy Runtime
143172

144-
The Go code generated by `grumpc` performs operations on data structures that
145-
represent Python objects in running Grumpy programs. These data structures and
146-
operations are defined in the `grumpy` Go library (source is in the runtime
147-
subdir of the source distribution). This runtime is analogous to the Python C
148-
API and many of the structures and operations defined by `grumpy` have
149-
counterparts in CPython.
173+
The Go code generated by `grumpy transpile` performs operations
174+
on data structures that represent Python objects in running Grumpy programs.
175+
These data structures and operations are defined in the `grumpy` Go library
176+
(source is in the `grumpy-runtime-src/runtime` subdir of the source
177+
distribution). This runtime is analogous to the Python C API and many of the
178+
structures and operations defined by `grumpy` have counterparts in CPython.
150179

151180
### Grumpy Standard Library
152181

153182
Much of the Python standard library is written in Python and thus "just works"
154183
in Grumpy. These parts of the standard library are copied from CPython 2.7
155184
(possibly with light modifications). For licensing reasons, these files are kept
156-
in the `third_party` subdir.
185+
in the `grumpy-runtime-src/third_party` subdir.
157186

158187
The parts of the standard library that cannot be written in pure Python, e.g.
159-
file and directory operations, are kept in the `lib` subdir. In CPython these
160-
kinds of modules are written as C extensions. In Grumpy they are written in
161-
Python but they use native Go extensions to access facilities not otherwise
162-
available in Python.
188+
file and directory operations, are kept in the `grumpy-runtime-src/lib` subdir.
189+
In CPython these kinds of modules are written as C extensions. In Grumpy they
190+
are written in Python but they use native Go extensions to access facilities not
191+
otherwise available in Python.
163192

164193
### Source Code Overview
165194

166-
- `compiler`: Python package implementating Python -> Go transcompilation logic.
167-
- `lib`: Grumpy-specific Python standard library implementation.
168-
- `runtime`: Go source code for the Grumpy runtime library.
169-
- `third_party/ouroboros`: Pure Python standard libraries copied from the
195+
- `grumpy-tools-src/grumpy_tools/compiler`: Python package implementating Python -> Go transcompilation logic.
196+
- `grumpy-runtime-src/lib`: Grumpy-specific Python standard library implementation.
197+
- `grumpy-runtime-src/runtime`: Go source code for the Grumpy runtime library.
198+
- `grumpy-runtime-src/third_party/ouroboros`: Pure Python standard libraries copied from the
170199
[Ouroboros project](https://github.com/pybee/ouroboros).
171-
- `third_party/pypy`: Pure Python standard libraries copied from PyPy.
172-
- `third_party/stdlib`: Pure Python standard libraries copied from CPython.
173-
- `tools`: Transcompilation and utility binaries.
200+
- `grumpy-runtime-src/third_party/pypy`: Pure Python standard libraries copied from PyPy.
201+
- `grumpy-runtime-src/third_party/stdlib`: Pure Python standard libraries copied from CPython.
202+
- `grumpy-tools-src/grumpy_tools/`: Transcompilation and utility CLI.
174203

175204
## Contact
176205

bumpversion.readme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bumpversion patch --verbose --dry-run

grumpy-runtime-src/AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../AUTHORS.md

grumpy-runtime-src/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CONTRIBUTING.md

grumpy-runtime-src/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

grumpy-runtime-src/MANIFEST.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global-include *.py
2+
global-include *.go
3+
global-include *.mk
4+
global-include Makefile
5+
recursive-include tools *
6+
7+
global-exclude *.egg-info/*
8+
global-exclude *__pycache__*
9+
10+
recursive-exclude grumpy-tools-src *.go

0 commit comments

Comments
 (0)