Metadata-Version: 2.4
Name: beautifhy
Version: 1.1.0
Summary: A Hy pretty-printer / code formatter / beautifier.
Author-email: Ati Sharma <ati+beautifhy@agalmic.ltd>
License: MIT License
        
        Copyright (c) 2024 the authors.
        
        Permission is hereby granted, free of charge, to any person obtaining a
        copy of this software and associated documentation files (the "Software"),
        to deal in the Software without restriction, including without limitation
        the rights to use, copy, modify, merge, publish, distribute, sublicense,
        and/or sell copies of the Software, and to permit persons to whom the
        Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
        THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
        FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
        DEALINGS IN THE SOFTWARE.
        
Project-URL: Repository, https://github.com/atisharma/beautifhy
Keywords: hy,hylang,utilities,automation,formatter
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Lisp
Classifier: Programming Language :: Hy
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: AUTHORS
Requires-Dist: hy>=1.0.0
Requires-Dist: hyrule>=1.0.0
Requires-Dist: toolz
Requires-Dist: multimethod>=2.0
Provides-Extra: hylight
Requires-Dist: pygments; extra == "hylight"
Dynamic: license-file

## 🦑 Beautifhy

*A Hy beautifier / code formatter / pretty-printer.*

Probably compatible with Hy 1.0.0 and later.


### Install

```bash
$ pip install -U beautifhy
```

If you want syntax highlighting available (which requires pygments), do instead

```bash
$ pip install -U beautifhy[hylight]
```


### Usage

From the command line, to pretty-print the file `core.hy`:
```bash
$ beautifhy core.hy
```
gives the output

```hylang
(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
```bash
$ hylight core.hy
```

You can use stdin and pipe by replacing the filename with `-`:
```bash
$ beautifhy core.hy | hylight -
```
which will pretty-print `core.hy` and then syntax highlight the output.
