Commit Graph

67 Commits

Author SHA1 Message Date
Kodi Arfer
ecf0352d37 Remove aliases: builtins, FileNotFoundError 2019-06-04 14:01:59 -04:00
Kodi Arfer
5c7441b011 Remove non-native tests of Python 2 2019-06-04 14:01:59 -04:00
Brandon T. Willard
4ae4baac2a Cache command line source for exceptions
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang/hy#1397.
2019-02-07 13:45:41 -05:00
Brandon T. Willard
fb6feaf082 Improve correspondence with Python errors and console behavior
Compiler and command-line error messages now reflect their Python counterparts.
E.g. where Python emits a `SyntaxError`, so does Hy; same for `TypeError`s.
Multiple tests have been added that check the format and type of raised
exceptions over varying command-line invocations (e.g. interactive and not).

A new exception type for `require` errors was added so that they can be treated
like normal run-time errors and not compiler errors.

The Hy REPL has been further refactored to better match the class-structured
API.  Now, different error types are handled separately and leverage more base
class-provided functionality.

Closes hylang/hy#1486.
2019-02-07 13:45:41 -05:00
Brandon T. Willard
51c7efe6e8 Retain compiled source and file information for exceptions
This commit refactors the exception/error classes and their handling.
It also retains Hy source strings and their originating file information, when
available, all throughout the core parser and compiler functions.

As well, with these changes, calling code is no longer responsible for providing
source and file details to exceptions,

Closes hylang/hy#657.
2019-02-07 13:43:58 -05:00
Kodi Arfer
62638b44a3 Update copyright years 2019-02-07 08:57:35 -05:00
Brandon T. Willard
144a7fa240 Produce Python AST for require statements and skip self requires
Closes hylang/hy#1211.
2018-11-08 22:57:17 -06:00
Brandon T. Willard
c0c5c9c699 Make cmdline Hy process unknown filetypes as Hy source
This change a Hy-preferring `runhy` that is used by cmdline Hy.  Standard
`runpy` is still patched so that it can run `.hy` files, but the default
behaviour for unknown filetypes is preserved (i.e. assume they are Python
source).

Closes hylang/hy#1677.
2018-09-24 16:27:50 -04:00
Brandon T. Willard
cbaba4a10a Use Python cmdline file-relative sys.path
Closes hylang/hy#1457.
2018-08-26 00:27:21 -05:00
Brandon T. Willard
c022abc831 Add Python cmdline bytecode option and set sys.executable
Closes hylang/hy#459.
2018-08-26 00:17:12 -05:00
Brandon T. Willard
4839acadf7 Add tests for importing __main__.hy files
Closes hylang/hy#1466.
2018-08-25 22:50:45 -05:00
Brandon T. Willard
87a5b117a1 Implement new importer using PEP-302 semantics
Python 3.x is patched in a way that integrates `.hy` source files into
Pythons default `importlib` machinery.  In Python 2.7, a PEP-302 "importer"
and "loader" is implemented according to the standard `import` logic (via
`pkgutil` and later pure-Python `imp` package code).

In both cases, the entry-point for the loaders is through `sys.path_hooks` only.
As well, the import semantics have been updated all throughout to utilize
`importlib` and follow aspects of PEP-420.  This, along with some light
patches, should allow for basic use of `runpy`, `py_compile` and `reload`.

In all cases, if a `.hy` file is shadowed by a `.py`, Hy will silently use
`.hy`.
2018-08-25 22:50:38 -05:00
Kodi Arfer
9c6714c176 Remove unused imports 2018-06-30 11:04:11 -07:00
Simon Gomizelj
fa54884131 Fix unit tests when run with PYTHONDONTWRITEBYTECODE
When set, it will conflict with any tests that generate bytecode
because they don't expect it to be set.

Fixable by sanitize the environment before forking, but we can't do
anything about import tests.

This is a pipenv default, and possibly a sane flag to set while doing
Hy development, so lets not let it be a hazard for developers to trip
over.
2018-04-14 12:12:01 -07:00
Kodi Arfer
f332ad2eae Improve testing of hy2py
Instead of just checking that hy2py outputs a nonempty string and doesn't crash, we check that a hy2py-generated Python program works the same as the original Hy program.

This test suggests my plan to make hy2py output real Python has succeeded, so I updated NEWS accordingly.
2018-04-08 15:35:57 -07:00
Yigong Wang
be8537c0cf Add recent REPL results globals *i and most recent error *e
This comment add *1, *2, *3 as globals for recent REPL results.
*e global is also added for the most recent error object.
2018-04-02 00:21:13 -04:00
Yigong Wang
4073c78069 Add -E support for Hy REPL
This commit adds -E support for Hy. Similar to Python, hy will ignore
all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME,
that might be set.
2018-03-31 15:16:40 -07:00
Simon Gomizelj
75af667fa1 Fix test_hy2py not respecting 'only_py36' 2018-03-22 13:27:56 -07:00
Kodi Arfer
3c97d2982c Use *1 instead of _ for REPL history
`_`, as a variable, is now the shadow subtraction operator.
2018-03-13 14:56:47 -04:00
Simon Gomizelj
7b87d42221 Properly teardown subprocesses when testing 2018-02-14 15:38:47 -05:00
Kodi Arfer
6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
gilch
6bb997dbea update astor to 0.6 2017-10-31 14:13:41 -06:00
Kodi Arfer
39785b4657 Fix a crash in HyTypeError.__str__ 2017-09-20 10:40:52 -07:00
gilch
50c21ca38c disable Popen shell option in test_bin.py
Fix failing tests from #1289 caused by bad quoting for Windows shell
Improve test_bin_hy_builtins and warn that it fails from IPython.
2017-09-05 13:35:22 -06:00
Kodi Arfer
e3e7fa8ce6 Catch exceptions raised by HyREPL.output_fn 2017-08-29 14:54:26 -07:00
Kodi Arfer
2d863abc85 Implement #* and #** unpacking 2017-07-17 13:34:39 -07:00
Kodi Arfer
f2278cf2f0 Support PYTHONDONTWRITEBYTECODE 2017-06-26 19:00:08 -06:00
Kodi Arfer
399e7628b4 Parametrize test_bin_hy_byte_compile 2017-06-26 18:58:51 -06:00
gilch
aa08149712 Use universal newlines in test_bin.py
Change run_cmd() implementation in test_bin.py to use universal newlines (text mode) for Windows compatibility.
2017-06-18 16:05:44 -06:00
Kodi Arfer
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer
2b11b9be20 Automatically read and write bytecode
Importing or executing a Hy file now loads the byte-compiled version if it exists and is up to date, and if not, the source is byte-compiled after it's parsed.

