diff --git a/AUTHORS b/AUTHORS index 0f5bc7f..311903b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,3 +17,4 @@ * Bob Tolbert * Ralph Möritz * Josh McLaughlin +* Berker Peksag diff --git a/docs/hacking.rst b/docs/hacking.rst index 404f4f3..77e0036 100644 --- a/docs/hacking.rst +++ b/docs/hacking.rst @@ -2,6 +2,8 @@ Hacking on hy =============== +.. highlight:: bash + Join our hyve! ============== @@ -21,24 +23,39 @@ Hack! Do this: -1. create a `Python virtual environment - `_ -2. (optional) go to https://github.com/paultag/hy and fork it -3. get the source code:: +1. create a `virtual environment + `_:: - $ git clone git://github.com/paultag/hy.git + $ virtualenv venv - (or use your fork) -4. install for hacking:: + and activate it:: - $ python setup.py develop + $ . venv/bin/activate -5. install other develop-y requirements:: + or use `virtualenvwrapper `_ + to create and manage your virtual environment:: + + $ mkvirtualenv hy + $ workon hy + +2. get the source code:: + + $ git clone https://github.com/hylang/hy.git + + or use your fork:: + + $ git clone git@github.com:/hy.git +3. install for hacking:: + + $ cd hy/ + $ pip install -e . + +4. install other develop-y requirements:: $ pip install -r requirements-dev.txt -6. do awesome things; make someone shriek in delight/disgust at what - you have wrought +5. do awesome things; make someone shriek in delight/disgust at what + you have wrought. Test! @@ -60,7 +77,7 @@ Document! Documentation is located in ``docs/``. We use `Sphinx `_. -To build the docs in html:: +To build the docs in HTML:: $ cd docs $ make html diff --git a/docs/language/api.rst b/docs/language/api.rst index 9226bc5..3fe8beb 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -24,8 +24,8 @@ languages. * UTF-8 entities will be encoded using `punycode `_ and prefixed with - `hy_`. For instance, `⚘` will become `hy_w7h`, and `♥` will become - `hy_g6h`. + `hy_`. For instance, `⚘` will become `hy_w7h`, `♥` will become `hy_g6h`, + and `i♥u` will become `hy_iu_t0x`. * Symbols that contain dashes will have them replaced with underscores. For example, `render-template` will become `render_template`. diff --git a/hy/util.py b/hy/_compat.py similarity index 86% rename from hy/util.py rename to hy/_compat.py index c0fc193..e30d0dc 100644 --- a/hy/util.py +++ b/hy/_compat.py @@ -19,10 +19,20 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +try: + import __builtin__ as builtins +except ImportError: + import builtins # NOQA import sys +PY3 = sys.version_info[0] >= 3 -if sys.version_info[0] >= 3: +if PY3: str_type = str else: str_type = unicode # NOQA + +if PY3: + long_type = int +else: + long_type = long # NOQA diff --git a/hy/cmdline.py b/hy/cmdline.py index 32afd05..031eb33 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -41,11 +41,7 @@ from hy.models.expression import HyExpression from hy.models.string import HyString from hy.models.symbol import HySymbol - -try: - import __builtin__ as builtins -except ImportError: - import builtins +from hy._compat import builtins class HyQuitter(object): diff --git a/hy/compiler.py b/hy/compiler.py index 90ad043..8830aa3 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -37,7 +37,7 @@ from hy.models.list import HyList from hy.models.dict import HyDict from hy.macros import require, process -from hy.util import str_type +from hy._compat import str_type import hy.importer import traceback @@ -610,7 +610,7 @@ class HyASTCompiler(object): level) imports.update(f_imports) if splice: - to_add = f_contents + to_add = HyExpression([HySymbol("list"), f_contents]) else: to_add = HyList([f_contents]) @@ -966,31 +966,6 @@ class HyASTCompiler(object): col_offset=expression.start_column) return ret - @builds("print") - def compile_print_expression(self, expr): - call = expr.pop(0) # print - values, ret = self._compile_collect(expr) - - if sys.version_info[0] >= 3: - call = self.compile(call) - ret += call - ret += ast.Call(func=call.expr, - args=values, - keywords=[], - starargs=None, - kwargs=None, - lineno=expr.start_line, - col_offset=expr.start_column) - else: - ret += ast.Print( - lineno=expr.start_line, - col_offset=expr.start_column, - dest=None, - values=values, - nl=True) - - return ret - @builds("break") def compile_break_expression(self, expr): ret = ast.Break(lineno=expr.start_line, diff --git a/hy/completer.py b/hy/completer.py index 4a6df63..96c46af 100644 --- a/hy/completer.py +++ b/hy/completer.py @@ -43,15 +43,11 @@ except ImportError: import hy.macros import hy.compiler -try: - import __builtin__ -except ImportError: - import builtins as __builtin__ # NOQA - +from hy._compat import builtins PATH = [hy.compiler._compile_table, hy.macros._hy_macros, - __builtin__.__dict__] + builtins.__dict__] class Completer(object): diff --git a/hy/importer.py b/hy/importer.py index 6831401..b32b71a 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -32,17 +32,15 @@ import ast import os import __future__ -if sys.version_info[0] >= 3: - long_type = int -else: - import __builtin__ - long_type = long # NOQA +from hy._compat import builtins, long_type def ast_compile(ast, filename, mode): """Compile AST. Like Python's compile, but with some special flags.""" - return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION) + flags = (__future__.CO_FUTURE_DIVISION | + __future__.CO_FUTURE_PRINT_FUNCTION) + return compile(ast, filename, mode, flags) def import_buffer_to_hst(buf): @@ -127,10 +125,7 @@ def write_hy_as_pyc(fname): code = ast_compile(_ast, fname, "exec") cfile = "%s.pyc" % fname[:-len(".hy")] - if sys.version_info[0] >= 3: - open_ = open - else: - open_ = __builtin__.open + open_ = builtins.open with open_(cfile, 'wb') as fc: if sys.version_info[0] >= 3: diff --git a/hy/macros.py b/hy/macros.py index baa5e51..b08f1a4 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -26,7 +26,7 @@ from hy.models.integer import HyInteger from hy.models.float import HyFloat from hy.models.complex import HyComplex from hy.models.dict import HyDict -from hy.util import str_type +from hy._compat import str_type from collections import defaultdict diff --git a/hy/models/__init__.py b/hy/models/__init__.py index 775862a..42032ca 100644 --- a/hy/models/__init__.py +++ b/hy/models/__init__.py @@ -24,7 +24,6 @@ class HyObject(object): Generic Hy Object model. This is helpful to inject things into all the Hy lexing Objects at once. """ - pass def replace(self, other): if isinstance(other, HyObject): diff --git a/hy/models/keyword.py b/hy/models/keyword.py index 2d1d48b..f2633a9 100644 --- a/hy/models/keyword.py +++ b/hy/models/keyword.py @@ -20,7 +20,7 @@ from __future__ import unicode_literals from hy.models import HyObject -from hy.util import str_type +from hy._compat import str_type class HyKeyword(HyObject, str_type): diff --git a/hy/models/string.py b/hy/models/string.py index ce0a238..ab7d792 100644 --- a/hy/models/string.py +++ b/hy/models/string.py @@ -19,7 +19,7 @@ # DEALINGS IN THE SOFTWARE. from hy.models import HyObject -from hy.util import str_type +from hy._compat import str_type class HyString(HyObject, str_type): diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 99607a5..a362d66 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -26,7 +26,6 @@ from hy.compiler import hy_compile, HyCompileError, HyTypeError from hy.lex import tokenize import ast -import sys def _ast_spotcheck(arg, root, secondary): @@ -369,10 +368,7 @@ def test_ast_lambda_lists(): def test_ast_print(): code = can_compile("(print \"foo\")").body[0] - if sys.version_info[0] >= 3: - assert type(code.value) == ast.Call - return - assert type(code) == ast.Print + assert type(code.value) == ast.Call def test_ast_tuple(): diff --git a/tests/native_tests/quote.hy b/tests/native_tests/quote.hy index 45c7648..8900578 100644 --- a/tests/native_tests/quote.hy +++ b/tests/native_tests/quote.hy @@ -82,3 +82,14 @@ (setv opt (quote &optional)) (assert (isinstance opt hy.HyLambdaListKeyword)) (assert (= (str opt) "&optional"))) + +(defmacro doodle [&rest body] + `(do ~@body)) + +(defn test-unquote-splice [] + "NATIVE: test unquote-splice does what's intended" + (assert (= + (doodle + [1 2 3] + [4 5 6]) + [4 5 6])))