Commit Graph

32 Commits

Author SHA1 Message Date
Bob Tolbert
ffd85bcc3e Fixes a long-standing bug in import under Python 3.3 and later.
Our MetaImporter was being inserted at the end of sys.meta_path.
For Python prior to 3.3, this was fine since sys.meta_path
was empty by default. As of the completion of PEP 302 in Py3.3 and
later, there are several importers registered by default. One of
these was trying (and failing) to import simple Hy modules,
resulting in a failure to import anything inside __init__.hy.

This change simply inserts the Hy-specific importer at the front
of the list.

This was noted in issue #620 (great catch @algernon)
2014-12-07 11:02:48 -07:00
Paul Tagliamonte
575388fc13 Merge branch 'master' into pr/397
Conflicts:
	hy/importer.py
2014-01-01 16:40:16 -05:00
Bob Tolbert
5040c29946 Cleaning up some comments from berker 2013-12-31 09:56:03 -07:00
Bob Tolbert
f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Berker Peksag
8120a25c08 Add py_compile.{MAGIC, wr_long} to hy._compat.
Closes #344.
2013-12-29 13:10:36 +02:00
Berker Peksag
f21ddeeded Add hy._compat module.
There was a couple of duplicate imports and type checkings in the
codebase. So I added a new module to unify all Python 2 and 3
compatibility codes.

Also, this is a somewhat common pattern in Python. See Jinja2 for
example:

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/_compat.py
2013-09-29 12:10:08 +03:00
Nicolas Dandrimont
f6aa7e953d Always import __future__.print_statement in hy code
This allows us to drop the print special-casing in the
compiler, and makes behavior consistent in Python2/3.
2013-09-22 15:31:15 +02:00
Morten Linderud
e4ae9880f4 Don't leave cruft around in sys.modules when an import fails.
Closes: #214, #225

Squashed from a bunch of commits by @olasd
2013-07-06 20:37:44 +02:00
Konrad Hinsen
269da19d76 Make macros module-specific.
A macro is available in the module where it was defined and
in any module that does a require of the defining module.
Only macros defined in hy.core are globally available.
Fixes #181
2013-05-16 15:34:14 +02:00
Nicolas Dandrimont
387bc0d9f2 Split eval in two steps to allow eval'ing statements
We compile the evaluated operand, separating the body (statements)
from the expression. We then eval() those separately, and return
the evaluated expression.
2013-05-05 20:42:48 +02:00
Nicolas Dandrimont
e9f7c47663 Do the macro processing in the compiler 2013-05-05 20:42:48 +02:00
John Jacobsen
760774afde Implement import_buffer_to_module 2013-04-24 21:58:42 -04:00
Julien Danjou
7f230fdd10 importer: remove useless import
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-20 22:14:08 +02:00
Julien Danjou
07e99dbd33 importer: doc update, MetaImport refactor
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-20 22:11:53 +02:00
Vladimir Gorbunov
f30e7cd99b Fix hyc 2013-04-13 16:28:37 +04:00
Konrad Hinsen
0c56885d42 Use __future__.division for all Hy code
Fixes #106
Note: This is implemented by replacing all calls to Python's
builtin "compile" function by calls to hy.importer.compile_,
which adds the "future division" flag. Anyone using "compile"
in future work will have to remember this.
2013-04-12 05:23:25 +02:00
Paul R. Tagliamonte
8cc26ba1bf moving to locals; fixing _ast vs ast, adding tests 2013-04-09 21:40:54 -04:00
Paul R. Tagliamonte
73be6afd3a Initial cut of `eval' 2013-04-09 21:33:09 -04:00
Paul R. Tagliamonte
5a96089266 Using backslashes for now; punycode soon. 2013-04-06 21:33:52 -04:00
Paul R. Tagliamonte
e0ed7cac40 Revert "Make HySymbol bytes free!"
This reverts commit 8b144a4f3d.
2013-04-06 20:02:08 -04:00
Julien Danjou
8b144a4f3d Make HySymbol bytes free!
We can know use any amount and type of bytes to build a HyString, meaning we
can use Unicode and UTF-8 for our function and variables.

Eat that, snake!

Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-06 23:37:34 +02:00
Julien Danjou
0eb795b4a5 Check the number of arguments for each function
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-06 19:00:32 +02:00
Paul Tagliamonte
980cd493e0 futzing with a few things 2013-03-21 19:27:34 -04:00
Paul R. Tagliamonte
4cb4e7384e holy shit it's 2013 2013-03-18 10:27:14 -04:00
Paul R. Tagliamonte
cdffc9d9d1 Forcing newlines 2013-03-11 20:40:38 -04:00
Paul R. Tagliamonte
3f29114fe1 Fiddling with the site. 2013-03-10 10:58:31 -04:00
Paul R. Tagliamonte
276df1b103 thinking through some manglers. 2013-03-09 16:34:35 -05:00
Paul R. Tagliamonte
a19d085620 Adding in better things. 2013-03-09 15:10:49 -05:00
Paul Tagliamonte
abf63fca12 fixing up the tests 2013-03-08 18:46:51 -05:00
Paul Tagliamonte
67b803b99a Breaking things to start again. 2013-03-08 18:18:43 -05:00
Paul R. Tagliamonte
9a31fc1f81 Futzin' with some things. 2013-03-04 22:35:07 -05:00
Paul R. Tagliamonte
9e16fb4ca0 Very broken. 2013-03-03 19:40:46 -05:00