Metadata-Version: 2.4
Name: f-codec
Version: 0.1.2
Summary: Python 'f' Codec
Author-email: Vitaly Kravtsov <in4lio@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/in4lio/f-codec
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Python `f` Codec

Wrap lonesome f-strings in `print()`.

## How to install

```sh
> python3 -m pip install f-codec
```

## Why?

```python
# -*- coding: f -*-

def dictionary(inst, depth=0):
    ಠ_ಠ = '    ' * depth

    f''' {{
'''

    for name, val in inst.items():
        if isinstance(val, dict):
            f'''
    {name} =
''' > ಠ_ಠ
            dictionary(val, depth + 1)
        else:
            f'''
    {name} = {val},
''' > ಠ_ಠ

    f'''
}}
''' > ಠ_ಠ

decl = {
    'a': 1,
    'b': 2,
    'c': { 'a': 3, 'b': 4 },
    'd': { 'a': 5, 'b': { 'a': 6, 'b': 7 }, 'c': 8 },
    'e': 9
}

f'''
decl =
'''
dictionary(decl)
```

```sh
> python3 test.py

decl = {
    a = 1,
    b = 2,
    c = {
        a = 3,
        b = 4,
    }
    d = {
        a = 5,
        b = {
            a = 6,
            b = 7,
        }
        c = 8,
    }
    e = 9,
}
```

## Development

```sh
> python3 -m unittest test_fcodec -v  # run the regression suite
> uv build                            # build sdist and wheel into dist/
```

The test suite compares decoding against golden files in `tests/golden/`,
which lock in the exact transformation of known-good sources.

## TODO
- true streaming support for `IncrementalDecoder` (currently it buffers the whole input and decodes at once)
- skip f-string if the previous line ends with "\" and it isn't a comment
- skip f-string inside another string
- support for `''' > indent` on a single-line f-string (only whitespace or a comment may follow the closing quotes)
- support for triple-quoted strings inside an `''' > indent` expression
- preserve CRLF line endings (currently normalized to LF)
