Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Built Status ReadTheDocs Coveralls PyPI-Server Project generated with PyScaffold

texted

Compact domain specific language (DSL) for editing blocks of plain text

texted is a line-oriented DSL that focus on simple text editing operations, operating on independent chunks of text (for example commenting/uncommenting lines).

It is not suitable for complex changes. If you need those, please consider using a library that is syntax-aware, like configupdater for .ini/.cfg files, tomlkit for .toml and libCST or refactor for Python files.

Installation

You can install texted with the help of pip:

$ pip install texted

After doing that you will be able to use texted in your Python scripts.

Quickstart

Using texted involves the following workflow:

  1. Select the relevant lines of a given text.

  2. Perform an edition operation over the selection.

This is workflow is shown in the example below:

>>> from texted import edit, find, until, contains, startswith, blank, remove_prefix
>>> example = """\
... # [testenv:typecheck]
... # deps = mypy
... # commands = python -m mypy {posargs:src}
... [testenv:docs]
... deps = sphinx
... changedir = docs
... commands = python -m sphinx -W --keep-going . {toxinidir}/build/html
... """
>>> new_text = edit(
...    example,
...    find(contains("[testenv:typecheck]")) >> until(startswith("[testenv") | blank),
...    remove_prefix("# "),
... )
>>> print(new_text)
[testenv:typecheck]
deps = mypy
commands = python -m mypy {posargs:src}
[testenv:docs]
deps = sphinx
changedir = docs
commands = python -m sphinx -W --keep-going . {toxinidir}/build/html

One of the most basic kinds of select operations can be created with find. This operation will select the first line that matches a criteria. For example:

find(lambda line: "[testenv:typecheck]" in line)

… will select the first line of a text that contains the "[testenv:typecheck]" string. We can then extend (>>) this selection for all the contiguous lines that are not empty with:

find(lambda line: "[testenv:typecheck]" in line) >> whilist(bool)
# => bool is handy! bool("") == False, bool("not empty") == True

After you have selected the block of lines, you can apply a edit operation. For example:

add_prefix("# ")  # => equivalent to: replace(lambda line: "# " + line)

… will add the prefix "# " to all the non empty lines in the selection.

Note that all these functions are lazy and don’t do anything until they are called with edit.

Note

This project has been set up using PyScaffold 4.4. For details and usage information on PyScaffold see https://pyscaffold.org/.

Metadata

Release files for texted 0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for texted 0b1
File Size Uploaded Provenance
texted-0b1.tar.gz 31.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for texted 0b1
File Interpreter ABI Platform
texted-0b1-py3-none-any.whl Python 3 none any Details

Total release size: 45.1 kB

Release files / texted-0b1.tar.gz

Download URL texted-0b1.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e31cad8bf8660fc536e10ba26404740c3d29b8d32c7e4cfade3790a0e5404916
BLAKE2b-256 checksum
How to use checksums
371d35e2800b0110df8cf408bc836124a65c149f4858b0e4bebd0f623e2a77c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / texted-0b1-py3-none-any.whl

Download URL texted-0b1-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3baec2e8be1abb125b731e1a098d4f9f8faae2198ffc36e55e8b2677ae739c3d
BLAKE2b-256 checksum
How to use checksums
cc2a3955c8d9a2e8a9851fd5123f4b7bb35e8b001166ed84a29fb70dd650a647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for texted 0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page