Skip to content

Commit

Permalink
doctester: repl examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyiam committed Feb 20, 2024
1 parent 0d6c103 commit 72ebef3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.rs]
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
run: nix-build
- name: Linkcheck
run: nix-shell --run "make linkcheck"
- name: Run doctests
run: nix run .#doctests
- name: Run code block tests
run: nix-shell --run "./run_code_block_tests.sh"
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@

Official documentation for getting things done with Nix.

## Contributing
## Development daemon

Run `./live` and open a browser at <http://localhost:5500>.

As you make changes your browser should auto-reload within a few seconds.

## Guidelines

For contents and style see [contribution guide](CONTRIBUTING.md).

For syntax see [RST/Sphinx Cheatsheet](https://sphinx-tutorial.readthedocs.io/cheatsheet/).

## Doctests

Must be run in the repository root.

- Single run: `nix run .#doctests`
- Daemon: `nix run .#watch-doctests`

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,30 @@
}
);
};
contentPath = "source";
doctester = pkgs.writeShellScriptBin "doctester" ''
${pkgs.lib.getExe eelco} ${pkgs.nix}/bin/nix '${contentPath}/**/*.md'
'';
doctests-watcher = pkgs.writeShellScriptBin "doctests-watcher" ''
${pkgs.watchexec}/bin/watchexec \
--watch=${contentPath}\
--restart\
--shell=none\
--emit-events-to=none\
--no-meta\
--print-events\
'${doctester}/bin/doctester'
'';
in
rec {
apps.doctests = {
type = "app";
program = "${doctester}/bin/doctester";
};
apps.watch-doctests = {
type = "app";
program = "${doctests-watcher}/bin/doctests-watcher";
};
packages = flake-utils.lib.flattenTree {
nix-dev-pyenv = pkgs.poetry2nix.mkPoetryEnv {
projectDir = self;
Expand Down
13 changes: 13 additions & 0 deletions source/_ext/nix_repl_workaround.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pygments.lexer import RegexLexer
from pygments.token import Text

class NixReplLexer(RegexLexer):
name = 'Nix REPL'
aliases = ['nix-repl']
filenames = []

tokens = {
'root': [
(r'.+', Text),
],
}
4 changes: 4 additions & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

from nix_repl_workaround import NixReplLexer
from sphinx.highlighting import lexers
lexers['nix-repl'] = NixReplLexer()

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

Expand Down
6 changes: 5 additions & 1 deletion source/tutorials/first-steps/nix-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ Use [`nix repl`] to evaluate Nix expressions interactively (by typing them on th
```shell-session
$ nix repl
Welcome to Nix 2.13.3. Type :? for help.
```

And you have a REPL:

```nix-repl
nix-repl> 1 + 2
3
```
Expand All @@ -127,7 +131,7 @@ If your output does not match the example, try prepending `:p` to the input expr

Example:

```shell-session
```nix-repl
nix-repl> { a.b.c = 1; }
{ a = { ... }; }
Expand Down

0 comments on commit 72ebef3

Please sign in to comment.