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

pip-installable package #404

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
ef47913
Fix overflow on math.MaxInt64
alanjds Mar 7, 2018
4f3cc3e
Fix int underflow on 32bit CPUs
alanjds Mar 7, 2018
4a74f69
Preparing to split the parts
alanjds Mar 17, 2018
04106eb
Fixed imports and CLI namespaces
alanjds Mar 17, 2018
8830b44
Use installed CLI instead of /bin/grump{c,run}
alanjds Mar 17, 2018
4e4db78
tools grump{c,run} should be called via CLI:
alanjds Mar 17, 2018
a0445e3
Give credit
alanjds Mar 17, 2018
6d97fdd
Docs update on how to install/use the tools
alanjds Mar 17, 2018
ea84b39
Oops: Correct path
alanjds Mar 17, 2018
818959b
Preparing to install Runtime as a package
alanjds Mar 17, 2018
ec7d02a
Docs updated
alanjds Mar 17, 2018
3435c55
Fix imports
alanjds Mar 17, 2018
fafddde
trigger the ci
alanjds Mar 17, 2018
ca7f1d9
Inform Travis of the new package
alanjds Mar 17, 2018
6befd76
Merge remote-tracking branch 'origin/namespaces' into namespaces
alanjds Mar 17, 2018
262c7b2
should pip install --user on Travis
alanjds Mar 17, 2018
1219483
Poking around for Travis bless
alanjds Mar 19, 2018
796ba6f
do not pylint bash files
alanjds Mar 19, 2018
2fb4481
do not pylint bash files
alanjds Mar 19, 2018
7063550
No need to be that verbose anymore
alanjds Mar 19, 2018
19f84d4
Hacking to fix the `make test`
alanjds Mar 19, 2018
532e959
Merge branch 'namespaces' of github.com:alanjds/grumpy into namespaces
alanjds Mar 19, 2018
18f407a
Fixed tests import namespaces
alanjds Mar 19, 2018
e97c50a
rvm (#6307) strikes back && On OSX do sudo, on Linux dont.
alanjds Mar 20, 2018
839d66c
Opening room for Git to work w/ pydeps on the future
alanjds Mar 22, 2018
a075e29
bin/pydeps -> grumpy dependents
alanjds Mar 23, 2018
952c5fd
Remove symlink hack for pydeps
alanjds Mar 23, 2018
52a3fe9
Do not pylint bash scripts
alanjds Mar 24, 2018
3527b0b
Fix import
alanjds Mar 24, 2018
cdc7a0f
Merge remote-tracking branch 'origin/pydeps' into pydeps
alanjds Mar 26, 2018
5b81c1b
MakeCommand for building the runtime
alanjds Mar 28, 2018
39accab
ensure recent setuptools
alanjds Apr 4, 2018
b83a525
name the two packages properly
alanjds Apr 4, 2018
fe43502
explicitly set the build command for each pack
alanjds Apr 4, 2018
917ea5f
Fixed grumpc grumprun and pydeps on setup.py build phase
alanjds Apr 6, 2018
ddd300b
Show the make --debug logs for now
alanjds Apr 6, 2018
4de7eec
Setup the tools and the runtime
alanjds Apr 6, 2018
df3f644
Should build on install too
alanjds Apr 6, 2018
4446db8
More divided options
alanjds May 3, 2018
020576e
Separate setup.py for grumpy-tools
alanjds May 3, 2018
84f5755
Most runtime files were added via MANIFEST.in
alanjds May 3, 2018
4cce255
A better make command
alanjds May 3, 2018
d7b2b8b
Should include tools!
alanjds May 5, 2018
c9c5a85
You need tests shipped to be able to compile
alanjds May 12, 2018
aefa49f
Shoud have installed grumpy-tools before. For now.
alanjds May 12, 2018
2271dde
New __init__ to have something installed
alanjds May 13, 2018
37daf67
Working `pip install grumpy-runtime` with data
alanjds May 14, 2018
fec293c
Fix overflow on math.MaxInt64
alanjds Mar 7, 2018
48dad22
Fix int underflow on 32bit CPUs
alanjds Mar 7, 2018
25a1b60
Abort `grumpy run` command if grumpy-runtime is not available
alanjds May 16, 2018
4fda5cc
Get the runtime folder from Distribution if not available on GOPATH
alanjds May 16, 2018
8206061
Bump version: 0.1.4
alanjds May 16, 2018
e974db6
Cleaner setup.py of Runtime
alanjds May 16, 2018
ade1aee
Runtime needs Tools >= 0.1.4
alanjds May 16, 2018
5512840
Update install_requires
alanjds May 16, 2018
8b9e621
Bump version: 0.1.5
alanjds May 16, 2018
493f35d
Merge remote-tracking branch 'origin/split-setuptools' into split-set…
alanjds May 16, 2018
a0965de
Bump to 0.1.5.1:
alanjds May 16, 2018
f4ec968
Inform Travis that paths changed.
alanjds May 16, 2018
89001f0
Run Tools tests via `pytest`
alanjds May 17, 2018
a4f784c
Runtime makefile does not need to test Tools compiler (translator).
alanjds May 17, 2018
70d604b
Run the Tools tests only after the depends got settled
alanjds May 17, 2018
0ac49b2
Fix the Tools tests for Travis
alanjds May 18, 2018
a66ba70
Merge remote-tracking branch 'origin/split-setuptools' into split-set…
alanjds May 18, 2018
c8506f1
Postpone the Tools tests up to Runtime got installed
alanjds May 18, 2018
1f4073b
Pin the golang version
alanjds May 18, 2018
e29c163
Minimum version on OSX in 1.10.
alanjds May 18, 2018
f47b15f
README over the binary distribution usage
alanjds May 21, 2018
a65fe78
README Path changes updates
alanjds May 21, 2018
6643980
Update versions to start using `bumpversion`
alanjds May 21, 2018
f65b819
For now on: major.minor.patch
alanjds May 21, 2018
88caf6c
Bump version: 0.1.5 → 0.1.6
alanjds May 21, 2018
f2dad1f
Merge branch 'split-setuptools'
alanjds May 21, 2018
983735d
Badge and link to the forked alanjds/grumpy repo
alanjds May 21, 2018
8b8a1b8
Different build commands for install and develop
alanjds May 22, 2018
c3b37a2
bumpversion usage reminder
alanjds May 22, 2018
1b66928
Bump version: 0.1.6 → 0.1.7
alanjds May 22, 2018
2eccae7
Fixes the setup.py develop and the setup.py install
alanjds May 22, 2018
c7d18a4
Bump version: 0.1.7 → 0.1.8
alanjds May 22, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[bumpversion]
current_version = 0.1.8
commit = True
tag = True

[bumpversion:file:grumpy-tools-src/setup.py]

[bumpversion:file:grumpy-tools-src/grumpy_tools/__init__.py]

[bumpversion:file:grumpy-runtime-src/setup.py]

[bumpversion:file:grumpy-runtime-src/grumpy_runtime/__init__.py]

14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@ build
errors.err
*.swp
*.pyc
*.egg
.eggs/

grumpy-tools-src/dist/
grumpy-tools-src/*.egg-info
grumpy-runtime-src/dist
grumpy-runtime-src/*.egg-info

# Cache
.pytest_cache/

# Editors
.vscode/

28 changes: 24 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
language: go
go:
- "1.10.x"

os:
- linux
- osx
before_script:
- rvm get head || true # https://github.com/travis-ci/travis-ci/issues/6307
- set -e
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # https://github.com/travis-ci/travis-ci/issues/8920#issuecomment-352661024
# Run gofmt and lint serially to avoid confusing output. Run tests in parallel
# for speed.
script: make gofmt lint && make -j2 test
after_script: set +e
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo pip2 install pytest ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then pip2 install pytest --user ; fi
script:
# Install the thing
- cd grumpy-tools-src
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo pip2 install . ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then pip2 install . --user ; fi
- which grumpy
- cd ../grumpy-runtime-src
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo pip2 install . ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then pip2 install . --user ; fi
# Test the thing
- cd ../grumpy-tools-src
- pytest
- cd ../grumpy-runtime-src
- make gofmt lint && make -j2 test

# OSX swallows error logs: https://github.com/travis-ci/travis-ci/issues/6018
after_error:
- echo "== End of test log ==""
83 changes: 56 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Grumpy: Go running Python

[![Build Status](https://travis-ci.org/google/grumpy.svg?branch=master)](https://travis-ci.org/google/grumpy)
[![Build Status](https://travis-ci.org/alanjds/grumpy.svg?branch=master)](https://travis-ci.org/alanjds/grumpy)
[![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)

## Overview
Expand Down Expand Up @@ -56,14 +56,34 @@ There are three basic categories of incomplete functionality:

## Running Grumpy Programs

### Pre-requisites

The commands ahead assumes that you have Golang installed and a recent
version of Python 2, `setuptools` and `pip`.

### Method 1: binary package

For convenience, a Python package is provided from the PyPI. During install,
many Grumpy will be compiled and stored inside your Python installation.

You need Golang preinstalled anyway for the installation to be successful.

```
pip2 install -U grumpy-runtime -I --no-cache
(wait about 5 minutes)
echo "print 'hello, world'" | grumpy run
```

### Method 1: make run:

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

```
cd grumpy-tools-src
python2 setup.py develop
cd ../grumpy-runtime-src
echo "print 'hello, world'" | make run
```

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

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

```
cd grumpy-runtime-src
echo 'import sys; print sys.version' | grumprun
```

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

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

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

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

```
cd grumpy-runtime-src
echo 'from hello import hello; hello()' | grumprun
```

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

### grumpc
### Grumpy Tools

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

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

### Grumpy Runtime

The Go code generated by `grumpc` performs operations on data structures that
represent Python objects in running Grumpy programs. These data structures and
operations are defined in the `grumpy` Go library (source is in the runtime
subdir of the source distribution). This runtime is analogous to the Python C
API and many of the structures and operations defined by `grumpy` have
counterparts in CPython.
The Go code generated by `grumpy transpile` performs operations
on data structures that represent Python objects in running Grumpy programs.
These data structures and operations are defined in the `grumpy` Go library
(source is in the `grumpy-runtime-src/runtime` subdir of the source
distribution). This runtime is analogous to the Python C API and many of the
structures and operations defined by `grumpy` have counterparts in CPython.

### Grumpy Standard Library

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

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

### Source Code Overview

- `compiler`: Python package implementating Python -> Go transcompilation logic.
- `lib`: Grumpy-specific Python standard library implementation.
- `runtime`: Go source code for the Grumpy runtime library.
- `third_party/ouroboros`: Pure Python standard libraries copied from the
- `grumpy-tools-src/grumpy_tools/compiler`: Python package implementating Python -> Go transcompilation logic.
- `grumpy-runtime-src/lib`: Grumpy-specific Python standard library implementation.
- `grumpy-runtime-src/runtime`: Go source code for the Grumpy runtime library.
- `grumpy-runtime-src/third_party/ouroboros`: Pure Python standard libraries copied from the
[Ouroboros project](https://github.com/pybee/ouroboros).
- `third_party/pypy`: Pure Python standard libraries copied from PyPy.
- `third_party/stdlib`: Pure Python standard libraries copied from CPython.
- `tools`: Transcompilation and utility binaries.
- `grumpy-runtime-src/third_party/pypy`: Pure Python standard libraries copied from PyPy.
- `grumpy-runtime-src/third_party/stdlib`: Pure Python standard libraries copied from CPython.
- `grumpy-tools-src/grumpy_tools/`: Transcompilation and utility CLI.

## Contact

Expand Down
1 change: 1 addition & 0 deletions bumpversion.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bumpversion patch --verbose --dry-run
1 change: 1 addition & 0 deletions grumpy-runtime-src/AUTHORS.md
1 change: 1 addition & 0 deletions grumpy-runtime-src/CONTRIBUTING.md
1 change: 1 addition & 0 deletions grumpy-runtime-src/LICENSE
9 changes: 9 additions & 0 deletions grumpy-runtime-src/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global-include *.py
global-include *.go
global-include *.mk
global-include Makefile
recursive-include tools *

global-exclude *.egg-info/*

recursive-exclude grumpy-tools-src *.go
6 changes: 3 additions & 3 deletions Makefile → grumpy-runtime-src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ clean:
run: $(RUNNER)
@$(RUNNER_BIN)

test: $(ACCEPT_PASS_FILES) $(ACCEPT_PY_PASS_FILES) $(COMPILER_PASS_FILES) $(COMPILER_EXPR_VISITOR_PASS_FILES) $(COMPILER_STMT_PASS_FILES) $(RUNTIME_PASS_FILE) $(STDLIB_PASS_FILES)
test: $(ACCEPT_PASS_FILES) $(ACCEPT_PY_PASS_FILES) $(RUNTIME_PASS_FILE) $(STDLIB_PASS_FILES)

precommit: cover gofmt lint test

Expand Down Expand Up @@ -246,8 +246,8 @@ $(PYLINT_BIN):
@cd build/third_party && curl -sL https://pypi.io/packages/source/p/pylint/pylint-1.6.4.tar.gz | tar -zx
@cd build/third_party/pylint-1.6.4 && $(PYTHON) setup.py install --prefix $(ROOT_DIR)/build

pylint: $(PYLINT_BIN) $(COMPILER_SRCS) $(PYTHONPARSER_SRCS) $(COMPILER_BIN) $(RUNNER_BIN) $(TOOL_BINS)
@$(PYTHON) $(PYLINT_BIN) $(COMPILER_SRCS) $(COMPILER_BIN) $(RUNNER_BIN) $(TOOL_BINS)
pylint: $(PYLINT_BIN) $(COMPILER_SRCS) $(PYTHONPARSER_SRCS) $(TOOL_BINS)
@$(PYTHON) $(PYLINT_BIN) $(COMPILER_SRCS) $(filter-out %pydeps,$(TOOL_BINS))

lint: golint pylint

Expand Down
1 change: 1 addition & 0 deletions grumpy-runtime-src/README.md
File renamed without changes.
15 changes: 15 additions & 0 deletions grumpy-runtime-src/grumpy_runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.1.8'
1 change: 1 addition & 0 deletions grumpy-runtime-src/grumpy_runtime/data/gopath
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading