Skip to content

Commit c968d2a

Browse files
committed
Move pythonparser into grumpy package (#291)
make install was broken since we moved to pythonparser because it was not being copied into the install dir. Rather than just copying it into the PYTHONPATH alongside grumpy, I thought it better to embed it within the grumpy package so that it won't conflict with an installed pythonparser. This addresses: google/grumpy#288
1 parent 86ec508 commit c968d2a

File tree

12 files changed

+28
-36
lines changed

12 files changed

+28
-36
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export PATH := $(ROOT_DIR)/build/bin:$(PATH)
5555

5656
GOPATH_PY_ROOT := $(GOPATH)/src/__python__
5757

58-
PYTHONPARSER_SRCS := $(patsubst third_party/%,$(PY_DIR)/%,$(wildcard third_party/pythonparser/*.py))
58+
PYTHONPARSER_SRCS := $(patsubst third_party/%,$(PY_DIR)/grumpy/%,$(wildcard third_party/pythonparser/*.py))
5959

6060
COMPILER_BIN := build/bin/grumpc
6161
COMPILER_SRCS := $(addprefix $(PY_DIR)/grumpy/compiler/,$(notdir $(shell find compiler -name '*.py' -not -name '*_test.py'))) $(PY_DIR)/grumpy/__init__.py
@@ -217,8 +217,8 @@ $(PYLINT_BIN):
217217
@cd build/third_party && curl -sL https://pypi.io/packages/source/p/pylint/pylint-1.6.4.tar.gz | tar -zx
218218
@cd build/third_party/pylint-1.6.4 && $(PYTHON) setup.py install --prefix $(ROOT_DIR)/build
219219

220-
pylint: $(PYLINT_BIN)
221-
@$(PYTHON) $(PYLINT_BIN) compiler/*.py $(addprefix tools/,benchcmp coverparse diffrange genmake grumpc grumprun pydeps)
220+
pylint: $(PYLINT_BIN) $(COMPILER_SRCS) $(PYTHONPARSER_SRCS) $(COMPILER_BIN) $(RUNNER_BIN) $(TOOL_BINS)
221+
@$(PYTHON) $(PYLINT_BIN) $(COMPILER_SRCS) $(COMPILER_BIN) $(RUNNER_BIN) $(TOOL_BINS)
222222

223223
lint: golint pylint
224224

@@ -284,7 +284,7 @@ $(eval $(foreach x,$(STDLIB_TESTS),$(call GRUMPY_STDLIB_TEST,$(x))))
284284
$(PY_DIR)/weetest.py: lib/weetest.py
285285
@cp -f $< $@
286286

287-
$(PYTHONPARSER_SRCS): $(PY_DIR)/%: third_party/%
287+
$(PYTHONPARSER_SRCS): $(PY_DIR)/grumpy/%: third_party/%
288288
@mkdir -p $(@D)
289289
@cp -f $< $@
290290

@@ -328,4 +328,5 @@ install: $(RUNNER_BIN) $(COMPILER) $(RUNTIME) $(STDLIB)
328328
install -d "$(DESTDIR)"{/usr/lib/go,"$(PY_INSTALL_DIR)"}
329329
cp -rv "$(PY_DIR)/grumpy" "$(DESTDIR)$(PY_INSTALL_DIR)"
330330
# Go package and sources
331+
install -d "$(DESTDIR)/usr/lib/go/"
331332
cp -rv build/pkg build/src "$(DESTDIR)/usr/lib/go/"

compiler/block.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
import collections
2323
import re
2424

25-
from pythonparser import algorithm
26-
from pythonparser import ast
27-
from pythonparser import source
28-
2925
from grumpy.compiler import expr
3026
from grumpy.compiler import util
27+
from grumpy.pythonparser import algorithm
28+
from grumpy.pythonparser import ast
29+
from grumpy.pythonparser import source
3130

3231

3332
_non_word_re = re.compile('[^A-Za-z0-9_]')

compiler/block_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import textwrap
2222
import unittest
2323

24-
import pythonparser
25-
2624
from grumpy.compiler import block
2725
from grumpy.compiler import imputil
2826
from grumpy.compiler import util
27+
from grumpy import pythonparser
2928

3029
class PackageTest(unittest.TestCase):
3130

compiler/expr_visitor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import contextlib
2222
import textwrap
2323

24-
from pythonparser import algorithm
25-
from pythonparser import ast
26-
2724
from grumpy.compiler import expr
2825
from grumpy.compiler import util
26+
from grumpy.pythonparser import algorithm
27+
from grumpy.pythonparser import ast
2928

3029

3130
class ExprVisitor(algorithm.Visitor):

compiler/expr_visitor_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
import textwrap
2323
import unittest
2424

25-
import pythonparser
26-
2725
from grumpy.compiler import block
2826
from grumpy.compiler import imputil
2927
from grumpy.compiler import shard_test
3028
from grumpy.compiler import stmt
29+
from grumpy import pythonparser
3130

3231

3332
def _MakeExprTest(expr):

compiler/imputil.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
import functools
2424
import os
2525

26-
from pythonparser import algorithm
27-
from pythonparser import ast
28-
2926
from grumpy.compiler import util
27+
from grumpy.pythonparser import algorithm
28+
from grumpy.pythonparser import ast
3029

3130

3231
_NATIVE_MODULE_PREFIX = '__go__.'

compiler/imputil_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
import textwrap
2525
import unittest
2626

27-
import pythonparser
28-
2927
from grumpy.compiler import imputil
3028
from grumpy.compiler import util
29+
from grumpy import pythonparser
3130

3231

3332
class ImportVisitorTest(unittest.TestCase):

compiler/stmt.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
import string
2222
import textwrap
2323

24-
from pythonparser import algorithm
25-
from pythonparser import ast
26-
2724
from grumpy.compiler import block
2825
from grumpy.compiler import expr
2926
from grumpy.compiler import expr_visitor
3027
from grumpy.compiler import imputil
3128
from grumpy.compiler import util
29+
from grumpy.pythonparser import algorithm
30+
from grumpy.pythonparser import ast
3231

3332

3433
_NATIVE_TYPE_PREFIX = 'type_'

compiler/stmt_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
import textwrap
2424
import unittest
2525

26-
import pythonparser
27-
from pythonparser import ast
28-
2926
from grumpy.compiler import block
3027
from grumpy.compiler import imputil
3128
from grumpy.compiler import shard_test
3229
from grumpy.compiler import stmt
3330
from grumpy.compiler import util
31+
from grumpy import pythonparser
32+
from grumpy.pythonparser import ast
3433

3534

3635
class StatementVisitorTest(unittest.TestCase):

third_party/pythonparser/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import, division, print_function, unicode_literals
2-
import sys, pythonparser.source, pythonparser.lexer, pythonparser.parser, pythonparser.diagnostic
2+
import sys
3+
from . import source as pythonparser_source, lexer as pythonparser_lexer, parser as pythonparser_parser, diagnostic as pythonparser_diagnostic
34

45
def parse_buffer(buffer, mode="exec", flags=[], version=None, engine=None):
56
"""
@@ -15,13 +16,13 @@ def parse_buffer(buffer, mode="exec", flags=[], version=None, engine=None):
1516
version = sys.version_info[0:2]
1617

1718
if engine is None:
18-
engine = pythonparser.diagnostic.Engine()
19+
engine = pythonparser_diagnostic.Engine()
1920

20-
lexer = pythonparser.lexer.Lexer(buffer, version, engine)
21+
lexer = pythonparser_lexer.Lexer(buffer, version, engine)
2122
if mode in ("single", "eval"):
2223
lexer.interactive = True
2324

24-
parser = pythonparser.parser.Parser(lexer, version, engine)
25+
parser = pythonparser_parser.Parser(lexer, version, engine)
2526
parser.add_flags(flags)
2627

2728
if mode == "exec":
@@ -54,7 +55,7 @@ def parse(source, filename="<unknown>", mode="exec",
5455
:raise: :class:`diagnostic.Error`
5556
if the source code is not well-formed
5657
"""
57-
ast, comments = parse_buffer(pythonparser.source.Buffer(source, filename),
58+
ast, comments = parse_buffer(pythonparser_source.Buffer(source, filename),
5859
mode, flags, version, engine)
5960
return ast
6061

tools/grumpc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ import os
2424
import sys
2525
import textwrap
2626

27-
import pythonparser
28-
2927
from grumpy.compiler import block
3028
from grumpy.compiler import imputil
3129
from grumpy.compiler import stmt
3230
from grumpy.compiler import util
31+
from grumpy import pythonparser
3332

3433

3534
parser = argparse.ArgumentParser()

tools/pydeps

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ import argparse
2020
import os
2121
import sys
2222

23-
import pythonparser
24-
from pythonparser import algorithm
25-
2623
from grumpy.compiler import imputil
2724
from grumpy.compiler import util
25+
from grumpy import pythonparser
26+
from grumpy.pythonparser import algorithm
2827

2928

3029
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)