Commit Graph

62 Commits

Author SHA1 Message Date
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
Yigong Wang
57064d38dd Prettify hy command helping message 2018-03-29 23:04:22 -04: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
Kodi Arfer
85968e70dd Add mangle and unmangle as core functions 2018-03-13 14:55:55 -04:00
Kodi Arfer
52edad28e2 Overhaul mangling rules 2018-03-13 14:55:53 -04:00
Kodi Arfer
6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Ryan Gonzalez
e0e664c030
Merge branch 'master' into letmacro 2017-11-01 09:39:18 -05:00
gilch
6bb997dbea update astor to 0.6 2017-10-31 14:13:41 -06:00
gilch
a54f6aa38b add hidden &name parameter to macros
The module name allows macros to preexpand their body in the proper
context.
2017-09-23 14:59:43 -06:00
Kodi Arfer
e3e7fa8ce6 Catch exceptions raised by HyREPL.output_fn 2017-08-29 14:54:26 -07:00
Kodi Arfer
850ba03d1f Slightly simplify HyREPL 2017-07-03 17:01:12 -07:00
Kodi Arfer
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer
e478008cce Fix HyMacroExpansionError underline alignment 2017-03-24 11:09:30 -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
e4a7b317e1 Make fn work like lambda and remove lambda (#1228)
* with-decorator: Allow a `setv` form as the form to be decorated

This feature is of dubious value by itself, but it's necessary to allow `defn` to create a lambda instead of a `def`.

* Make `fn` work the same as `lambda`

That is, allow it to generate a `lambda` instead of a `def` statement if the function body is just an expression.

I've removed two uses of with_decorator in hy.compiler because they'd require adding another case to HyASTCompiler.compile_decorate_expression and they have no ultimate effect, anyway.

In a few tests, I've added a meaningless statement in `fn` bodies to force generation of a `def`.

I've removed `test_fn_compiler_empty_function` rather than rewrite it because it seems like a pain to maintain and not very useful.

* Remove `lambda`, now that `fn` does the same thing
2017-02-22 17:36:52 -06:00
Kodi Arfer
ace125ee9b Consolidate hy.models.* and tests/models/* into one file apiece
They were a lot of similar, tiny files.
2017-02-16 19:43:00 -08:00
Jakub Wilk
7aaf5f5330 Fix invalid escape sequences
Fixes:

    hy/cmdline.py:175: DeprecationWarning: invalid escape sequence \_
    tests/lex/test_lex.py:267: DeprecationWarning: invalid escape sequence \s
    tests/compilers/test_compiler.py:45: DeprecationWarning: invalid escape sequence \*

when run against Python 3.6 with warnings enabled.
2017-01-01 00:20:04 +03:00
Kodi Arfer
397fa80380 Revert "Modernized." (#1085) (#1188)
This reverts commit 13b484ce46 and fixes #1183.
2016-12-27 09:09:58 -06:00
Elf M. Sternberg
13b484ce46 Modernized. 2016-12-20 10:54:11 +02:00
Kodi Arfer
55301884a4 Allow hy2py to use standard input instead of a file (#1163)
Fixes #1160.
2016-12-13 20:30:12 +02:00
Kodi Arfer
14fddbe6c3 Give require the same features as import (#1142)
Give `require` the same features as `import`

You can now do (require foo), (require [foo [a b c]]), (require [foo [*]]), and (require [foo :as bar]). The first and last forms get you macros named foo.a, foo.b, etc. or bar.a, bar.b, etc., respectively. The second form only gets the macros in the list.

Implements #1118 and perhaps partly addresses #277.

N.B. The new meaning of (require foo) will cause all existing code that uses macros to break. Simply replace these forms with (require [foo [*]]) to get your code working again.

There's a bit of a hack involved in the forms (require foo) or (require [foo :as bar]). When you call (foo.a ...) or (bar.a ...), Hy doesn't actually look inside modules. Instead, these (require ...) forms give the macros names that have periods in them, which happens to work fine with the way Hy finds and interprets macro calls.

* Make `require` syntax stricter and add tests

* Update documentation for `require`

* Documentation wording improvements

* Allow :as in `require` name lists
2016-11-03 09:35:58 +02:00
Kodi Arfer
a33f80b2ce Allow --version as a synonym for -v
--version is a GNU standard that is also common for non-GNU programs, such as Python.
2016-09-29 09:18:04 -07:00
Andrew Scorpil
7dcc583d63 Fix issue #982: UTF-8 encode error message before passing it to clint. 2015-12-14 21:55:53 +01:00
Ryan Gonzalez
d4764dcc2a Nice-ify errors with hy2py and hyc 2015-10-16 15:00:30 -05:00
Jakub Wilk
3a1af0c219 Fix typos 2015-09-29 22:57:36 +02: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
4bea6dc59e distinguish IOError when loading file from that raised by program itself
Previously, Hy scripts that raised a subclass of IOError would be caught
by code intended to deal with IOErrors raised when Hy couldn't import
the script itself, resulting in either a misleading "Can't open file"
error message, or a misleading TypeError traceback from not being able
to format the "Can't open file" message (for IOErrors for which the
errno attribute was None). This commit (a straightforward implementation
of the idea proposed by @slimetree in #714) introduces a new HyIOError
class, raises that when `import_file_to_hst` can't open the file path,
and catches it in the `cmdline_handler`.

This is believed to fix #513, #714, and #727.
2015-02-16 14:27:18 -08:00
Berker Peksag
8d6f9c3d84 Merge pull request #756 from icholy/master
Fix issues with tab completion.
2015-01-19 19:30:47 +02:00
Ilia Choly
7ef4d37169 Fix completion bugs
* freezing issue
* missing __name__
* reader & macro completion
* improve underscore to dash conversion
* python 3/2 string compatibility
2015-01-19 12:17:12 -05:00
Ilia Choly
925a1dd313 fix typos in koan 2015-01-15 15:06:10 -05:00
Ilia Choly
a5654e33ee Adapt attribute completion from IPython completer 2015-01-14 16:22:17 -05:00
Bob Tolbert
05574f6ad7 Implement -m command line flag to run a module by name 2014-11-26 09:13:45 -07:00
Bob Tolbert
bd661a3ae8 Fix hy2py output on Windows/Python 3
If there are Unicode symbols in the hy2py output (as in
tests/native_test/language.hy) and the user is on Windows, and
the user is using Python3 and the user doesn't have an appropriate
codepage in the terminal for Unicode, then hy2py will fail at
encoding the output.

This fix makes sure that if encoding fails, the bytes output is shown
instead of throwing an exception and failing completely.  This also
allows the hy2py tests to pass on Windows.

If the user does activate an appropriate codepage, for example,

chcp 65001

then the Unicode output will show correctly.

Converted printing code to small function to eliminate some duplicate code
2014-06-23 14:51:02 -06:00
Abhishek L
18a6346d42 Display python version & platform at repl startup
*hy/cmdline.py: At the repl startup the Python implementation & version
 is displayed along with the platform(os) information
2014-05-07 01:04:07 +05:30
Berker Peksag
cdea12b276 Make hy2py public. 2014-04-30 01:51:21 +03: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
Bob Tolbert
05899423df Changing --show_tracebacks to --show-tracebacks 2013-12-31 09:56:03 -07:00
Bob Tolbert
765dba3e56 More updates, including from Foxboron, for errors like (for) 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
Kenan Bölükbaşı
3f590f8916 Reflect parameters of code.InteractiveConsele in HyREPL in order to make hy run inside Blender. 2013-12-29 01:22:16 +02:00
Henrique Carvalho Alves
62bc86a0b5 Fix sys.argv to reflect default Python behaviour
By default, calling the Python REPL without arguments causes
sys.argv to be a non-empty list with an empty string, and some
modules (e.g., pyNN) rely on that.
2013-11-29 23:51:41 -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
Bob Tolbert
e33c27d447 Fixing blank line Flake8 failures 2013-08-24 08:33:13 -06:00
Konrad Hinsen
a3847191b6 Merge branch 'master' into spy-mode 2013-08-20 10:12:23 +02:00
Julien Danjou
e158fba865 Merge pull request #265 from rwtolbert/hyc_args_fix
Add CL handling to hyc
2013-08-20 01:10:44 -07:00
Konrad Hinsen
3321daa4cf Add "spy mode" to REPL
With the command-line option --spy, the Hy REPL prints the Python
equivalent of each expression before evaluating it.
2013-08-19 15:27:55 +02:00
Nicolas Dandrimont
81af09d002 Wire the rply parser
Amend the tests to account for the changes
2013-07-28 17:36:36 +02:00
Bob Tolbert
d960dc963f Add CL handling to hyc
This adds real command line handling to 'hyc' for issue #256

This fix catches missing/unreadable files and prints a nice
error message instead of a nasty stack trace when trying to
compile a non-existent file.

Also add this non-existent file check to hy to prevent the
current stack trace from something like "hy foobarbaz" when
"foobarbaz" doesn't exist.

also changes the failure return value to 2 to match Python.
2013-07-26 08:40:56 -06:00
Bob Tolbert
df7bb1d29a Provide bin scripts for both Windows and *nix
Summary: This update does away with the scripts in bin and changes
setup.py to use entry_points in cmdline.py for the scripts 'hy' and
'hyc'.

This fixes installing and running on Windows.

The tests are updated to run the 'hy' script produced by setup.py
and not from bin/hy. This is more correct and makes the tox tests
run on both Window and *nix.

For running hy or nosetests directly in the source tree, you do have
to run 'python setup.py develop' first. But since tox runs and builds
dists, all tox tests pass on all platforms.

Also, since there is no built-in readline on Windows, the setup.py
only on Windows requires 'pyreadline' as a replacement.

Switched from optparse to argparse in cmdline.py

Instead of trying to manually separate args meant for
hy from args meant for a hy script, this switches from
optparse to argparse for the CLI.

argparse automatically peels out args meant for hy and leaves
the rest, including the user hy script in options.args.

This fixes the issue @paultag found running "hy foo" where
foo is not a real file. Also added a test that makes sure
trying to run a non-existent script exits instead of dropping
the user into the REPL.

Added argparse as setup.py resource (and removed from tox.ini) as well as removed uses of deprecated setf
2013-07-14 09:06:42 -06:00
Paul Tagliamonte
b78be9a594 Jank @olasd's hack, clean up core.
The core shall from now on be only for the core language bits. Macro
 bits shall live in hy.macros and in hy.compiler. This cleans up
 garbage.
2013-07-06 14:00:11 -04:00