diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 00000000..9f32ea7c --- /dev/null +++ b/.bumpversion.cfg @@ -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] + diff --git a/.gitignore b/.gitignore index af4e99f5..c9619d0f 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ + diff --git a/.travis.yml b/.travis.yml index 7f0c7112..4c0be2e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 =="" diff --git a/README.md b/README.md index 13ec575d..ea2f0d94 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` @@ -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 @@ -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 @@ -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 ``` @@ -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 diff --git a/bumpversion.readme b/bumpversion.readme new file mode 100644 index 00000000..1ced1baf --- /dev/null +++ b/bumpversion.readme @@ -0,0 +1 @@ +bumpversion patch --verbose --dry-run diff --git a/grumpy-runtime-src/AUTHORS.md b/grumpy-runtime-src/AUTHORS.md new file mode 120000 index 00000000..3234d6e0 --- /dev/null +++ b/grumpy-runtime-src/AUTHORS.md @@ -0,0 +1 @@ +../AUTHORS.md \ No newline at end of file diff --git a/grumpy-runtime-src/CONTRIBUTING.md b/grumpy-runtime-src/CONTRIBUTING.md new file mode 120000 index 00000000..44fcc634 --- /dev/null +++ b/grumpy-runtime-src/CONTRIBUTING.md @@ -0,0 +1 @@ +../CONTRIBUTING.md \ No newline at end of file diff --git a/grumpy-runtime-src/LICENSE b/grumpy-runtime-src/LICENSE new file mode 120000 index 00000000..ea5b6064 --- /dev/null +++ b/grumpy-runtime-src/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/grumpy-runtime-src/MANIFEST.in b/grumpy-runtime-src/MANIFEST.in new file mode 100644 index 00000000..7f60bcbd --- /dev/null +++ b/grumpy-runtime-src/MANIFEST.in @@ -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 diff --git a/Makefile b/grumpy-runtime-src/Makefile similarity index 97% rename from Makefile rename to grumpy-runtime-src/Makefile index 9398f9e7..394e4bd7 100644 --- a/Makefile +++ b/grumpy-runtime-src/Makefile @@ -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 @@ -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 diff --git a/grumpy-runtime-src/README.md b/grumpy-runtime-src/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/grumpy-runtime-src/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/__init__.py b/grumpy-runtime-src/__init__.py similarity index 100% rename from __init__.py rename to grumpy-runtime-src/__init__.py diff --git a/benchmarks/bm_call_method.py b/grumpy-runtime-src/benchmarks/bm_call_method.py similarity index 100% rename from benchmarks/bm_call_method.py rename to grumpy-runtime-src/benchmarks/bm_call_method.py diff --git a/benchmarks/bm_call_simple.py b/grumpy-runtime-src/benchmarks/bm_call_simple.py similarity index 100% rename from benchmarks/bm_call_simple.py rename to grumpy-runtime-src/benchmarks/bm_call_simple.py diff --git a/benchmarks/call.py b/grumpy-runtime-src/benchmarks/call.py similarity index 100% rename from benchmarks/call.py rename to grumpy-runtime-src/benchmarks/call.py diff --git a/benchmarks/comprehension.py b/grumpy-runtime-src/benchmarks/comprehension.py similarity index 100% rename from benchmarks/comprehension.py rename to grumpy-runtime-src/benchmarks/comprehension.py diff --git a/benchmarks/concurrent.py b/grumpy-runtime-src/benchmarks/concurrent.py similarity index 100% rename from benchmarks/concurrent.py rename to grumpy-runtime-src/benchmarks/concurrent.py diff --git a/benchmarks/dict.py b/grumpy-runtime-src/benchmarks/dict.py similarity index 100% rename from benchmarks/dict.py rename to grumpy-runtime-src/benchmarks/dict.py diff --git a/benchmarks/generator.py b/grumpy-runtime-src/benchmarks/generator.py similarity index 100% rename from benchmarks/generator.py rename to grumpy-runtime-src/benchmarks/generator.py diff --git a/benchmarks/list.py b/grumpy-runtime-src/benchmarks/list.py similarity index 100% rename from benchmarks/list.py rename to grumpy-runtime-src/benchmarks/list.py diff --git a/benchmarks/loop.py b/grumpy-runtime-src/benchmarks/loop.py similarity index 100% rename from benchmarks/loop.py rename to grumpy-runtime-src/benchmarks/loop.py diff --git a/benchmarks/tuple.py b/grumpy-runtime-src/benchmarks/tuple.py similarity index 100% rename from benchmarks/tuple.py rename to grumpy-runtime-src/benchmarks/tuple.py diff --git a/grumpy-runtime-src/grumpy_runtime/__init__.py b/grumpy-runtime-src/grumpy_runtime/__init__.py new file mode 100644 index 00000000..fa6142cd --- /dev/null +++ b/grumpy-runtime-src/grumpy_runtime/__init__.py @@ -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' diff --git a/grumpy-runtime-src/grumpy_runtime/data/gopath b/grumpy-runtime-src/grumpy_runtime/data/gopath new file mode 120000 index 00000000..d77d3f3c --- /dev/null +++ b/grumpy-runtime-src/grumpy_runtime/data/gopath @@ -0,0 +1 @@ +../../build/lib/grumpy_runtime/data/gopath \ No newline at end of file diff --git a/lib/README.md b/grumpy-runtime-src/lib/README.md similarity index 100% rename from lib/README.md rename to grumpy-runtime-src/lib/README.md diff --git a/lib/__builtin__.py b/grumpy-runtime-src/lib/__builtin__.py similarity index 100% rename from lib/__builtin__.py rename to grumpy-runtime-src/lib/__builtin__.py diff --git a/lib/_random.py b/grumpy-runtime-src/lib/_random.py similarity index 100% rename from lib/_random.py rename to grumpy-runtime-src/lib/_random.py diff --git a/lib/_syscall.py b/grumpy-runtime-src/lib/_syscall.py similarity index 100% rename from lib/_syscall.py rename to grumpy-runtime-src/lib/_syscall.py diff --git a/lib/cStringIO.py b/grumpy-runtime-src/lib/cStringIO.py similarity index 100% rename from lib/cStringIO.py rename to grumpy-runtime-src/lib/cStringIO.py diff --git a/lib/errno.py b/grumpy-runtime-src/lib/errno.py similarity index 100% rename from lib/errno.py rename to grumpy-runtime-src/lib/errno.py diff --git a/lib/exceptions.py b/grumpy-runtime-src/lib/exceptions.py similarity index 100% rename from lib/exceptions.py rename to grumpy-runtime-src/lib/exceptions.py diff --git a/lib/itertools.py b/grumpy-runtime-src/lib/itertools.py similarity index 100% rename from lib/itertools.py rename to grumpy-runtime-src/lib/itertools.py diff --git a/lib/itertools_test.py b/grumpy-runtime-src/lib/itertools_test.py similarity index 100% rename from lib/itertools_test.py rename to grumpy-runtime-src/lib/itertools_test.py diff --git a/lib/math.py b/grumpy-runtime-src/lib/math.py similarity index 100% rename from lib/math.py rename to grumpy-runtime-src/lib/math.py diff --git a/lib/math_test.py b/grumpy-runtime-src/lib/math_test.py similarity index 100% rename from lib/math_test.py rename to grumpy-runtime-src/lib/math_test.py diff --git a/lib/os/__init__.py b/grumpy-runtime-src/lib/os/__init__.py similarity index 100% rename from lib/os/__init__.py rename to grumpy-runtime-src/lib/os/__init__.py diff --git a/lib/os/path.py b/grumpy-runtime-src/lib/os/path.py similarity index 100% rename from lib/os/path.py rename to grumpy-runtime-src/lib/os/path.py diff --git a/lib/os/path_test.py b/grumpy-runtime-src/lib/os/path_test.py similarity index 100% rename from lib/os/path_test.py rename to grumpy-runtime-src/lib/os/path_test.py diff --git a/lib/os_test.py b/grumpy-runtime-src/lib/os_test.py similarity index 100% rename from lib/os_test.py rename to grumpy-runtime-src/lib/os_test.py diff --git a/lib/random_test.py b/grumpy-runtime-src/lib/random_test.py similarity index 100% rename from lib/random_test.py rename to grumpy-runtime-src/lib/random_test.py diff --git a/lib/select_.py b/grumpy-runtime-src/lib/select_.py similarity index 100% rename from lib/select_.py rename to grumpy-runtime-src/lib/select_.py diff --git a/lib/stat.py b/grumpy-runtime-src/lib/stat.py similarity index 100% rename from lib/stat.py rename to grumpy-runtime-src/lib/stat.py diff --git a/lib/sys.py b/grumpy-runtime-src/lib/sys.py similarity index 100% rename from lib/sys.py rename to grumpy-runtime-src/lib/sys.py diff --git a/lib/sys_test.py b/grumpy-runtime-src/lib/sys_test.py similarity index 100% rename from lib/sys_test.py rename to grumpy-runtime-src/lib/sys_test.py diff --git a/lib/tempfile.py b/grumpy-runtime-src/lib/tempfile.py similarity index 100% rename from lib/tempfile.py rename to grumpy-runtime-src/lib/tempfile.py diff --git a/lib/tempfile_test.py b/grumpy-runtime-src/lib/tempfile_test.py similarity index 100% rename from lib/tempfile_test.py rename to grumpy-runtime-src/lib/tempfile_test.py diff --git a/lib/thread.py b/grumpy-runtime-src/lib/thread.py similarity index 100% rename from lib/thread.py rename to grumpy-runtime-src/lib/thread.py diff --git a/lib/time.py b/grumpy-runtime-src/lib/time.py similarity index 100% rename from lib/time.py rename to grumpy-runtime-src/lib/time.py diff --git a/lib/time_test.py b/grumpy-runtime-src/lib/time_test.py similarity index 100% rename from lib/time_test.py rename to grumpy-runtime-src/lib/time_test.py diff --git a/lib/types_test.py b/grumpy-runtime-src/lib/types_test.py similarity index 100% rename from lib/types_test.py rename to grumpy-runtime-src/lib/types_test.py diff --git a/lib/weetest.py b/grumpy-runtime-src/lib/weetest.py similarity index 100% rename from lib/weetest.py rename to grumpy-runtime-src/lib/weetest.py diff --git a/lib/weetest_test.py b/grumpy-runtime-src/lib/weetest_test.py similarity index 100% rename from lib/weetest_test.py rename to grumpy-runtime-src/lib/weetest_test.py diff --git a/runtime/baseexception.go b/grumpy-runtime-src/runtime/baseexception.go similarity index 100% rename from runtime/baseexception.go rename to grumpy-runtime-src/runtime/baseexception.go diff --git a/runtime/baseexception_test.go b/grumpy-runtime-src/runtime/baseexception_test.go similarity index 100% rename from runtime/baseexception_test.go rename to grumpy-runtime-src/runtime/baseexception_test.go diff --git a/runtime/basestring.go b/grumpy-runtime-src/runtime/basestring.go similarity index 100% rename from runtime/basestring.go rename to grumpy-runtime-src/runtime/basestring.go diff --git a/runtime/basestring_test.go b/grumpy-runtime-src/runtime/basestring_test.go similarity index 100% rename from runtime/basestring_test.go rename to grumpy-runtime-src/runtime/basestring_test.go diff --git a/runtime/bool.go b/grumpy-runtime-src/runtime/bool.go similarity index 100% rename from runtime/bool.go rename to grumpy-runtime-src/runtime/bool.go diff --git a/runtime/bool_test.go b/grumpy-runtime-src/runtime/bool_test.go similarity index 100% rename from runtime/bool_test.go rename to grumpy-runtime-src/runtime/bool_test.go diff --git a/runtime/builtin_types.go b/grumpy-runtime-src/runtime/builtin_types.go similarity index 100% rename from runtime/builtin_types.go rename to grumpy-runtime-src/runtime/builtin_types.go diff --git a/runtime/builtin_types_test.go b/grumpy-runtime-src/runtime/builtin_types_test.go similarity index 100% rename from runtime/builtin_types_test.go rename to grumpy-runtime-src/runtime/builtin_types_test.go diff --git a/runtime/bytearray.go b/grumpy-runtime-src/runtime/bytearray.go similarity index 100% rename from runtime/bytearray.go rename to grumpy-runtime-src/runtime/bytearray.go diff --git a/runtime/bytearray_test.go b/grumpy-runtime-src/runtime/bytearray_test.go similarity index 100% rename from runtime/bytearray_test.go rename to grumpy-runtime-src/runtime/bytearray_test.go diff --git a/runtime/code.go b/grumpy-runtime-src/runtime/code.go similarity index 100% rename from runtime/code.go rename to grumpy-runtime-src/runtime/code.go diff --git a/runtime/code_test.go b/grumpy-runtime-src/runtime/code_test.go similarity index 100% rename from runtime/code_test.go rename to grumpy-runtime-src/runtime/code_test.go diff --git a/runtime/complex.go b/grumpy-runtime-src/runtime/complex.go similarity index 100% rename from runtime/complex.go rename to grumpy-runtime-src/runtime/complex.go diff --git a/runtime/complex_test.go b/grumpy-runtime-src/runtime/complex_test.go similarity index 100% rename from runtime/complex_test.go rename to grumpy-runtime-src/runtime/complex_test.go diff --git a/runtime/core.go b/grumpy-runtime-src/runtime/core.go similarity index 100% rename from runtime/core.go rename to grumpy-runtime-src/runtime/core.go diff --git a/runtime/core_test.go b/grumpy-runtime-src/runtime/core_test.go similarity index 100% rename from runtime/core_test.go rename to grumpy-runtime-src/runtime/core_test.go diff --git a/runtime/descriptor.go b/grumpy-runtime-src/runtime/descriptor.go similarity index 100% rename from runtime/descriptor.go rename to grumpy-runtime-src/runtime/descriptor.go diff --git a/runtime/descriptor_test.go b/grumpy-runtime-src/runtime/descriptor_test.go similarity index 100% rename from runtime/descriptor_test.go rename to grumpy-runtime-src/runtime/descriptor_test.go diff --git a/runtime/dict.go b/grumpy-runtime-src/runtime/dict.go similarity index 100% rename from runtime/dict.go rename to grumpy-runtime-src/runtime/dict.go diff --git a/runtime/dict_test.go b/grumpy-runtime-src/runtime/dict_test.go similarity index 100% rename from runtime/dict_test.go rename to grumpy-runtime-src/runtime/dict_test.go diff --git a/runtime/doc.go b/grumpy-runtime-src/runtime/doc.go similarity index 100% rename from runtime/doc.go rename to grumpy-runtime-src/runtime/doc.go diff --git a/runtime/exceptions.go b/grumpy-runtime-src/runtime/exceptions.go similarity index 100% rename from runtime/exceptions.go rename to grumpy-runtime-src/runtime/exceptions.go diff --git a/runtime/file.go b/grumpy-runtime-src/runtime/file.go similarity index 100% rename from runtime/file.go rename to grumpy-runtime-src/runtime/file.go diff --git a/runtime/file_test.go b/grumpy-runtime-src/runtime/file_test.go similarity index 100% rename from runtime/file_test.go rename to grumpy-runtime-src/runtime/file_test.go diff --git a/runtime/float.go b/grumpy-runtime-src/runtime/float.go similarity index 100% rename from runtime/float.go rename to grumpy-runtime-src/runtime/float.go diff --git a/runtime/float_test.go b/grumpy-runtime-src/runtime/float_test.go similarity index 100% rename from runtime/float_test.go rename to grumpy-runtime-src/runtime/float_test.go diff --git a/runtime/frame.go b/grumpy-runtime-src/runtime/frame.go similarity index 100% rename from runtime/frame.go rename to grumpy-runtime-src/runtime/frame.go diff --git a/runtime/frame_test.go b/grumpy-runtime-src/runtime/frame_test.go similarity index 100% rename from runtime/frame_test.go rename to grumpy-runtime-src/runtime/frame_test.go diff --git a/runtime/function.go b/grumpy-runtime-src/runtime/function.go similarity index 100% rename from runtime/function.go rename to grumpy-runtime-src/runtime/function.go diff --git a/runtime/function_test.go b/grumpy-runtime-src/runtime/function_test.go similarity index 100% rename from runtime/function_test.go rename to grumpy-runtime-src/runtime/function_test.go diff --git a/runtime/generator.go b/grumpy-runtime-src/runtime/generator.go similarity index 100% rename from runtime/generator.go rename to grumpy-runtime-src/runtime/generator.go diff --git a/runtime/generator_test.go b/grumpy-runtime-src/runtime/generator_test.go similarity index 100% rename from runtime/generator_test.go rename to grumpy-runtime-src/runtime/generator_test.go diff --git a/runtime/int.go b/grumpy-runtime-src/runtime/int.go similarity index 100% rename from runtime/int.go rename to grumpy-runtime-src/runtime/int.go diff --git a/runtime/int_test.go b/grumpy-runtime-src/runtime/int_test.go similarity index 100% rename from runtime/int_test.go rename to grumpy-runtime-src/runtime/int_test.go diff --git a/runtime/list.go b/grumpy-runtime-src/runtime/list.go similarity index 100% rename from runtime/list.go rename to grumpy-runtime-src/runtime/list.go diff --git a/runtime/list_test.go b/grumpy-runtime-src/runtime/list_test.go similarity index 100% rename from runtime/list_test.go rename to grumpy-runtime-src/runtime/list_test.go diff --git a/runtime/long.go b/grumpy-runtime-src/runtime/long.go similarity index 100% rename from runtime/long.go rename to grumpy-runtime-src/runtime/long.go diff --git a/runtime/long_test.go b/grumpy-runtime-src/runtime/long_test.go similarity index 100% rename from runtime/long_test.go rename to grumpy-runtime-src/runtime/long_test.go diff --git a/runtime/method.go b/grumpy-runtime-src/runtime/method.go similarity index 100% rename from runtime/method.go rename to grumpy-runtime-src/runtime/method.go diff --git a/runtime/method_test.go b/grumpy-runtime-src/runtime/method_test.go similarity index 100% rename from runtime/method_test.go rename to grumpy-runtime-src/runtime/method_test.go diff --git a/runtime/module.go b/grumpy-runtime-src/runtime/module.go similarity index 100% rename from runtime/module.go rename to grumpy-runtime-src/runtime/module.go diff --git a/runtime/module_test.go b/grumpy-runtime-src/runtime/module_test.go similarity index 100% rename from runtime/module_test.go rename to grumpy-runtime-src/runtime/module_test.go diff --git a/runtime/native.go b/grumpy-runtime-src/runtime/native.go similarity index 100% rename from runtime/native.go rename to grumpy-runtime-src/runtime/native.go diff --git a/runtime/native_test.go b/grumpy-runtime-src/runtime/native_test.go similarity index 100% rename from runtime/native_test.go rename to grumpy-runtime-src/runtime/native_test.go diff --git a/runtime/numeric.go b/grumpy-runtime-src/runtime/numeric.go similarity index 100% rename from runtime/numeric.go rename to grumpy-runtime-src/runtime/numeric.go diff --git a/runtime/object.go b/grumpy-runtime-src/runtime/object.go similarity index 100% rename from runtime/object.go rename to grumpy-runtime-src/runtime/object.go diff --git a/runtime/object_test.go b/grumpy-runtime-src/runtime/object_test.go similarity index 100% rename from runtime/object_test.go rename to grumpy-runtime-src/runtime/object_test.go diff --git a/runtime/param.go b/grumpy-runtime-src/runtime/param.go similarity index 100% rename from runtime/param.go rename to grumpy-runtime-src/runtime/param.go diff --git a/runtime/param_test.go b/grumpy-runtime-src/runtime/param_test.go similarity index 100% rename from runtime/param_test.go rename to grumpy-runtime-src/runtime/param_test.go diff --git a/runtime/range.go b/grumpy-runtime-src/runtime/range.go similarity index 100% rename from runtime/range.go rename to grumpy-runtime-src/runtime/range.go diff --git a/runtime/range_test.go b/grumpy-runtime-src/runtime/range_test.go similarity index 100% rename from runtime/range_test.go rename to grumpy-runtime-src/runtime/range_test.go diff --git a/runtime/seq.go b/grumpy-runtime-src/runtime/seq.go similarity index 100% rename from runtime/seq.go rename to grumpy-runtime-src/runtime/seq.go diff --git a/runtime/seq_test.go b/grumpy-runtime-src/runtime/seq_test.go similarity index 100% rename from runtime/seq_test.go rename to grumpy-runtime-src/runtime/seq_test.go diff --git a/runtime/set.go b/grumpy-runtime-src/runtime/set.go similarity index 100% rename from runtime/set.go rename to grumpy-runtime-src/runtime/set.go diff --git a/runtime/set_test.go b/grumpy-runtime-src/runtime/set_test.go similarity index 100% rename from runtime/set_test.go rename to grumpy-runtime-src/runtime/set_test.go diff --git a/runtime/slice.go b/grumpy-runtime-src/runtime/slice.go similarity index 100% rename from runtime/slice.go rename to grumpy-runtime-src/runtime/slice.go diff --git a/runtime/slice_test.go b/grumpy-runtime-src/runtime/slice_test.go similarity index 100% rename from runtime/slice_test.go rename to grumpy-runtime-src/runtime/slice_test.go diff --git a/runtime/slots.go b/grumpy-runtime-src/runtime/slots.go similarity index 100% rename from runtime/slots.go rename to grumpy-runtime-src/runtime/slots.go diff --git a/runtime/slots_test.go b/grumpy-runtime-src/runtime/slots_test.go similarity index 100% rename from runtime/slots_test.go rename to grumpy-runtime-src/runtime/slots_test.go diff --git a/runtime/str.go b/grumpy-runtime-src/runtime/str.go similarity index 100% rename from runtime/str.go rename to grumpy-runtime-src/runtime/str.go diff --git a/runtime/str_test.go b/grumpy-runtime-src/runtime/str_test.go similarity index 100% rename from runtime/str_test.go rename to grumpy-runtime-src/runtime/str_test.go diff --git a/runtime/super.go b/grumpy-runtime-src/runtime/super.go similarity index 100% rename from runtime/super.go rename to grumpy-runtime-src/runtime/super.go diff --git a/runtime/super_test.go b/grumpy-runtime-src/runtime/super_test.go similarity index 100% rename from runtime/super_test.go rename to grumpy-runtime-src/runtime/super_test.go diff --git a/runtime/threading.go b/grumpy-runtime-src/runtime/threading.go similarity index 100% rename from runtime/threading.go rename to grumpy-runtime-src/runtime/threading.go diff --git a/runtime/threading_test.go b/grumpy-runtime-src/runtime/threading_test.go similarity index 100% rename from runtime/threading_test.go rename to grumpy-runtime-src/runtime/threading_test.go diff --git a/runtime/traceback.go b/grumpy-runtime-src/runtime/traceback.go similarity index 100% rename from runtime/traceback.go rename to grumpy-runtime-src/runtime/traceback.go diff --git a/runtime/tuple.go b/grumpy-runtime-src/runtime/tuple.go similarity index 100% rename from runtime/tuple.go rename to grumpy-runtime-src/runtime/tuple.go diff --git a/runtime/tuple_test.go b/grumpy-runtime-src/runtime/tuple_test.go similarity index 100% rename from runtime/tuple_test.go rename to grumpy-runtime-src/runtime/tuple_test.go diff --git a/runtime/type.go b/grumpy-runtime-src/runtime/type.go similarity index 100% rename from runtime/type.go rename to grumpy-runtime-src/runtime/type.go diff --git a/runtime/type_test.go b/grumpy-runtime-src/runtime/type_test.go similarity index 100% rename from runtime/type_test.go rename to grumpy-runtime-src/runtime/type_test.go diff --git a/runtime/unicode.go b/grumpy-runtime-src/runtime/unicode.go similarity index 100% rename from runtime/unicode.go rename to grumpy-runtime-src/runtime/unicode.go diff --git a/runtime/unicode_test.go b/grumpy-runtime-src/runtime/unicode_test.go similarity index 100% rename from runtime/unicode_test.go rename to grumpy-runtime-src/runtime/unicode_test.go diff --git a/runtime/weakref.go b/grumpy-runtime-src/runtime/weakref.go similarity index 100% rename from runtime/weakref.go rename to grumpy-runtime-src/runtime/weakref.go diff --git a/runtime/weakref_test.go b/grumpy-runtime-src/runtime/weakref_test.go similarity index 100% rename from runtime/weakref_test.go rename to grumpy-runtime-src/runtime/weakref_test.go diff --git a/grumpy-runtime-src/setup.py b/grumpy-runtime-src/setup.py new file mode 100644 index 00000000..64591708 --- /dev/null +++ b/grumpy-runtime-src/setup.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# 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. + +"""The setup script.""" + +import os +import fnmatch +import shutil +import sys +from setuptools import setup, find_packages +from distutils.command.build_py import build_py as BuildPyCommand +from distutils.command.build_ext import build_ext as BuildExtCommand +import subprocess + +try: + with open('README.md') as readme_file: + readme = readme_file.read() +except: + readme = '' + +setup_requirements = [ + 'setuptools>=28.8.0', +] + +test_requirements = [ + 'pytest', + # TODO: Put package test requirements here +] + +needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) +if needs_pytest: + setup_requirements += ['pytest-runner'] + +COMMON_OPTIONS = dict( + version='0.1.8', + description="Grumpy Runtime & Transpiler", + long_description=readme, + author="Dylan Trotter et al.", + maintainer="Alan Justino et al.", + maintainer_email="alan.justino@yahoo.com.br", + url='https://github.com/google/grumpy', + license="Apache Software License 2.0", + zip_safe=False, + keywords='grumpy_runtime', + python_requires='~=2.7.0', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + "Programming Language :: Python :: 2", + 'Programming Language :: Python :: 2.7', + ], + test_suite='tests', + tests_require=test_requirements, + setup_requires=setup_requirements, +) + + +def _run_make(self, *args, **kwargs): + subprocess.check_call(["""echo "print 'Make Runtime Success'" | make run --debug"""], shell=True) + + +def _glob_deep(directory, pattern): + # From: https://stackoverflow.com/a/2186673/798575 + for root, dirs, files in os.walk(directory): + for basename in files: + if fnmatch.fnmatch(basename, pattern): + filename = os.path.join(root, basename) + yield filename + + +class BuildMakeCommandInstall(BuildPyCommand): # Ran on setup.py install + def run(self, *args, **kwargs): + # Thanks http://www.digip.org/blog/2011/01/generating-data-files-in-setup.py.html for the tip + + _run_make(self, *args, **kwargs) + + # Makefile creates a "gopath" folder named "build" on root folder. Change it! + shutil.move('build', 'gopath') + + if not self.dry_run: + target_dir = os.path.join(self.build_lib, 'grumpy_runtime/data') + + # Remove the symlink used on develop + shutil.rmtree(target_dir, ignore_errors=True) + self.mkpath(target_dir) + shutil.move('gopath', target_dir) + + build_dir = os.path.join(self.build_lib, 'grumpy_runtime') + built_files = _glob_deep(os.path.join(build_dir, 'gopath'), '*') + + # Strip directory from globbed filenames + build_dir_len = len(build_dir) + 1 # One more for leading "/" + built_files = [fn[build_dir_len:] for fn in built_files] + + self.data_files = [ + # (package, src_dir, build_dir, filenames[]) + ('grumpy_runtime', 'grumpy_runtime', build_dir, built_files), + ] + + super_result = BuildPyCommand.run(self, *args, **kwargs) + return super_result + + +class BuildMakeCommandDevelop(BuildExtCommand): # Ran on setup.py develop + def run(self, *args, **kwargs): + # Thanks http://www.digip.org/blog/2011/01/generating-data-files-in-setup.py.html for the tip + + _run_make(self, *args, **kwargs) + + # Makefile creates a "gopath" folder named "build" on root folder. Change it! + shutil.move('build', 'gopath') + + if not self.dry_run: + target_dir = os.path.join(self.build_lib, 'grumpy_runtime/data') + self.mkpath(target_dir) + shutil.move('gopath', target_dir) + + build_dir = os.path.join(self.build_lib, 'grumpy_runtime') + built_files = _glob_deep(os.path.join(build_dir, 'gopath'), '*') + + # Strip directory from globbed filenames + build_dir_len = len(build_dir) + 1 # One more for leading "/" + built_files = [fn[build_dir_len:] for fn in built_files] + + self.data_files = [ + # (package, src_dir, build_dir, filenames[]) + ('grumpy_runtime', 'grumpy_runtime', build_dir, built_files), + ] + + super_result = BuildExtCommand.run(self, *args, **kwargs) + return super_result + + +GRUMPY_RUNTIME_OPTIONS = dict( + name='grumpy-runtime', + requires=['grumpy_tools'], + install_requires=['grumpy-tools>=0.1.8'], + packages=find_packages( + exclude=["*.tests", "*.tests.*", "tests.*", "tests"], + ), + include_package_data=True, + cmdclass={ + 'build_py': BuildMakeCommandInstall, # Ran on setup.py install + 'build_ext': BuildMakeCommandDevelop, # Ran on setup.py develop + }, + zip_safe=False, +) +GRUMPY_RUNTIME_OPTIONS.update(COMMON_OPTIONS) + +setup(**GRUMPY_RUNTIME_OPTIONS) diff --git a/testing/assert_test.py b/grumpy-runtime-src/testing/assert_test.py similarity index 100% rename from testing/assert_test.py rename to grumpy-runtime-src/testing/assert_test.py diff --git a/testing/assign_test.py b/grumpy-runtime-src/testing/assign_test.py similarity index 100% rename from testing/assign_test.py rename to grumpy-runtime-src/testing/assign_test.py diff --git a/testing/builtin_test.py b/grumpy-runtime-src/testing/builtin_test.py similarity index 100% rename from testing/builtin_test.py rename to grumpy-runtime-src/testing/builtin_test.py diff --git a/testing/class_test.py b/grumpy-runtime-src/testing/class_test.py similarity index 100% rename from testing/class_test.py rename to grumpy-runtime-src/testing/class_test.py diff --git a/testing/compare_test.py b/grumpy-runtime-src/testing/compare_test.py similarity index 100% rename from testing/compare_test.py rename to grumpy-runtime-src/testing/compare_test.py diff --git a/testing/complex_test.py b/grumpy-runtime-src/testing/complex_test.py similarity index 100% rename from testing/complex_test.py rename to grumpy-runtime-src/testing/complex_test.py diff --git a/testing/comprehension_test.py b/grumpy-runtime-src/testing/comprehension_test.py similarity index 100% rename from testing/comprehension_test.py rename to grumpy-runtime-src/testing/comprehension_test.py diff --git a/testing/dict_test.py b/grumpy-runtime-src/testing/dict_test.py similarity index 100% rename from testing/dict_test.py rename to grumpy-runtime-src/testing/dict_test.py diff --git a/testing/file_test.py b/grumpy-runtime-src/testing/file_test.py similarity index 100% rename from testing/file_test.py rename to grumpy-runtime-src/testing/file_test.py diff --git a/testing/float_test.py b/grumpy-runtime-src/testing/float_test.py similarity index 100% rename from testing/float_test.py rename to grumpy-runtime-src/testing/float_test.py diff --git a/testing/for_test.py b/grumpy-runtime-src/testing/for_test.py similarity index 100% rename from testing/for_test.py rename to grumpy-runtime-src/testing/for_test.py diff --git a/testing/function_test.py b/grumpy-runtime-src/testing/function_test.py similarity index 100% rename from testing/function_test.py rename to grumpy-runtime-src/testing/function_test.py diff --git a/testing/generator_test.py b/grumpy-runtime-src/testing/generator_test.py similarity index 100% rename from testing/generator_test.py rename to grumpy-runtime-src/testing/generator_test.py diff --git a/testing/getopt_test.py b/grumpy-runtime-src/testing/getopt_test.py similarity index 100% rename from testing/getopt_test.py rename to grumpy-runtime-src/testing/getopt_test.py diff --git a/testing/global_test.py b/grumpy-runtime-src/testing/global_test.py similarity index 100% rename from testing/global_test.py rename to grumpy-runtime-src/testing/global_test.py diff --git a/testing/if_test.py b/grumpy-runtime-src/testing/if_test.py similarity index 100% rename from testing/if_test.py rename to grumpy-runtime-src/testing/if_test.py diff --git a/testing/import_test.py b/grumpy-runtime-src/testing/import_test.py similarity index 100% rename from testing/import_test.py rename to grumpy-runtime-src/testing/import_test.py diff --git a/testing/list_test.py b/grumpy-runtime-src/testing/list_test.py similarity index 100% rename from testing/list_test.py rename to grumpy-runtime-src/testing/list_test.py diff --git a/testing/native_test.py b/grumpy-runtime-src/testing/native_test.py similarity index 100% rename from testing/native_test.py rename to grumpy-runtime-src/testing/native_test.py diff --git a/testing/op_test.py b/grumpy-runtime-src/testing/op_test.py similarity index 100% rename from testing/op_test.py rename to grumpy-runtime-src/testing/op_test.py diff --git a/testing/pow_test.py b/grumpy-runtime-src/testing/pow_test.py similarity index 100% rename from testing/pow_test.py rename to grumpy-runtime-src/testing/pow_test.py diff --git a/testing/scope_test.py b/grumpy-runtime-src/testing/scope_test.py similarity index 100% rename from testing/scope_test.py rename to grumpy-runtime-src/testing/scope_test.py diff --git a/testing/str_test.py b/grumpy-runtime-src/testing/str_test.py similarity index 100% rename from testing/str_test.py rename to grumpy-runtime-src/testing/str_test.py diff --git a/testing/struct_test.py b/grumpy-runtime-src/testing/struct_test.py similarity index 100% rename from testing/struct_test.py rename to grumpy-runtime-src/testing/struct_test.py diff --git a/testing/try_test.py b/grumpy-runtime-src/testing/try_test.py similarity index 100% rename from testing/try_test.py rename to grumpy-runtime-src/testing/try_test.py diff --git a/testing/tuple_test.py b/grumpy-runtime-src/testing/tuple_test.py similarity index 100% rename from testing/tuple_test.py rename to grumpy-runtime-src/testing/tuple_test.py diff --git a/testing/while_test.py b/grumpy-runtime-src/testing/while_test.py similarity index 100% rename from testing/while_test.py rename to grumpy-runtime-src/testing/while_test.py diff --git a/testing/with_test.py b/grumpy-runtime-src/testing/with_test.py similarity index 100% rename from testing/with_test.py rename to grumpy-runtime-src/testing/with_test.py diff --git a/third_party/ouroboros/AUTHORS b/grumpy-runtime-src/third_party/ouroboros/AUTHORS similarity index 100% rename from third_party/ouroboros/AUTHORS rename to grumpy-runtime-src/third_party/ouroboros/AUTHORS diff --git a/third_party/ouroboros/LICENSE b/grumpy-runtime-src/third_party/ouroboros/LICENSE similarity index 100% rename from third_party/ouroboros/LICENSE rename to grumpy-runtime-src/third_party/ouroboros/LICENSE diff --git a/third_party/ouroboros/READEME.md b/grumpy-runtime-src/third_party/ouroboros/READEME.md similarity index 100% rename from third_party/ouroboros/READEME.md rename to grumpy-runtime-src/third_party/ouroboros/READEME.md diff --git a/third_party/ouroboros/operator.py b/grumpy-runtime-src/third_party/ouroboros/operator.py similarity index 100% rename from third_party/ouroboros/operator.py rename to grumpy-runtime-src/third_party/ouroboros/operator.py diff --git a/third_party/ouroboros/test/test_operator.py b/grumpy-runtime-src/third_party/ouroboros/test/test_operator.py similarity index 100% rename from third_party/ouroboros/test/test_operator.py rename to grumpy-runtime-src/third_party/ouroboros/test/test_operator.py diff --git a/third_party/pypy/LICENSE b/grumpy-runtime-src/third_party/pypy/LICENSE similarity index 100% rename from third_party/pypy/LICENSE rename to grumpy-runtime-src/third_party/pypy/LICENSE diff --git a/third_party/pypy/README.md b/grumpy-runtime-src/third_party/pypy/README.md similarity index 100% rename from third_party/pypy/README.md rename to grumpy-runtime-src/third_party/pypy/README.md diff --git a/third_party/pypy/_collections.py b/grumpy-runtime-src/third_party/pypy/_collections.py similarity index 100% rename from third_party/pypy/_collections.py rename to grumpy-runtime-src/third_party/pypy/_collections.py diff --git a/third_party/pypy/_csv.py b/grumpy-runtime-src/third_party/pypy/_csv.py similarity index 100% rename from third_party/pypy/_csv.py rename to grumpy-runtime-src/third_party/pypy/_csv.py diff --git a/third_party/pypy/_functools.py b/grumpy-runtime-src/third_party/pypy/_functools.py similarity index 100% rename from third_party/pypy/_functools.py rename to grumpy-runtime-src/third_party/pypy/_functools.py diff --git a/third_party/pypy/_md5.py b/grumpy-runtime-src/third_party/pypy/_md5.py similarity index 100% rename from third_party/pypy/_md5.py rename to grumpy-runtime-src/third_party/pypy/_md5.py diff --git a/third_party/pypy/_sha.py b/grumpy-runtime-src/third_party/pypy/_sha.py similarity index 100% rename from third_party/pypy/_sha.py rename to grumpy-runtime-src/third_party/pypy/_sha.py diff --git a/third_party/pypy/_sha256.py b/grumpy-runtime-src/third_party/pypy/_sha256.py similarity index 100% rename from third_party/pypy/_sha256.py rename to grumpy-runtime-src/third_party/pypy/_sha256.py diff --git a/third_party/pypy/_sha512.py b/grumpy-runtime-src/third_party/pypy/_sha512.py similarity index 100% rename from third_party/pypy/_sha512.py rename to grumpy-runtime-src/third_party/pypy/_sha512.py diff --git a/third_party/pypy/_sre.py b/grumpy-runtime-src/third_party/pypy/_sre.py similarity index 100% rename from third_party/pypy/_sre.py rename to grumpy-runtime-src/third_party/pypy/_sre.py diff --git a/third_party/pypy/_struct.py b/grumpy-runtime-src/third_party/pypy/_struct.py similarity index 100% rename from third_party/pypy/_struct.py rename to grumpy-runtime-src/third_party/pypy/_struct.py diff --git a/third_party/pypy/binascii.py b/grumpy-runtime-src/third_party/pypy/binascii.py similarity index 100% rename from third_party/pypy/binascii.py rename to grumpy-runtime-src/third_party/pypy/binascii.py diff --git a/third_party/pypy/datetime.py b/grumpy-runtime-src/third_party/pypy/datetime.py similarity index 100% rename from third_party/pypy/datetime.py rename to grumpy-runtime-src/third_party/pypy/datetime.py diff --git a/third_party/stdlib/LICENSE b/grumpy-runtime-src/third_party/stdlib/LICENSE similarity index 100% rename from third_party/stdlib/LICENSE rename to grumpy-runtime-src/third_party/stdlib/LICENSE diff --git a/third_party/stdlib/Queue.py b/grumpy-runtime-src/third_party/stdlib/Queue.py similarity index 100% rename from third_party/stdlib/Queue.py rename to grumpy-runtime-src/third_party/stdlib/Queue.py diff --git a/third_party/stdlib/README.md b/grumpy-runtime-src/third_party/stdlib/README.md similarity index 100% rename from third_party/stdlib/README.md rename to grumpy-runtime-src/third_party/stdlib/README.md diff --git a/third_party/stdlib/StringIO.py b/grumpy-runtime-src/third_party/stdlib/StringIO.py similarity index 100% rename from third_party/stdlib/StringIO.py rename to grumpy-runtime-src/third_party/stdlib/StringIO.py diff --git a/third_party/stdlib/UserDict.py b/grumpy-runtime-src/third_party/stdlib/UserDict.py similarity index 100% rename from third_party/stdlib/UserDict.py rename to grumpy-runtime-src/third_party/stdlib/UserDict.py diff --git a/third_party/stdlib/UserList.py b/grumpy-runtime-src/third_party/stdlib/UserList.py similarity index 100% rename from third_party/stdlib/UserList.py rename to grumpy-runtime-src/third_party/stdlib/UserList.py diff --git a/third_party/stdlib/UserString.py b/grumpy-runtime-src/third_party/stdlib/UserString.py similarity index 100% rename from third_party/stdlib/UserString.py rename to grumpy-runtime-src/third_party/stdlib/UserString.py diff --git a/third_party/stdlib/_abcoll.py b/grumpy-runtime-src/third_party/stdlib/_abcoll.py similarity index 100% rename from third_party/stdlib/_abcoll.py rename to grumpy-runtime-src/third_party/stdlib/_abcoll.py diff --git a/third_party/stdlib/_weakrefset.py b/grumpy-runtime-src/third_party/stdlib/_weakrefset.py similarity index 100% rename from third_party/stdlib/_weakrefset.py rename to grumpy-runtime-src/third_party/stdlib/_weakrefset.py diff --git a/third_party/stdlib/abc.py b/grumpy-runtime-src/third_party/stdlib/abc.py similarity index 100% rename from third_party/stdlib/abc.py rename to grumpy-runtime-src/third_party/stdlib/abc.py diff --git a/third_party/stdlib/argparse.py b/grumpy-runtime-src/third_party/stdlib/argparse.py similarity index 100% rename from third_party/stdlib/argparse.py rename to grumpy-runtime-src/third_party/stdlib/argparse.py diff --git a/third_party/stdlib/base64.py b/grumpy-runtime-src/third_party/stdlib/base64.py similarity index 100% rename from third_party/stdlib/base64.py rename to grumpy-runtime-src/third_party/stdlib/base64.py diff --git a/third_party/stdlib/bisect.py b/grumpy-runtime-src/third_party/stdlib/bisect.py similarity index 100% rename from third_party/stdlib/bisect.py rename to grumpy-runtime-src/third_party/stdlib/bisect.py diff --git a/third_party/stdlib/collections.py b/grumpy-runtime-src/third_party/stdlib/collections.py similarity index 100% rename from third_party/stdlib/collections.py rename to grumpy-runtime-src/third_party/stdlib/collections.py diff --git a/third_party/stdlib/colorsys.py b/grumpy-runtime-src/third_party/stdlib/colorsys.py similarity index 100% rename from third_party/stdlib/colorsys.py rename to grumpy-runtime-src/third_party/stdlib/colorsys.py diff --git a/third_party/stdlib/contextlib.py b/grumpy-runtime-src/third_party/stdlib/contextlib.py similarity index 100% rename from third_party/stdlib/contextlib.py rename to grumpy-runtime-src/third_party/stdlib/contextlib.py diff --git a/third_party/stdlib/copy.py b/grumpy-runtime-src/third_party/stdlib/copy.py similarity index 100% rename from third_party/stdlib/copy.py rename to grumpy-runtime-src/third_party/stdlib/copy.py diff --git a/third_party/stdlib/copy_reg.py b/grumpy-runtime-src/third_party/stdlib/copy_reg.py similarity index 100% rename from third_party/stdlib/copy_reg.py rename to grumpy-runtime-src/third_party/stdlib/copy_reg.py diff --git a/third_party/stdlib/csv.py b/grumpy-runtime-src/third_party/stdlib/csv.py similarity index 100% rename from third_party/stdlib/csv.py rename to grumpy-runtime-src/third_party/stdlib/csv.py diff --git a/third_party/stdlib/difflib.py b/grumpy-runtime-src/third_party/stdlib/difflib.py similarity index 100% rename from third_party/stdlib/difflib.py rename to grumpy-runtime-src/third_party/stdlib/difflib.py diff --git a/third_party/stdlib/dircache.py b/grumpy-runtime-src/third_party/stdlib/dircache.py similarity index 100% rename from third_party/stdlib/dircache.py rename to grumpy-runtime-src/third_party/stdlib/dircache.py diff --git a/third_party/stdlib/dummy_thread.py b/grumpy-runtime-src/third_party/stdlib/dummy_thread.py similarity index 100% rename from third_party/stdlib/dummy_thread.py rename to grumpy-runtime-src/third_party/stdlib/dummy_thread.py diff --git a/third_party/stdlib/fnmatch.py b/grumpy-runtime-src/third_party/stdlib/fnmatch.py similarity index 100% rename from third_party/stdlib/fnmatch.py rename to grumpy-runtime-src/third_party/stdlib/fnmatch.py diff --git a/third_party/stdlib/fpformat.py b/grumpy-runtime-src/third_party/stdlib/fpformat.py similarity index 100% rename from third_party/stdlib/fpformat.py rename to grumpy-runtime-src/third_party/stdlib/fpformat.py diff --git a/third_party/stdlib/functools.py b/grumpy-runtime-src/third_party/stdlib/functools.py similarity index 100% rename from third_party/stdlib/functools.py rename to grumpy-runtime-src/third_party/stdlib/functools.py diff --git a/third_party/stdlib/genericpath.py b/grumpy-runtime-src/third_party/stdlib/genericpath.py similarity index 100% rename from third_party/stdlib/genericpath.py rename to grumpy-runtime-src/third_party/stdlib/genericpath.py diff --git a/third_party/stdlib/getopt.py b/grumpy-runtime-src/third_party/stdlib/getopt.py similarity index 100% rename from third_party/stdlib/getopt.py rename to grumpy-runtime-src/third_party/stdlib/getopt.py diff --git a/third_party/stdlib/glob.py b/grumpy-runtime-src/third_party/stdlib/glob.py similarity index 100% rename from third_party/stdlib/glob.py rename to grumpy-runtime-src/third_party/stdlib/glob.py diff --git a/third_party/stdlib/heapq.py b/grumpy-runtime-src/third_party/stdlib/heapq.py similarity index 100% rename from third_party/stdlib/heapq.py rename to grumpy-runtime-src/third_party/stdlib/heapq.py diff --git a/third_party/stdlib/json/__init__.py b/grumpy-runtime-src/third_party/stdlib/json/__init__.py similarity index 100% rename from third_party/stdlib/json/__init__.py rename to grumpy-runtime-src/third_party/stdlib/json/__init__.py diff --git a/third_party/stdlib/json/decoder.py b/grumpy-runtime-src/third_party/stdlib/json/decoder.py similarity index 100% rename from third_party/stdlib/json/decoder.py rename to grumpy-runtime-src/third_party/stdlib/json/decoder.py diff --git a/third_party/stdlib/json/encoder.py b/grumpy-runtime-src/third_party/stdlib/json/encoder.py similarity index 100% rename from third_party/stdlib/json/encoder.py rename to grumpy-runtime-src/third_party/stdlib/json/encoder.py diff --git a/third_party/stdlib/json_scanner.py b/grumpy-runtime-src/third_party/stdlib/json_scanner.py similarity index 100% rename from third_party/stdlib/json_scanner.py rename to grumpy-runtime-src/third_party/stdlib/json_scanner.py diff --git a/third_party/stdlib/keyword.py b/grumpy-runtime-src/third_party/stdlib/keyword.py similarity index 100% rename from third_party/stdlib/keyword.py rename to grumpy-runtime-src/third_party/stdlib/keyword.py diff --git a/third_party/stdlib/linecache.py b/grumpy-runtime-src/third_party/stdlib/linecache.py similarity index 100% rename from third_party/stdlib/linecache.py rename to grumpy-runtime-src/third_party/stdlib/linecache.py diff --git a/third_party/stdlib/md5.py b/grumpy-runtime-src/third_party/stdlib/md5.py similarity index 100% rename from third_party/stdlib/md5.py rename to grumpy-runtime-src/third_party/stdlib/md5.py diff --git a/third_party/stdlib/mimetools.py b/grumpy-runtime-src/third_party/stdlib/mimetools.py similarity index 100% rename from third_party/stdlib/mimetools.py rename to grumpy-runtime-src/third_party/stdlib/mimetools.py diff --git a/third_party/stdlib/mutex.py b/grumpy-runtime-src/third_party/stdlib/mutex.py similarity index 100% rename from third_party/stdlib/mutex.py rename to grumpy-runtime-src/third_party/stdlib/mutex.py diff --git a/third_party/stdlib/optparse.py b/grumpy-runtime-src/third_party/stdlib/optparse.py similarity index 100% rename from third_party/stdlib/optparse.py rename to grumpy-runtime-src/third_party/stdlib/optparse.py diff --git a/third_party/stdlib/pprint.py b/grumpy-runtime-src/third_party/stdlib/pprint.py similarity index 100% rename from third_party/stdlib/pprint.py rename to grumpy-runtime-src/third_party/stdlib/pprint.py diff --git a/third_party/stdlib/quopri.py b/grumpy-runtime-src/third_party/stdlib/quopri.py similarity index 100% rename from third_party/stdlib/quopri.py rename to grumpy-runtime-src/third_party/stdlib/quopri.py diff --git a/third_party/stdlib/random.py b/grumpy-runtime-src/third_party/stdlib/random.py similarity index 100% rename from third_party/stdlib/random.py rename to grumpy-runtime-src/third_party/stdlib/random.py diff --git a/third_party/stdlib/re.py b/grumpy-runtime-src/third_party/stdlib/re.py similarity index 100% rename from third_party/stdlib/re.py rename to grumpy-runtime-src/third_party/stdlib/re.py diff --git a/third_party/stdlib/re_tests.py b/grumpy-runtime-src/third_party/stdlib/re_tests.py similarity index 100% rename from third_party/stdlib/re_tests.py rename to grumpy-runtime-src/third_party/stdlib/re_tests.py diff --git a/third_party/stdlib/repr.py b/grumpy-runtime-src/third_party/stdlib/repr.py similarity index 100% rename from third_party/stdlib/repr.py rename to grumpy-runtime-src/third_party/stdlib/repr.py diff --git a/third_party/stdlib/rfc822.py b/grumpy-runtime-src/third_party/stdlib/rfc822.py similarity index 100% rename from third_party/stdlib/rfc822.py rename to grumpy-runtime-src/third_party/stdlib/rfc822.py diff --git a/third_party/stdlib/sched.py b/grumpy-runtime-src/third_party/stdlib/sched.py similarity index 100% rename from third_party/stdlib/sched.py rename to grumpy-runtime-src/third_party/stdlib/sched.py diff --git a/third_party/stdlib/sha.py b/grumpy-runtime-src/third_party/stdlib/sha.py similarity index 100% rename from third_party/stdlib/sha.py rename to grumpy-runtime-src/third_party/stdlib/sha.py diff --git a/third_party/stdlib/sre_compile.py b/grumpy-runtime-src/third_party/stdlib/sre_compile.py similarity index 100% rename from third_party/stdlib/sre_compile.py rename to grumpy-runtime-src/third_party/stdlib/sre_compile.py diff --git a/third_party/stdlib/sre_constants.py b/grumpy-runtime-src/third_party/stdlib/sre_constants.py similarity index 100% rename from third_party/stdlib/sre_constants.py rename to grumpy-runtime-src/third_party/stdlib/sre_constants.py diff --git a/third_party/stdlib/sre_parse.py b/grumpy-runtime-src/third_party/stdlib/sre_parse.py similarity index 100% rename from third_party/stdlib/sre_parse.py rename to grumpy-runtime-src/third_party/stdlib/sre_parse.py diff --git a/third_party/stdlib/string.py b/grumpy-runtime-src/third_party/stdlib/string.py similarity index 100% rename from third_party/stdlib/string.py rename to grumpy-runtime-src/third_party/stdlib/string.py diff --git a/third_party/stdlib/test/__init__.py b/grumpy-runtime-src/third_party/stdlib/test/__init__.py similarity index 100% rename from third_party/stdlib/test/__init__.py rename to grumpy-runtime-src/third_party/stdlib/test/__init__.py diff --git a/third_party/stdlib/test/list_tests.py b/grumpy-runtime-src/third_party/stdlib/test/list_tests.py similarity index 100% rename from third_party/stdlib/test/list_tests.py rename to grumpy-runtime-src/third_party/stdlib/test/list_tests.py diff --git a/third_party/stdlib/test/lock_tests.py b/grumpy-runtime-src/third_party/stdlib/test/lock_tests.py similarity index 100% rename from third_party/stdlib/test/lock_tests.py rename to grumpy-runtime-src/third_party/stdlib/test/lock_tests.py diff --git a/third_party/stdlib/test/mapping_tests.py b/grumpy-runtime-src/third_party/stdlib/test/mapping_tests.py similarity index 100% rename from third_party/stdlib/test/mapping_tests.py rename to grumpy-runtime-src/third_party/stdlib/test/mapping_tests.py diff --git a/third_party/stdlib/test/seq_tests.py b/grumpy-runtime-src/third_party/stdlib/test/seq_tests.py similarity index 100% rename from third_party/stdlib/test/seq_tests.py rename to grumpy-runtime-src/third_party/stdlib/test/seq_tests.py diff --git a/third_party/stdlib/test/string_tests.py b/grumpy-runtime-src/third_party/stdlib/test/string_tests.py similarity index 100% rename from third_party/stdlib/test/string_tests.py rename to grumpy-runtime-src/third_party/stdlib/test/string_tests.py diff --git a/third_party/stdlib/test/test_argparse.py b/grumpy-runtime-src/third_party/stdlib/test/test_argparse.py similarity index 100% rename from third_party/stdlib/test/test_argparse.py rename to grumpy-runtime-src/third_party/stdlib/test/test_argparse.py diff --git a/third_party/stdlib/test/test_bisect.py b/grumpy-runtime-src/third_party/stdlib/test/test_bisect.py similarity index 100% rename from third_party/stdlib/test/test_bisect.py rename to grumpy-runtime-src/third_party/stdlib/test/test_bisect.py diff --git a/third_party/stdlib/test/test_colorsys.py b/grumpy-runtime-src/third_party/stdlib/test/test_colorsys.py similarity index 100% rename from third_party/stdlib/test/test_colorsys.py rename to grumpy-runtime-src/third_party/stdlib/test/test_colorsys.py diff --git a/third_party/stdlib/test/test_datetime.py b/grumpy-runtime-src/third_party/stdlib/test/test_datetime.py similarity index 100% rename from third_party/stdlib/test/test_datetime.py rename to grumpy-runtime-src/third_party/stdlib/test/test_datetime.py diff --git a/third_party/stdlib/test/test_dict.py b/grumpy-runtime-src/third_party/stdlib/test/test_dict.py similarity index 100% rename from third_party/stdlib/test/test_dict.py rename to grumpy-runtime-src/third_party/stdlib/test/test_dict.py diff --git a/third_party/stdlib/test/test_dircache.py b/grumpy-runtime-src/third_party/stdlib/test/test_dircache.py similarity index 100% rename from third_party/stdlib/test/test_dircache.py rename to grumpy-runtime-src/third_party/stdlib/test/test_dircache.py diff --git a/third_party/stdlib/test/test_dummy_thread.py b/grumpy-runtime-src/third_party/stdlib/test/test_dummy_thread.py similarity index 100% rename from third_party/stdlib/test/test_dummy_thread.py rename to grumpy-runtime-src/third_party/stdlib/test/test_dummy_thread.py diff --git a/third_party/stdlib/test/test_fpformat.py b/grumpy-runtime-src/third_party/stdlib/test/test_fpformat.py similarity index 100% rename from third_party/stdlib/test/test_fpformat.py rename to grumpy-runtime-src/third_party/stdlib/test/test_fpformat.py diff --git a/third_party/stdlib/test/test_genericpath.py b/grumpy-runtime-src/third_party/stdlib/test/test_genericpath.py similarity index 100% rename from third_party/stdlib/test/test_genericpath.py rename to grumpy-runtime-src/third_party/stdlib/test/test_genericpath.py diff --git a/third_party/stdlib/test/test_list.py b/grumpy-runtime-src/third_party/stdlib/test/test_list.py similarity index 100% rename from third_party/stdlib/test/test_list.py rename to grumpy-runtime-src/third_party/stdlib/test/test_list.py diff --git a/third_party/stdlib/test/test_md5.py b/grumpy-runtime-src/third_party/stdlib/test/test_md5.py similarity index 100% rename from third_party/stdlib/test/test_md5.py rename to grumpy-runtime-src/third_party/stdlib/test/test_md5.py diff --git a/third_party/stdlib/test/test_mimetools.py b/grumpy-runtime-src/third_party/stdlib/test/test_mimetools.py similarity index 100% rename from third_party/stdlib/test/test_mimetools.py rename to grumpy-runtime-src/third_party/stdlib/test/test_mimetools.py diff --git a/third_party/stdlib/test/test_mutex.py b/grumpy-runtime-src/third_party/stdlib/test/test_mutex.py similarity index 100% rename from third_party/stdlib/test/test_mutex.py rename to grumpy-runtime-src/third_party/stdlib/test/test_mutex.py diff --git a/third_party/stdlib/test/test_queue.py b/grumpy-runtime-src/third_party/stdlib/test/test_queue.py similarity index 100% rename from third_party/stdlib/test/test_queue.py rename to grumpy-runtime-src/third_party/stdlib/test/test_queue.py diff --git a/third_party/stdlib/test/test_quopri.py b/grumpy-runtime-src/third_party/stdlib/test/test_quopri.py similarity index 100% rename from third_party/stdlib/test/test_quopri.py rename to grumpy-runtime-src/third_party/stdlib/test/test_quopri.py diff --git a/third_party/stdlib/test/test_rfc822.py b/grumpy-runtime-src/third_party/stdlib/test/test_rfc822.py similarity index 100% rename from third_party/stdlib/test/test_rfc822.py rename to grumpy-runtime-src/third_party/stdlib/test/test_rfc822.py diff --git a/third_party/stdlib/test/test_sched.py b/grumpy-runtime-src/third_party/stdlib/test/test_sched.py similarity index 100% rename from third_party/stdlib/test/test_sched.py rename to grumpy-runtime-src/third_party/stdlib/test/test_sched.py diff --git a/third_party/stdlib/test/test_select.py b/grumpy-runtime-src/third_party/stdlib/test/test_select.py similarity index 100% rename from third_party/stdlib/test/test_select.py rename to grumpy-runtime-src/third_party/stdlib/test/test_select.py diff --git a/third_party/stdlib/test/test_slice.py b/grumpy-runtime-src/third_party/stdlib/test/test_slice.py similarity index 100% rename from third_party/stdlib/test/test_slice.py rename to grumpy-runtime-src/third_party/stdlib/test/test_slice.py diff --git a/third_party/stdlib/test/test_stat.py b/grumpy-runtime-src/third_party/stdlib/test/test_stat.py similarity index 100% rename from third_party/stdlib/test/test_stat.py rename to grumpy-runtime-src/third_party/stdlib/test/test_stat.py diff --git a/third_party/stdlib/test/test_string.py b/grumpy-runtime-src/third_party/stdlib/test/test_string.py similarity index 100% rename from third_party/stdlib/test/test_string.py rename to grumpy-runtime-src/third_party/stdlib/test/test_string.py diff --git a/third_party/stdlib/test/test_support.py b/grumpy-runtime-src/third_party/stdlib/test/test_support.py similarity index 100% rename from third_party/stdlib/test/test_support.py rename to grumpy-runtime-src/third_party/stdlib/test/test_support.py diff --git a/third_party/stdlib/test/test_threading.py b/grumpy-runtime-src/third_party/stdlib/test/test_threading.py similarity index 100% rename from third_party/stdlib/test/test_threading.py rename to grumpy-runtime-src/third_party/stdlib/test/test_threading.py diff --git a/third_party/stdlib/test/test_tuple.py b/grumpy-runtime-src/third_party/stdlib/test/test_tuple.py similarity index 100% rename from third_party/stdlib/test/test_tuple.py rename to grumpy-runtime-src/third_party/stdlib/test/test_tuple.py diff --git a/third_party/stdlib/test/test_uu.py b/grumpy-runtime-src/third_party/stdlib/test/test_uu.py similarity index 100% rename from third_party/stdlib/test/test_uu.py rename to grumpy-runtime-src/third_party/stdlib/test/test_uu.py diff --git a/third_party/stdlib/textwrap.py b/grumpy-runtime-src/third_party/stdlib/textwrap.py similarity index 100% rename from third_party/stdlib/textwrap.py rename to grumpy-runtime-src/third_party/stdlib/textwrap.py diff --git a/third_party/stdlib/threading.py b/grumpy-runtime-src/third_party/stdlib/threading.py similarity index 100% rename from third_party/stdlib/threading.py rename to grumpy-runtime-src/third_party/stdlib/threading.py diff --git a/third_party/stdlib/traceback.py b/grumpy-runtime-src/third_party/stdlib/traceback.py similarity index 100% rename from third_party/stdlib/traceback.py rename to grumpy-runtime-src/third_party/stdlib/traceback.py diff --git a/third_party/stdlib/types.py b/grumpy-runtime-src/third_party/stdlib/types.py similarity index 100% rename from third_party/stdlib/types.py rename to grumpy-runtime-src/third_party/stdlib/types.py diff --git a/third_party/stdlib/unittest/__init__.py b/grumpy-runtime-src/third_party/stdlib/unittest/__init__.py similarity index 100% rename from third_party/stdlib/unittest/__init__.py rename to grumpy-runtime-src/third_party/stdlib/unittest/__init__.py diff --git a/third_party/stdlib/unittest_case.py b/grumpy-runtime-src/third_party/stdlib/unittest_case.py similarity index 100% rename from third_party/stdlib/unittest_case.py rename to grumpy-runtime-src/third_party/stdlib/unittest_case.py diff --git a/third_party/stdlib/unittest_loader.py b/grumpy-runtime-src/third_party/stdlib/unittest_loader.py similarity index 100% rename from third_party/stdlib/unittest_loader.py rename to grumpy-runtime-src/third_party/stdlib/unittest_loader.py diff --git a/third_party/stdlib/unittest_result.py b/grumpy-runtime-src/third_party/stdlib/unittest_result.py similarity index 100% rename from third_party/stdlib/unittest_result.py rename to grumpy-runtime-src/third_party/stdlib/unittest_result.py diff --git a/third_party/stdlib/unittest_runner.py b/grumpy-runtime-src/third_party/stdlib/unittest_runner.py similarity index 100% rename from third_party/stdlib/unittest_runner.py rename to grumpy-runtime-src/third_party/stdlib/unittest_runner.py diff --git a/third_party/stdlib/unittest_signals.py b/grumpy-runtime-src/third_party/stdlib/unittest_signals.py similarity index 100% rename from third_party/stdlib/unittest_signals.py rename to grumpy-runtime-src/third_party/stdlib/unittest_signals.py diff --git a/third_party/stdlib/unittest_suite.py b/grumpy-runtime-src/third_party/stdlib/unittest_suite.py similarity index 100% rename from third_party/stdlib/unittest_suite.py rename to grumpy-runtime-src/third_party/stdlib/unittest_suite.py diff --git a/third_party/stdlib/unittest_util.py b/grumpy-runtime-src/third_party/stdlib/unittest_util.py similarity index 100% rename from third_party/stdlib/unittest_util.py rename to grumpy-runtime-src/third_party/stdlib/unittest_util.py diff --git a/third_party/stdlib/urlparse.py b/grumpy-runtime-src/third_party/stdlib/urlparse.py similarity index 100% rename from third_party/stdlib/urlparse.py rename to grumpy-runtime-src/third_party/stdlib/urlparse.py diff --git a/third_party/stdlib/uu.py b/grumpy-runtime-src/third_party/stdlib/uu.py similarity index 100% rename from third_party/stdlib/uu.py rename to grumpy-runtime-src/third_party/stdlib/uu.py diff --git a/third_party/stdlib/warnings.py b/grumpy-runtime-src/third_party/stdlib/warnings.py similarity index 100% rename from third_party/stdlib/warnings.py rename to grumpy-runtime-src/third_party/stdlib/warnings.py diff --git a/third_party/stdlib/weakref.py b/grumpy-runtime-src/third_party/stdlib/weakref.py similarity index 100% rename from third_party/stdlib/weakref.py rename to grumpy-runtime-src/third_party/stdlib/weakref.py diff --git a/tools/benchcmp b/grumpy-runtime-src/tools/benchcmp similarity index 100% rename from tools/benchcmp rename to grumpy-runtime-src/tools/benchcmp diff --git a/tools/coverparse b/grumpy-runtime-src/tools/coverparse similarity index 100% rename from tools/coverparse rename to grumpy-runtime-src/tools/coverparse diff --git a/tools/diffrange b/grumpy-runtime-src/tools/diffrange similarity index 100% rename from tools/diffrange rename to grumpy-runtime-src/tools/diffrange diff --git a/tools/genmake b/grumpy-runtime-src/tools/genmake similarity index 100% rename from tools/genmake rename to grumpy-runtime-src/tools/genmake diff --git a/grumpy-runtime-src/tools/grumpc b/grumpy-runtime-src/tools/grumpc new file mode 100755 index 00000000..a9974b12 --- /dev/null +++ b/grumpy-runtime-src/tools/grumpc @@ -0,0 +1,8 @@ +#!/usr/bin/env python +## Import boilerplate +import os +import sys +from grumpy_tools import cli + +sys.argv = ['grumpy', 'transpile'] + sys.argv[1:] +sys.exit(cli.main()) diff --git a/grumpy-runtime-src/tools/grumprun b/grumpy-runtime-src/tools/grumprun new file mode 100755 index 00000000..788e8891 --- /dev/null +++ b/grumpy-runtime-src/tools/grumprun @@ -0,0 +1,8 @@ +#!/usr/bin/env python +## Import boilerplate +import os +import sys +from grumpy_tools import cli + +sys.argv = ['grumpy', 'run'] + sys.argv[1:] +sys.exit(cli.main()) diff --git a/tools/pkgc.go b/grumpy-runtime-src/tools/pkgc.go similarity index 88% rename from tools/pkgc.go rename to grumpy-runtime-src/tools/pkgc.go index 4b08aac5..93a6fe7d 100644 --- a/tools/pkgc.go +++ b/grumpy-runtime-src/tools/pkgc.go @@ -65,12 +65,26 @@ func getConst(name string, v constant.Value) string { case constant.Int: if constant.Sign(v) >= 0 { if i, exact := constant.Uint64Val(v); exact { - if i > math.MaxInt64 { + if i < math.MaxInt8 { + format = "uint(%s)" + } else if i < math.MaxInt32 { + format = "uint32(%s)" + } else { format = "uint64(%s)" } } else { format = "float64(%s)" } + } else { + if i, exact := constant.Int64Val(v); exact { + if i > math.MinInt8 { + format = "int(%s)" + } else if i > math.MinInt32 { + format = "int32(%s)" + } else { + format = "int64(%s)" + } + } } case constant.Float: format = "float64(%s)" diff --git a/grumpy-runtime-src/tools/pydeps b/grumpy-runtime-src/tools/pydeps new file mode 100755 index 00000000..ad95f5a8 --- /dev/null +++ b/grumpy-runtime-src/tools/pydeps @@ -0,0 +1,8 @@ +#!/usr/bin/env python +import os +import sys + +from grumpy_tools import cli + +sys.argv = ['grumpy', 'depends'] + sys.argv[1:] +sys.exit(cli.main()) diff --git a/grumpy-tools-src/AUTHORS.md b/grumpy-tools-src/AUTHORS.md new file mode 120000 index 00000000..3234d6e0 --- /dev/null +++ b/grumpy-tools-src/AUTHORS.md @@ -0,0 +1 @@ +../AUTHORS.md \ No newline at end of file diff --git a/grumpy-tools-src/CONTRIBUTING.md b/grumpy-tools-src/CONTRIBUTING.md new file mode 120000 index 00000000..44fcc634 --- /dev/null +++ b/grumpy-tools-src/CONTRIBUTING.md @@ -0,0 +1 @@ +../CONTRIBUTING.md \ No newline at end of file diff --git a/grumpy-tools-src/LICENSE b/grumpy-tools-src/LICENSE new file mode 120000 index 00000000..ea5b6064 --- /dev/null +++ b/grumpy-tools-src/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/grumpy-tools-src/README.md b/grumpy-tools-src/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/grumpy-tools-src/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/grumpy-tools-src/grumpy_tools/__init__.py b/grumpy-tools-src/grumpy_tools/__init__.py new file mode 100644 index 00000000..2ecccbad --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +"""Top-level package for Grumpy Tools.""" + +__author__ = """Alan Justino et al.""" +__email__ = 'alan.justino@yahoo.com.br' +__version__ = '0.1.8' diff --git a/grumpy-tools-src/grumpy_tools/benchcmp.py b/grumpy-tools-src/grumpy_tools/benchcmp.py new file mode 100755 index 00000000..be4dafc2 --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/benchcmp.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# 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. + +"""Runs two benchmark programs and compares their results.""" + +import argparse +import subprocess +import sys + + +parser = argparse.ArgumentParser() +parser.add_argument('prog1') +parser.add_argument('prog2') +parser.add_argument('--runs', default=1, type=int, + help='number of times to run each program') + + +def main(args): + results1 = _RunBenchmark(args.prog1) + benchmarks = set(results1.keys()) + results2 = {} + for _ in xrange(args.runs - 1): + _MergeResults(results1, _RunBenchmark(args.prog1), benchmarks) + _MergeResults(results2, _RunBenchmark(args.prog2), benchmarks) + _MergeResults(results2, _RunBenchmark(args.prog2), benchmarks) + for b in sorted(benchmarks): + print b, '{:+.1%}'.format(results2[b] / results1[b] - 1) + + +def _MergeResults(merged, results, benchmarks): + benchmarks = set(benchmarks) + for k, v in results.iteritems(): + if k not in benchmarks: + _Die('unmatched benchmark: {}', k) + merged[k] = max(merged.get(k, 0), v) + benchmarks.remove(k) + if benchmarks: + _Die('missing benchmark(s): {}', ', '.join(benchmarks)) + + +def _RunBenchmark(prog): + """Executes prog and returns a dict mapping benchmark name -> result.""" + try: + p = subprocess.Popen([prog], shell=True, stdout=subprocess.PIPE) + except OSError as e: + _Die(e) + out, _ = p.communicate() + if p.returncode: + _Die('{} exited with status: {}', prog, p.returncode) + results = {} + for line in out.splitlines(): + line = line.strip() + if not line: + continue + parts = line.split() + if len(parts) != 3: + _Die('invalid benchmark output: {}', line) + name, status, result = parts + if status != 'PASSED': + _Die('benchmark failed: {}', line) + try: + result = float(result) + except ValueError: + _Die('invalid benchmark result: {}', line) + results[name] = result + return results + + +def _Die(msg, *args): + if args: + msg = msg.format(*args) + print >> sys.stderr, msg + sys.exit(1) + + +if __name__ == '__main__': + main(parser.parse_args()) diff --git a/grumpy-tools-src/grumpy_tools/cli.py b/grumpy-tools-src/grumpy_tools/cli.py new file mode 100644 index 00000000..660ff2b4 --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/cli.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +"""Console script for grumpy_tools.""" +import os +import sys +from pkg_resources import resource_filename, Requirement, DistributionNotFound + +import click + +from . import grumpc, grumprun, pydeps + + +@click.group('grumpy') +def main(args=None): + """Console script for grumpy_tools.""" + return 0 + + +@main.command('transpile') +@click.argument('script') +@click.option('-m', '-modname', '--modname', default='__main__', help='Python module name') +def transpile(script=None, modname=None): + """ + Translates the python SCRIPT file to Go, then prints to stdout + """ + result = grumpc.main(script=script, modname=modname) + sys.exit(result) + + +@main.command('run') +@click.option('-m', '-modname', '--modname', help='Run the named module') +def run(modname=None): + environ_gopath = os.environ.get('GOPATH', '') + + try: + runtime_gopath = resource_filename( + Requirement.parse('grumpy-runtime'), + 'grumpy_runtime/data/gopath', + ) + except DistributionNotFound: + runtime_gopath = None + + if runtime_gopath and runtime_gopath not in environ_gopath: + gopaths = environ_gopath.split(':') + [runtime_gopath] + new_gopath = ':'.join([p for p in gopaths if p]) # Filter empty ones + if new_gopath: + os.environ['GOPATH'] = new_gopath + + if not runtime_gopath and not environ_gopath: + raise click.ClickException("Could not found the Grumpy Runtime 'data/gopath' resource.\n" + "Is 'grumpy-runtime' package installed?") + + result = grumprun.main(modname=modname) + sys.exit(result) + + +@main.command('depends') +@click.argument('script') +@click.option('-m', '-modname', '--modname', default='__main__', help='Python module name') +def depends(script=None, modname=None): + """ + Translates the python SCRIPT file to Go, then prints to stdout + """ + result = pydeps.main(script=script, modname=modname) + sys.exit(result) + + +if __name__ == "__main__": + import sys + sys.exit(main()) diff --git a/compiler/__init__.py b/grumpy-tools-src/grumpy_tools/compiler/__init__.py similarity index 100% rename from compiler/__init__.py rename to grumpy-tools-src/grumpy_tools/compiler/__init__.py diff --git a/compiler/block.py b/grumpy-tools-src/grumpy_tools/compiler/block.py similarity index 98% rename from compiler/block.py rename to grumpy-tools-src/grumpy_tools/compiler/block.py index 423ded2d..2287fab2 100644 --- a/compiler/block.py +++ b/grumpy-tools-src/grumpy_tools/compiler/block.py @@ -22,11 +22,11 @@ import collections import re -from grumpy.compiler import expr -from grumpy.compiler import util -from grumpy.pythonparser import algorithm -from grumpy.pythonparser import ast -from grumpy.pythonparser import source +from grumpy_tools.compiler import expr +from grumpy_tools.compiler import util +from grumpy_tools.vendor.pythonparser import algorithm +from grumpy_tools.vendor.pythonparser import ast +from grumpy_tools.vendor.pythonparser import source _non_word_re = re.compile('[^A-Za-z0-9_]') diff --git a/compiler/block_test.py b/grumpy-tools-src/grumpy_tools/compiler/block_test.py similarity index 98% rename from compiler/block_test.py rename to grumpy-tools-src/grumpy_tools/compiler/block_test.py index 63376997..56e29d4b 100644 --- a/compiler/block_test.py +++ b/grumpy-tools-src/grumpy_tools/compiler/block_test.py @@ -21,10 +21,10 @@ import textwrap import unittest -from grumpy.compiler import block -from grumpy.compiler import imputil -from grumpy.compiler import util -from grumpy import pythonparser +from grumpy_tools.compiler import block +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import util +from grumpy_tools.vendor import pythonparser class PackageTest(unittest.TestCase): diff --git a/compiler/expr.py b/grumpy-tools-src/grumpy_tools/compiler/expr.py similarity index 98% rename from compiler/expr.py rename to grumpy-tools-src/grumpy_tools/compiler/expr.py index bdc72966..1cc08d10 100644 --- a/compiler/expr.py +++ b/grumpy-tools-src/grumpy_tools/compiler/expr.py @@ -20,7 +20,7 @@ import abc -from grumpy.compiler import util +from grumpy_tools.compiler import util class GeneratedExpr(object): diff --git a/compiler/expr_visitor.py b/grumpy-tools-src/grumpy_tools/compiler/expr_visitor.py similarity index 98% rename from compiler/expr_visitor.py rename to grumpy-tools-src/grumpy_tools/compiler/expr_visitor.py index 267abdf7..1432f6a3 100644 --- a/compiler/expr_visitor.py +++ b/grumpy-tools-src/grumpy_tools/compiler/expr_visitor.py @@ -21,10 +21,10 @@ import contextlib import textwrap -from grumpy.compiler import expr -from grumpy.compiler import util -from grumpy.pythonparser import algorithm -from grumpy.pythonparser import ast +from grumpy_tools.compiler import expr +from grumpy_tools.compiler import util +from grumpy_tools.vendor.pythonparser import algorithm +from grumpy_tools.vendor.pythonparser import ast class ExprVisitor(algorithm.Visitor): diff --git a/compiler/expr_visitor_test.py b/grumpy-tools-src/grumpy_tools/compiler/expr_visitor_test.py similarity index 96% rename from compiler/expr_visitor_test.py rename to grumpy-tools-src/grumpy_tools/compiler/expr_visitor_test.py index 08e392ea..5453847e 100644 --- a/compiler/expr_visitor_test.py +++ b/grumpy-tools-src/grumpy_tools/compiler/expr_visitor_test.py @@ -22,11 +22,11 @@ import textwrap import unittest -from grumpy.compiler import block -from grumpy.compiler import imputil -from grumpy.compiler import shard_test -from grumpy.compiler import stmt -from grumpy import pythonparser +from grumpy_tools.compiler import block +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import shard_test +from grumpy_tools.compiler import stmt +from grumpy_tools.vendor import pythonparser def _MakeExprTest(expr): @@ -237,7 +237,7 @@ def _ParseAndVisitExpr(expr): def _GrumpRun(cmd): - p = subprocess.Popen(['grumprun'], stdin=subprocess.PIPE, + p = subprocess.Popen(['grumpy', 'run'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = p.communicate(cmd) return p.returncode, out diff --git a/compiler/imputil.py b/grumpy-tools-src/grumpy_tools/compiler/imputil.py similarity index 98% rename from compiler/imputil.py rename to grumpy-tools-src/grumpy_tools/compiler/imputil.py index 811a6555..6daafc7d 100644 --- a/compiler/imputil.py +++ b/grumpy-tools-src/grumpy_tools/compiler/imputil.py @@ -24,10 +24,10 @@ import os import os.path -from grumpy.compiler import util -from grumpy import pythonparser -from grumpy.pythonparser import algorithm -from grumpy.pythonparser import ast +from grumpy_tools.compiler import util +from grumpy_tools.vendor import pythonparser +from grumpy_tools.vendor.pythonparser import algorithm +from grumpy_tools.vendor.pythonparser import ast _NATIVE_MODULE_PREFIX = '__go__/' diff --git a/compiler/imputil_test.py b/grumpy-tools-src/grumpy_tools/compiler/imputil_test.py similarity index 99% rename from compiler/imputil_test.py rename to grumpy-tools-src/grumpy_tools/compiler/imputil_test.py index 600afdf0..932fb396 100644 --- a/compiler/imputil_test.py +++ b/grumpy-tools-src/grumpy_tools/compiler/imputil_test.py @@ -25,9 +25,9 @@ import textwrap import unittest -from grumpy.compiler import imputil -from grumpy.compiler import util -from grumpy import pythonparser +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import util +from grumpy_tools.vendor import pythonparser class ImportVisitorTest(unittest.TestCase): diff --git a/compiler/shard_test.py b/grumpy-tools-src/grumpy_tools/compiler/shard_test.py similarity index 100% rename from compiler/shard_test.py rename to grumpy-tools-src/grumpy_tools/compiler/shard_test.py diff --git a/compiler/stmt.py b/grumpy-tools-src/grumpy_tools/compiler/stmt.py similarity index 99% rename from compiler/stmt.py rename to grumpy-tools-src/grumpy_tools/compiler/stmt.py index 8daac1db..c02f2664 100644 --- a/compiler/stmt.py +++ b/grumpy-tools-src/grumpy_tools/compiler/stmt.py @@ -21,13 +21,13 @@ import string import textwrap -from grumpy.compiler import block -from grumpy.compiler import expr -from grumpy.compiler import expr_visitor -from grumpy.compiler import imputil -from grumpy.compiler import util -from grumpy.pythonparser import algorithm -from grumpy.pythonparser import ast +from grumpy_tools.compiler import block +from grumpy_tools.compiler import expr +from grumpy_tools.compiler import expr_visitor +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import util +from grumpy_tools.vendor.pythonparser import algorithm +from grumpy_tools.vendor.pythonparser import ast _NATIVE_TYPE_PREFIX = 'type_' diff --git a/compiler/stmt_test.py b/grumpy-tools-src/grumpy_tools/compiler/stmt_test.py similarity index 97% rename from compiler/stmt_test.py rename to grumpy-tools-src/grumpy_tools/compiler/stmt_test.py index 5f4cb0f5..aa766823 100644 --- a/compiler/stmt_test.py +++ b/grumpy-tools-src/grumpy_tools/compiler/stmt_test.py @@ -23,13 +23,13 @@ import textwrap import unittest -from grumpy.compiler import block -from grumpy.compiler import imputil -from grumpy.compiler import shard_test -from grumpy.compiler import stmt -from grumpy.compiler import util -from grumpy import pythonparser -from grumpy.pythonparser import ast +from grumpy_tools.compiler import block +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import shard_test +from grumpy_tools.compiler import stmt +from grumpy_tools.compiler import util +from grumpy_tools.vendor import pythonparser +from grumpy_tools.vendor.pythonparser import ast class StatementVisitorTest(unittest.TestCase): @@ -545,7 +545,7 @@ def _ParseAndVisit(source): def _GrumpRun(cmd): - p = subprocess.Popen(['grumprun'], stdin=subprocess.PIPE, + p = subprocess.Popen(['grumpy', 'run'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = p.communicate(cmd) return p.returncode, out diff --git a/compiler/util.py b/grumpy-tools-src/grumpy_tools/compiler/util.py similarity index 96% rename from compiler/util.py rename to grumpy-tools-src/grumpy_tools/compiler/util.py index e70ce527..3d517b67 100644 --- a/compiler/util.py +++ b/grumpy-tools-src/grumpy_tools/compiler/util.py @@ -20,11 +20,14 @@ import codecs import contextlib -import cStringIO import string import StringIO import textwrap +try: + string.letters +except AttributeError: + string.letters = string.ascii_letters _SIMPLE_CHARS = set(string.digits + string.letters + string.punctuation + " ") _ESCAPES = {'\t': r'\t', '\r': r'\r', '\n': r'\n', '"': r'\"', '\\': r'\\'} @@ -62,7 +65,7 @@ class Writer(object): """Utility class for writing blocks of Go code to a file-like object.""" def __init__(self, out=None): - self.out = codecs.getwriter('utf8')(out or cStringIO.StringIO()) + self.out = codecs.getwriter('utf8')(out or StringIO.StringIO()) self.indent_level = 0 def getvalue(self): diff --git a/compiler/util_test.py b/grumpy-tools-src/grumpy_tools/compiler/util_test.py similarity index 95% rename from compiler/util_test.py rename to grumpy-tools-src/grumpy_tools/compiler/util_test.py index d129ffa8..a94999da 100644 --- a/compiler/util_test.py +++ b/grumpy-tools-src/grumpy_tools/compiler/util_test.py @@ -20,9 +20,9 @@ import unittest -from grumpy.compiler import block -from grumpy.compiler import imputil -from grumpy.compiler import util +from grumpy_tools.compiler import block +from grumpy_tools.compiler import imputil +from grumpy_tools.compiler import util class WriterTest(unittest.TestCase): diff --git a/grumpy-tools-src/grumpy_tools/coverparse.py b/grumpy-tools-src/grumpy_tools/coverparse.py new file mode 100755 index 00000000..d8b72aba --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/coverparse.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# 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. + +"""Parse a Go coverage file and prints a message for lines missing coverage.""" + +import collections +import re +import sys + + +cover_re = re.compile(r'([^:]+):(\d+)\.\d+,(\d+).\d+ \d+ (\d+)$') + + +def _ParseCover(f): + """Return a dict of sets with uncovered line numbers from a Go cover file.""" + uncovered = collections.defaultdict(set) + for line in f: + match = cover_re.match(line.rstrip()) + if not match: + raise RuntimeError('invalid coverage line: {!r}'.format(line)) + filename, line_start, line_end, count = match.groups() + if not int(count): + for i in xrange(int(line_start), int(line_end) + 1): + uncovered[filename].add(i) + return uncovered + + +def main(): + with open(sys.argv[1]) as f: + f.readline() + uncovered = _ParseCover(f) + for filename in sorted(uncovered.keys()): + for lineno in sorted(uncovered[filename]): + print '{}:{}'.format(filename, lineno) + + +if __name__ == '__main__': + main() diff --git a/grumpy-tools-src/grumpy_tools/diffrange.py b/grumpy-tools-src/grumpy_tools/diffrange.py new file mode 100755 index 00000000..ea60fb0f --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/diffrange.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +# 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. + +"""Convert a unified diff into a list of modified files and line numbers.""" + +import sys + + +class _LineBuffer(object): + """Iterator over lines in a file supporting one-step rewind.""" + + def __init__(self, f): + self._f = f + self._prev = None + self._next = None + + def __iter__(self): + return self + + def next(self): + if self._next is not None: + cur = self._next + else: + cur = self._f.readline() + if not cur: + raise StopIteration + self._next = None + self._prev = cur + return cur + + def Rewind(self): + assert self._prev is not None + self._next = self._prev + self._prev = None + + +def _ReadHunks(buf): + for line in buf: + if not line.startswith('@@'): + break + base = int(line.split()[2].split(',')[0]) + for offset in _ReadHunkBody(buf): + yield base + offset + + +def _ReadHunkBody(buf): + n = 0 + for line in buf: + prefix = line[0] + if prefix == ' ': + n += 1 + elif prefix == '+': + yield n + n += 1 + elif prefix != '-' or line.startswith('---'): + buf.Rewind() + break + + +def main(): + buf = _LineBuffer(sys.stdin) + for line in buf: + if line.startswith('+++'): + filename = line.split()[1] + for n in _ReadHunks(buf): + print '{}:{}'.format(filename, n) + + +if __name__ == '__main__': + main() diff --git a/grumpy-tools-src/grumpy_tools/genmake.py b/grumpy-tools-src/grumpy_tools/genmake.py new file mode 100755 index 00000000..c13465a5 --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/genmake.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python + +# 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. + +"""Generate a Makefile for Python targets in a GOPATH directory.""" + +import argparse +import os +import subprocess +import sys + + +parser = argparse.ArgumentParser() +parser.add_argument('dir', help='GOPATH dir to scan for Python modules') +parser.add_argument('-all_target', default='all', + help='make target that will build all modules') + + +def _PrintRule(target, prereqs, rules): + print '{}: {}'.format(target, ' '.join(prereqs)) + if rules: + print '\t@mkdir -p $(@D)' + for rule in rules: + print '\t@{}'.format(rule) + print + + +def main(args): + try: + proc = subprocess.Popen('go env GOOS GOARCH', shell=True, + stdout=subprocess.PIPE) + except OSError as e: + print >> sys.stderr, str(e) + return 1 + out, _ = proc.communicate() + if proc.returncode: + print >> sys.stderr, 'go exited with status: {}'.format(proc.returncode) + return 1 + goos, goarch = out.split() + + if args.all_target: + print '{}:\n'.format(args.all_target) + + gopath = os.path.normpath(args.dir) + pkg_dir = os.path.join(gopath, 'pkg', '{}_{}'.format(goos, goarch)) + pydir = os.path.join(gopath, 'src', '__python__') + for dirpath, _, filenames in os.walk(pydir): + for filename in filenames: + if not filename.endswith('.py'): + continue + basename = os.path.relpath(dirpath, pydir) + if filename != '__init__.py': + basename = os.path.normpath( + os.path.join(basename, filename[:-3])) + modname = basename.replace(os.sep, '.') + ar_name = os.path.join(pkg_dir, '__python__', basename + '.a') + go_file = os.path.join(pydir, basename, 'module.go') + _PrintRule(go_file, + [os.path.join(dirpath, filename)], + ['grumpc -modname={} $< > $@'.format(modname)]) + recipe = (r"""pydeps -modname=%s $< | awk '{gsub(/\./, "/", $$0); """ + r"""print "%s: %s/__python__/" $$0 ".a"}' > $@""") + dep_file = os.path.join(pydir, basename, 'module.d') + _PrintRule(dep_file, [os.path.join(dirpath, filename)], + [recipe % (modname, ar_name, pkg_dir)]) + go_package = '__python__/' + basename.replace(os.sep, '/') + recipe = 'go tool compile -o $@ -p {} -complete -I {} -pack $<' + _PrintRule(ar_name, [go_file], [recipe.format(go_package, pkg_dir)]) + if args.all_target: + _PrintRule(args.all_target, [ar_name], []) + print '-include {}\n'.format(dep_file) + + +if __name__ == '__main__': + sys.exit(main(parser.parse_args())) diff --git a/tools/grumpc b/grumpy-tools-src/grumpy_tools/grumpc.py similarity index 71% rename from tools/grumpc rename to grumpy-tools-src/grumpy_tools/grumpc.py index 53837738..4ea6440a 100755 --- a/tools/grumpc +++ b/grumpy-tools-src/grumpy_tools/grumpc.py @@ -24,30 +24,22 @@ import sys import textwrap -from grumpy.compiler import block -from grumpy.compiler import imputil -from grumpy.compiler import stmt -from grumpy.compiler import util -from grumpy import pythonparser +from .compiler import block +from .compiler import imputil +from .compiler import stmt +from .compiler import util +from .vendor import pythonparser -parser = argparse.ArgumentParser() -parser.add_argument('script', help='Python source filename') -parser.add_argument('-modname', default='__main__', help='Python module name') - - -def main(args): - for arg in ('script', 'modname'): - if not getattr(args, arg, None): - print >> sys.stderr, '{} arg must not be empty'.format(arg) - return 1 +def main(script=None, modname=None): + assert script and modname, 'Script "%s" or Modname "%s" is empty' % (script,modname) gopath = os.getenv('GOPATH', None) if not gopath: print >> sys.stderr, 'GOPATH not set' return 1 - with open(args.script) as py_file: + with open(script) as py_file: py_contents = py_file.read() try: mod = pythonparser.parse(py_contents) @@ -63,10 +55,10 @@ def main(args): print >> sys.stderr, str(e) return 2 - importer = imputil.Importer(gopath, args.modname, args.script, + importer = imputil.Importer(gopath, modname, script, future_features.absolute_import) - full_package_name = args.modname.replace('.', '/') - mod_block = block.ModuleBlock(importer, full_package_name, args.script, + full_package_name = modname.replace('.', '/') + mod_block = block.ModuleBlock(importer, full_package_name, script, py_contents, future_features) visitor = stmt.StatementVisitor(mod_block, future_node) @@ -87,8 +79,8 @@ def main(args): \tCode = πg.NewCode("", $script, nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) { \t\tvar πR *πg.Object; _ = πR \t\tvar πE *πg.BaseException; _ = πE""") - writer.write_tmpl(tmpl, package=args.modname.split('.')[-1], - script=util.go_str(args.script)) + writer.write_tmpl(tmpl, package=modname.split('.')[-1], + script=util.go_str(script)) with writer.indent_block(2): for s in sorted(mod_block.strings): writer.write('ß{} := πg.InternStr({})'.format(s, util.go_str(s))) @@ -98,9 +90,5 @@ def main(args): \t\treturn nil, πE \t}) \tπg.RegisterModule($modname, Code) - }"""), modname=util.go_str(args.modname)) + }"""), modname=util.go_str(modname)) return 0 - - -if __name__ == '__main__': - sys.exit(main(parser.parse_args())) diff --git a/tools/grumprun b/grumpy-tools-src/grumpy_tools/grumprun.py similarity index 90% rename from tools/grumprun rename to grumpy-tools-src/grumpy_tools/grumprun.py index fd237713..3de483dc 100755 --- a/tools/grumprun +++ b/grumpy-tools-src/grumpy_tools/grumprun.py @@ -29,12 +29,9 @@ import sys import tempfile -from grumpy.compiler import imputil +from .compiler import imputil -parser = argparse.ArgumentParser() -parser.add_argument('-m', '--modname', help='Run the named module') - module_tmpl = string.Template("""\ package main import ( @@ -50,13 +47,12 @@ """) -def main(args): +def main(modname=None): gopath = os.getenv('GOPATH', None) if not gopath: print >> sys.stderr, 'GOPATH not set' return 1 - modname = args.modname workdir = tempfile.mkdtemp() try: if modname: @@ -83,7 +79,7 @@ def main(args): # Compile the dummy script to Go using grumpc. fd = os.open(os.path.join(mod_dir, 'module.go'), os.O_WRONLY | os.O_CREAT) try: - p = subprocess.Popen('grumpc ' + script, stdout=fd, shell=True) + p = subprocess.Popen('grumpy transpile ' + script, stdout=fd, shell=True) if p.wait(): return 1 finally: @@ -106,7 +102,3 @@ def _package_name(modname): if modname.startswith('__go__/'): return '__python__/' + modname return '__python__/' + modname.replace('.', '/') - - -if __name__ == '__main__': - sys.exit(main(parser.parse_args())) diff --git a/grumpy-tools-src/grumpy_tools/grumpy_tools.py b/grumpy-tools-src/grumpy_tools/grumpy_tools.py new file mode 100644 index 00000000..7fbbae4f --- /dev/null +++ b/grumpy-tools-src/grumpy_tools/grumpy_tools.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +"""Main module.""" diff --git a/tools/pydeps b/grumpy-tools-src/grumpy_tools/pydeps.py similarity index 75% rename from tools/pydeps rename to grumpy-tools-src/grumpy_tools/pydeps.py index f0dd45f7..54ed37a8 100755 --- a/tools/pydeps +++ b/grumpy-tools-src/grumpy_tools/pydeps.py @@ -15,28 +15,23 @@ # limitations under the License. """Outputs names of modules imported by a script.""" +from __future__ import absolute_import -import argparse import os import sys -from grumpy.compiler import imputil -from grumpy.compiler import util +from .compiler import imputil +from .compiler import util -parser = argparse.ArgumentParser() -parser.add_argument('script', help='Python source filename') -parser.add_argument('-modname', default='__main__', help='Python module name') - - -def main(args): +def main(script=None, modname=None): gopath = os.getenv('GOPATH', None) if not gopath: print >> sys.stderr, 'GOPATH not set' return 1 try: - imports = imputil.collect_imports(args.modname, args.script, gopath) + imports = imputil.collect_imports(modname, script, gopath) except SyntaxError as e: print >> sys.stderr, '{}: line {}: invalid syntax: {}'.format( e.filename, e.lineno, e.text) @@ -45,7 +40,7 @@ def main(args): print >> sys.stderr, str(e) return 2 - names = set([args.modname]) + names = set([modname]) for imp in imports: if imp.is_native: print imp.name @@ -58,6 +53,3 @@ def main(args): names.add(name) print name - -if __name__ == '__main__': - main(parser.parse_args()) diff --git a/grumpy-tools-src/grumpy_tools/vendor/__init__.py b/grumpy-tools-src/grumpy_tools/vendor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/third_party/pythonparser/LICENSE.txt b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/LICENSE.txt similarity index 100% rename from third_party/pythonparser/LICENSE.txt rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/LICENSE.txt diff --git a/third_party/pythonparser/README.md b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/README.md similarity index 100% rename from third_party/pythonparser/README.md rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/README.md diff --git a/third_party/pythonparser/__init__.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/__init__.py similarity index 100% rename from third_party/pythonparser/__init__.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/__init__.py diff --git a/third_party/pythonparser/algorithm.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/algorithm.py similarity index 100% rename from third_party/pythonparser/algorithm.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/algorithm.py diff --git a/third_party/pythonparser/ast.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/ast.py similarity index 100% rename from third_party/pythonparser/ast.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/ast.py diff --git a/third_party/pythonparser/diagnostic.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/diagnostic.py similarity index 100% rename from third_party/pythonparser/diagnostic.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/diagnostic.py diff --git a/third_party/pythonparser/lexer.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/lexer.py similarity index 100% rename from third_party/pythonparser/lexer.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/lexer.py diff --git a/third_party/pythonparser/parser.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/parser.py similarity index 100% rename from third_party/pythonparser/parser.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/parser.py diff --git a/third_party/pythonparser/source.py b/grumpy-tools-src/grumpy_tools/vendor/pythonparser/source.py similarity index 100% rename from third_party/pythonparser/source.py rename to grumpy-tools-src/grumpy_tools/vendor/pythonparser/source.py diff --git a/grumpy-tools-src/setup.py b/grumpy-tools-src/setup.py new file mode 100644 index 00000000..6bb4f0af --- /dev/null +++ b/grumpy-tools-src/setup.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# 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. + +"""The setup script.""" + +import sys +from setuptools import setup, find_packages + +try: + with open('README.md') as readme_file: + readme = readme_file.read() +except: + readme = '' + +requirements = [ + 'Click>=6.0', + # TODO: Put package requirements here + 'importlib2>=3.5.0.2', + 'click-default-group>=1.2', +] + +setup_requirements = [ + # TODO(alanjds): Put setup requirements (distutils extensions, etc.) here +] + +test_requirements = [ + 'pytest', + # TODO: Put package test requirements here +] + +needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) +if needs_pytest: + setup_requirements += ['pytest-runner'] + + +COMMON_OPTIONS = dict( + version='0.1.8', + description="Grumpy Runtime & Transpiler", + long_description=readme, + author="Dylan Trotter et al.", + maintainer="Alan Justino et al.", + maintainer_email="alan.justino@yahoo.com.br", + url='https://github.com/google/grumpy', + install_requires=requirements, + license="Apache Software License 2.0", + zip_safe=False, + keywords='grumpy_runtime', + python_requires='~=2.7.0', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + "Programming Language :: Python :: 2", + 'Programming Language :: Python :: 2.7', + ], + test_suite='tests', + tests_require=test_requirements, + setup_requires=setup_requirements, +) + +GRUMPY_TOOLS_OPTIONS = dict( + name='grumpy-tools', + packages=find_packages( + exclude=["*.tests", "*.tests.*", "tests.*", "tests"], + ), + include_package_data=False, + entry_points={ + 'console_scripts': [ + 'grumpy=grumpy_tools.cli:main', + ], + }, +) + +GRUMPY_TOOLS_OPTIONS.update(COMMON_OPTIONS) + +setup(**GRUMPY_TOOLS_OPTIONS) diff --git a/grumpy-tools-src/tests/test_grumpy_tools.py b/grumpy-tools-src/tests/test_grumpy_tools.py new file mode 100644 index 00000000..f9d1d2fb --- /dev/null +++ b/grumpy-tools-src/tests/test_grumpy_tools.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Tests for `grumpy_tools` package.""" + +import pytest + +from click.testing import CliRunner + +from grumpy_tools import cli + + +@pytest.fixture +def response(): + """Sample pytest fixture. + + See more at: http://doc.pytest.org/en/latest/fixture.html + """ + # import requests + # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') + + +def test_content(response): + """Sample pytest test function with the pytest fixture as an argument.""" + # from bs4 import BeautifulSoup + # assert 'GitHub' in BeautifulSoup(response.content).title.string + + +def test_command_line_interface(): + """Test the CLI.""" + runner = CliRunner() + result = runner.invoke(cli.main) + assert result.exit_code == 0 + assert 'Usage: ' in result.output + help_result = runner.invoke(cli.main, ['--help']) + assert help_result.exit_code == 0 + assert '--help Show this message and exit.' in help_result.output