This change can speed up Hy a lot. Here are some examples comparing run times of the current master (491b474e) to this commit, on my laptop with Python 3.6:

- `nosetests --exclude='test_bin'` goes from 3.8 s to 0.7 s (a 5-fold speedup)
- `hy -c '(print "hello world")` goes from 0.47 s to 0.20 s (a 2-fold speedup)
- Rogue TV's startup goes from 3.6 s to 0.4 s (a 9-fold speedup)

Accompanying changes include:

- `setup.py` now creates and installs bytecode for `hy.core`, `hy.contrib`, and `hy.extra`.
- The `hyc` command under Python 3 now creates bytecode in `__pycache__`, as usual for Python 3, instead of putting the `.pyc` right next to the source file like Python 2 does.

I've removed a test of `hy.extra.anaphoric.a-if` that triggers #1268 when the test file is byte-compiled and then hits some weird `macroexpand` bug or something when I try to work around that—Nose crashes when trying to produce an error message, and I can't seem to replicate the bug without Nose.
2017-04-14 13:38:33 -07:00
Kodi Arfer
a7085138f6 Add tests for #533 2017-03-30 16:10:34 -07:00
Kodi Arfer
e478008cce Fix HyMacroExpansionError underline alignment 2017-03-24 11:09:30 -07:00
Kodi Arfer
ca1bd0ffd3 Add a test for as-> in the REPL
Closes #1255.
2017-03-24 09:03:55 -07:00
Kodi Arfer
33a696d487 Add a command-line option --repl-output-fn (especially for hy.contrib.hy-repr) 2017-03-24 09:03:12 -07:00
Kodi Arfer
32e76caafe Refactor test_bin 2017-03-24 08:43:53 -07:00
Kodi Arfer
d649147b0c Minor test reorganization
This removes two singleton directories.
2017-02-24 12:47:35 -08:00
Nathan Woodrow
a3ad4df6a1 Run file using hy -i
Add test for -i using file
2015-02-28 18:11:42 +10:00
Zack M. Davis
0fd6ed052c move imports and operators to satisfy new version of pep8 checker
jcrocholl/pep8 (used by flake8, used in Hy's continuous integration
builds) introduced an imports-at-top-of-file check in 1.6.0 and a
line-breaks-around-binary-operators check in 1.6.2. This commit makes
nonfunctional changes to bring the Hy codebase in compliance with this
tool, fixing #764.
2015-02-16 22:21:49 -08:00
Bob Tolbert
05574f6ad7 Implement -m command line flag to run a module by name 2014-11-26 09:13:45 -07:00
Ryan Gonzalez
c88e75251c Fix Travis failures 2014-11-05 21:01:10 -06:00
Nicolas Dandrimont
aafb16d69f Merge branch 'master' into pr/584 2014-08-18 18:18:25 +02:00
Tuukka Turto
b1a928037e Merge branch 'master' into pr/526 2014-05-02 10:34:37 +03:00
Allison Kaptur
caa53fb095 Tests for explicit exception chaining
This also breaks out the PY3 only tests into their own file.  We need to do this because raise from is a syntax error in PY2, so we can't rely on the previous hack of catching a HyCompileError - it would compile fine through Hy and then be a syntax error in Python.
2014-05-01 16:33:10 -04:00
Berker Peksag
cdea12b276 Make hy2py public. 2014-04-30 01:51:21 +03:00
Christopher Allan Webber
774aad2ca8 defmain macro; handles the whole if __name__ == __main__ / main function dance
Example:

  (defmain [&rest args]
    (print "now we're having a fun time!")
    (print args))

Which outputs:

  $ hy test.hy
  now we're having a fun time!
  (['test.hy'],)

Includes documentation and tests.
2014-04-10 13:58:38 -05:00
Bob Tolbert
bb567aab3e Enabling hy2py test on Windows 2014-03-14 10:21:07 -04:00
Nicolas Dandrimont
4022203496 Merge branch 'master' into pr/440 2014-01-17 20:20:39 +01:00
Gergely Nagy
a619295dd7
bin/hy2py: Add a bunch of command-line options
The hy2py tool has been very useful for me, but most of the time, it's
only a part of its output that one is interested in. The whole output,
with source code, AST and python code together is one big monstrosity.
So instead of printing all that, lets have a few handy command-line
options to control which part gets printed.

By default, only the generated python source is, as that's what the name
of the tool implies.

Also, don't run it. That's what hy is for.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-14 09:17:56 +01:00
Gergely Nagy
5b78735011 hy/cmdline.py: Add support for running with --spy -i
There's no reason why one would need to choose between --spy and -i, so
pass down options.spy to run_icommand, and then to HyREPL, so we can
have both.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
2014-01-13 22:12:32 +01:00