Command-Line Interface¶
Hy provides a handful of command-line programs for working with Hy code.
hy¶
hy
is a command-line interface for Hy that in general imitates the program
python
provided by CPython. For example, hy
without arguments launches
the REPL, whereas hy foo.hy a b
runs the Hy program
foo.hy
with a
and b
as command-line arguments. See hy --help
for a complete list of options and Python’s documentation for many details. Here are some Hy-specific details:
- --spy¶
Print equivalent Python code before executing each piece of Hy code in the REPL:
=> (+ 1 2) 1 + 2 3
- --repl-output-fn¶
Set the REPL output function. This can be the name of a Python builtin, mostly likely
repr
, or a dotted name likefoo.bar.baz
. In the latter case, Hy will attempt to import the named object with code like(import foo.bar [baz])
.
hy2py¶
hy2py
is a program to convert Hy source code into Python source code. Use hy2py --help
for usage instructions. It can take its input from standard input, from a filename, or folder name provided as a command-line argument. If it is a folder, the output parameter (–output/-o) must be provided. When the output parameter is provided, the output will be written into the folder or file, otherwise the result is written to standard output.
Warning
hy2py
can execute arbitrary code. Don’t give it untrusted input.
hyc¶
hyc
is a program to compile files of Hy code into Python bytecode. Use hyc --help
for usage instructions. The generated bytecode files are named and placed according to the usual scheme of your Python executable, as indicated by importlib.util.cache_from_source()
.
Warning
hyc
can execute arbitrary code. Don’t give it untrusted input.