A Hy pretty-printer / code formatter / beautifier.
Project description
🦑 Beautifhy
A Hy beautifier / code formatter / pretty-printer.
Probably compatible with Hy 1.0.0 and later.
Install
$ pip install -U beautifhy
If you want syntax highlighting available (which requires pygments), do instead
$ pip install -U beautifhy[hylight]
Usage
From the command line, to pretty-print the file core.hy:
$ beautifhy core.hy
gives the output
(import toolz [first second last])
;; * Utility things
;; -----------------------------------------
(defmacro defmethod [#* args]
"Define a multimethod (using multimethod.multimethod).
For example, the Hy code
`(defmethod f [#^ int x #^ float y]
(// x (int y)))`
is equivalent to the following Python code:
`@multimethod
def f(x: int, y: float):
return await x // int(y)`
You can also define an asynchronous multimethod:
`(defmethod :async f [#* args #** kwargs]
(await some-async-function #* args #** kwargs))`
"
(if (= :async (first args))
(let [f (second args) body (cut args 2 None)]
`(defn :async [hy.I.multimethod.multimethod] ~f ~@body))
(let [f (first args) body (cut args 1 None)]
`(defn [hy.I.multimethod.multimethod] ~f ~@body))))
(defn slurp [fname #** kwargs]
"Read a file and return as a string.
kwargs can include mode, encoding and buffering, and will be passed
to open()."
(let [f (if (:encoding kwargs None) hy.I.codecs.open open)]
(with [o (f fname #** kwargs)]
(o.read))))
(defmacro rest [xs]
"A slice of all but the first element of a sequence."
`(cut ~xs 1 None))
To apply syntax highlighting (no pretty-printing), do
$ hylight core.hy
You can use stdin and pipe by replacing the filename with -:
$ beautifhy core.hy | hylight -
which will pretty-print core.hy and then syntax highlight the output.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file beautifhy-1.1.1.tar.gz.
File metadata
- Download URL: beautifhy-1.1.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74595a6fbc6b6a34152c91b58dd33ae4a7bca3c8261ce9e484d9dc0f65b6dca5
|
|
| MD5 |
0b8b2a59d7b6d011de0e9984f8ee46a2
|
|
| BLAKE2b-256 |
8d725ba4f31fa30a5046c9a2859eb6245ab862cafabda8140e0aff6c41b30e69
|
File details
Details for the file beautifhy-1.1.1-py3-none-any.whl.
File metadata
- Download URL: beautifhy-1.1.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcb20f4edd51d17a278d775ed49c6b12aedba7ec58d999e75fd77247bd6a303f
|
|
| MD5 |
77545f84f19a24fc090fadd9cb7eec84
|
|
| BLAKE2b-256 |
cf58119510273d13a06c8a831199dc8b12f6f627d7bfa160ea651fbc16ba1fe9
|