Skip to main content

Literate Programming toolbox

Project description

Entangled

Entangled is a solution for Literate Programming, a technique in which the programmer writes a human narrative first, then implementing the program in code blocks. Literate programming was introduced by Donald Knuth in 1984 and has since then found several surges in popularity. One thing holding back the popularity of literate programming is the lack of maintainability under increasing program complexity. Entangled solves this issue by offering a two-way synchronisation mechanism. You can edit and debug your code as normal in your favourite IDE or text editor. Entangled will make sure that your Markdown files stay up-to-date with your code and vice-versa. Because Entangled works with Markdown, you can use it with most static document generators. To summarise, you keep using:

  • your favourite editor: Entangled runs as a daemon in the background, keeping your text files synchronised.
  • your favourite programming language: Entangled is agnostic to programming languages.
  • your favourite document generator: Entangled is configurable to any dialect of Markdown.

Get started

To install Entangled, all you need is a Python installation. If you use poetry,

poetry add entangled-cli[rich]

Or, if you prefer pip,

pip install entangled-cli[rich]

Use

:warning: This version of Entangled is still in alpha. Configuration is not yet implemented.

Run the entangled watch daemon in the root of your project folder. By default all Markdown files are monitored for fenced code blocks like so:

``` {.rust #hello file="src/world.rs"}
...
```

The syntax of code block properties is the same as CSS properties: #hello gives the block the hello identifier, .rust adds the rust class and the file attribute is set to src/world.rs (quotes are optional). For Entangled to know how to tangle this block, you need to specify a language and a target file. However, now comes the cool stuff. We can split our code in meaningful components by cross-refrences.

Hello World in C++

The combined code-blocks in this example compose a compilable source code for "Hello World". For didactic reasons we don't always give the listing of an entire source file in one go. In stead, we use a system of references known as noweb (after Ramsey 1994).

Inside source fragments you may encounter a line with <<...>> marks like,

``` {.cpp file=hello_world.cc}
#include <cstdlib>
#include <iostream>

<<example-main-function>>
```

which is then elsewhere specified. Order doesn't matter,

``` {.cpp #hello-world}
std::cout << "Hello, World!" << std::endl;
```

So we can reference the <<hello-world>> code block later on.

``` {.cpp #example-main-function}
int main(int argc, char **argv)
{
    <<hello-world>>
}
```

A definition can be appended with more code as follows (in this case, order does matter!):

``` {.cpp #hello-world}
return EXIT_SUCCESS;
```

These blocks of code can be tangled into source files.

History

This is a rewrite of Entangled in Python. Older versions were written in Haskell. The rewrite in Python was motivated by ease of installation, larger community and quite frankly, a fit of mental derangement.

Contributing

If you have an idea for improving Entangled, please file an issue before creating a pull request. Code in this repository is formatted using black and type checked using mypy.

License

Copyright 2023 Netherlands eScience Center, written by Johan Hidding, licensed under the Apache 2 license, see LICENSE.

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

entangled_cli-2.0.0a3.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

entangled_cli-2.0.0a3-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file entangled_cli-2.0.0a3.tar.gz.

File metadata

  • Download URL: entangled_cli-2.0.0a3.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for entangled_cli-2.0.0a3.tar.gz
Algorithm Hash digest
SHA256 1e274e0f759d72bd391bd591564afc227ba1486bd5f989d43a71ddd2dcf2b505
MD5 6a199aceacf81304a730c7e174f038a4
BLAKE2b-256 5a94602c1fe8d56f25c147e53591830c7fae5ad3f22f7599ff3e7d87d008ca23

See more details on using hashes here.

File details

Details for the file entangled_cli-2.0.0a3-py3-none-any.whl.

File metadata

File hashes

Hashes for entangled_cli-2.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8dacefde25da10722102bcd9a0048a520fce2c13a5e174d4d84bfc66ac7057
MD5 2b8badb277c3de612504119121f22401
BLAKE2b-256 bb4be063ec76ea00767359499848d106eaca91a0b2f2a38d82fdff2db86f97bb

See more details on using hashes here.

Supported by

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