future-fstrings


Namefuture-fstrings JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/asottile/future-fstrings
SummaryA backport of fstrings to python<3.6
upload_time2019-06-16 03:04:42
maintainer
docs_urlNone
authorAnthony Sottile
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/asottile.future-fstrings?branchName=master)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=15&branchName=master)
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/15/master.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=15&branchName=master)

future-fstrings
===============

A backport of fstrings to python<3.6.


## Installation

`pip install future-fstrings`


## Usage

Include the following encoding cookie at the top of your file (this replaces
the utf-8 cookie if you already have it):

```python
# -*- coding: future_fstrings -*-
```

And then write python3.6 fstring code as usual!

```python
# -*- coding: future_fstrings -*-
thing = 'world'
print(f'hello {thing}')
```

```console
$ python2.7 main.py
hello world
```

## Showing transformed source

`future-fstrings` also includes a cli to show transformed source.

```console
$ future-fstrings-show main.py
# -*- coding: future_fstrings -*-
thing = 'world'
print('hello {}'.format((thing)))
```

## Transform source for micropython

The `future-fstrings-show` command can be used to transform source before
distributing.  This can allow you to write f-string code but target platforms
which do not support f-strings, such as [micropython].

To use this on modern versions of python, install using:

```bash
pip install future-fstrings[rewrite]
```

and then use `future-fstrings-show` as above.

For instance:

```bash
future-fstrings-show code.py > code_rewritten.py
```

[micropython]: https://github.com/micropython/micropython

## How does this work?

`future-fstrings` has two parts:

1. A utf-8 compatible `codec` which performs source manipulation
    - The `codec` first decodes the source bytes using the UTF-8 codec
    - The `codec` then leverages
      [tokenize-rt](https://github.com/asottile/tokenize-rt) to rewrite
      f-strings.
2. A `.pth` file which registers a codec on interpreter startup.

## you may also like

- [future-breakpoint](https://github.com/asottile/future-breakpoint)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/asottile/future-fstrings",
    "name": "future-fstrings",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anthony Sottile",
    "author_email": "asottile@umich.edu",
    "download_url": "https://files.pythonhosted.org/packages/5d/e2/3874574cce18a2e3608abfe5b4b5b3c9765653c464f5da18df8971cf501d/future_fstrings-1.2.0.tar.gz",
    "platform": "",
    "description": "[![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/asottile.future-fstrings?branchName=master)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=15&branchName=master)\n[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/15/master.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=15&branchName=master)\n\nfuture-fstrings\n===============\n\nA backport of fstrings to python<3.6.\n\n\n## Installation\n\n`pip install future-fstrings`\n\n\n## Usage\n\nInclude the following encoding cookie at the top of your file (this replaces\nthe utf-8 cookie if you already have it):\n\n```python\n# -*- coding: future_fstrings -*-\n```\n\nAnd then write python3.6 fstring code as usual!\n\n```python\n# -*- coding: future_fstrings -*-\nthing = 'world'\nprint(f'hello {thing}')\n```\n\n```console\n$ python2.7 main.py\nhello world\n```\n\n## Showing transformed source\n\n`future-fstrings` also includes a cli to show transformed source.\n\n```console\n$ future-fstrings-show main.py\n# -*- coding: future_fstrings -*-\nthing = 'world'\nprint('hello {}'.format((thing)))\n```\n\n## Transform source for micropython\n\nThe `future-fstrings-show` command can be used to transform source before\ndistributing.  This can allow you to write f-string code but target platforms\nwhich do not support f-strings, such as [micropython].\n\nTo use this on modern versions of python, install using:\n\n```bash\npip install future-fstrings[rewrite]\n```\n\nand then use `future-fstrings-show` as above.\n\nFor instance:\n\n```bash\nfuture-fstrings-show code.py > code_rewritten.py\n```\n\n[micropython]: https://github.com/micropython/micropython\n\n## How does this work?\n\n`future-fstrings` has two parts:\n\n1. A utf-8 compatible `codec` which performs source manipulation\n    - The `codec` first decodes the source bytes using the UTF-8 codec\n    - The `codec` then leverages\n      [tokenize-rt](https://github.com/asottile/tokenize-rt) to rewrite\n      f-strings.\n2. A `.pth` file which registers a codec on interpreter startup.\n\n## you may also like\n\n- [future-breakpoint](https://github.com/asottile/future-breakpoint)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A backport of fstrings to python<3.6",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/asottile/future-fstrings"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab6dea1d52e9038558dd37f5d30647eb9f07888c164960a5d4daa5f970c6da25",
                "md5": "9b6ebc3b489e1b68ea4a79985e0c6e96",
                "sha256": "90e49598b553d8746c4dc7d9442e0359d038c3039d802c91c0a55505da318c63"
            },
            "downloads": -1,
            "filename": "future_fstrings-1.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b6ebc3b489e1b68ea4a79985e0c6e96",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 6138,
            "upload_time": "2019-06-16T03:04:40",
            "upload_time_iso_8601": "2019-06-16T03:04:40.395680Z",
            "url": "https://files.pythonhosted.org/packages/ab/6d/ea1d52e9038558dd37f5d30647eb9f07888c164960a5d4daa5f970c6da25/future_fstrings-1.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5de23874574cce18a2e3608abfe5b4b5b3c9765653c464f5da18df8971cf501d",
                "md5": "0221a15b77b426aa6b5049b2b05664e5",
                "sha256": "6cf41cbe97c398ab5a81168ce0dbb8ad95862d3caf23c21e4430627b90844089"
            },
            "downloads": -1,
            "filename": "future_fstrings-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0221a15b77b426aa6b5049b2b05664e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 5786,
            "upload_time": "2019-06-16T03:04:42",
            "upload_time_iso_8601": "2019-06-16T03:04:42.651982Z",
            "url": "https://files.pythonhosted.org/packages/5d/e2/3874574cce18a2e3608abfe5b4b5b3c9765653c464f5da18df8971cf501d/future_fstrings-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-06-16 03:04:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asottile",
    "github_project": "future-fstrings",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "future-fstrings"
}
        
Elapsed time: 0.56585s