Skip to main content

Python-based command line tool to replace text/code in files

Project description

librep - LIne Block REPlacement

Code style: black PyPI version

librep is a python-based command-line tools allows to render file placeholders. It replaces a placeholder of a given syntax with the content of the file that is specified in the placeholder.

The tool is independent of the document type, since it is assumed that the chosen syntax does not interfere with the syntax of any (especially markup) language.

The indentation of the placeholder is used for the whole inserted code/text block.

Usage

Insert a placeholder of the following syntax inside a file:

§§§<filename>:<start>:<end>§§§

Afterwards, you can render the placeholder by running

$ librep -i "file_with_placeholder.md"

This will replace the original line in the file file_with_placeholder.md with the content of the file <filename> from line <start> to line <end>. The filename has to either be absolute or relative to the file you specify the placeholder in.

Using a URL instead of a file from the repository

If you want to link a file that is not present on your machine, but you have a URL to that exact file, you can use the following syntax:

§§§url="<url>":<start>:<end>§§§

Note that this requires wget to be installed on your machine

Example

This file file_with_placeholders.md

# Heading

Check out this awesome python code!
```py
§§§./code.py§§§
```

Can be processed with librep by doing

$ librep -i "file_with_placeholder.md"

Which results in

# Heading

Check out this awesome python code!
```py
def calc_sum(a, b):
    """Calculates the sum of a+b
    Parameters
    ----------
    a : float, int
        First number
    b : float, int
        Second number
    Returns
    -------
    sum : float
        Sum of a and b
    """

    return a + b
```

Examples

Below you can find different versions for inserting different parts of the file examples/plotting/plot_rocs.py into your markdown file.

Placeholder Result
§§§examples/file.py§§§ whole file
§§§examples/file.py::§§§ whole file
§§§examples/file.py:10:20§§§ from line 10 to line 20
§§§examples/file.py::10§§§ from top to line 10
§§§examples/file.py:10§§§ from line 10 to bottom
§§§examples/file.py:10:§§§ from line 10 to bottom

Installation

librep can simply be installed using pip install:

pip install librep
# or
pip install https://github.com/umami-hep/librep/archive/master.tar.gz

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

librep-0.0.3.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

librep-0.0.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file librep-0.0.3.tar.gz.

File metadata

  • Download URL: librep-0.0.3.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.13

File hashes

Hashes for librep-0.0.3.tar.gz
Algorithm Hash digest
SHA256 34756aa01e1e86fdb7a83fa8f52facbad0c743de0e869010e7823e0513f7f41a
MD5 6a2c6f1302b7a15359eb5361f8722794
BLAKE2b-256 13ccb6591e697b162d50388c10a8dc910d339b6e93337d18ba0e58494158c62d

See more details on using hashes here.

File details

Details for the file librep-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: librep-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.13

File hashes

Hashes for librep-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7dbc39f10aa0c0061633095d7e174f5cf34a09291f74120fb3c86f16517cb43e
MD5 cff2008dd1f510b5544a60e48f2e702a
BLAKE2b-256 da5c878fe9e44f581d9711f4184f46726322d52425e31b15f3871f23b68fe831

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page