-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from telostat/vst/various-improvements
Various Improvements
- Loading branch information
Showing
7 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ pkgs, ... }: | ||
|
||
let | ||
mkDevshell = import ./devsh.nix { pkgs = pkgs; }; | ||
in | ||
mkDevshell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ pkgs }: | ||
|
||
let | ||
## Create devsh script: | ||
scriptDevsh = pkgs.writeScriptBin "devsh" (builtins.readFile ./devsh.py); | ||
|
||
## Example usage: | ||
## | ||
## ``` | ||
## { compiler ? "ghc92" }: | ||
## | ||
## let | ||
## ## Import this codebase's Nix helper set: | ||
## nix = import ./nix { compiler = compiler; }; | ||
## | ||
## ## Get packages: | ||
## pkgs = nix.pkgs; | ||
## | ||
## ## Create the devshell: | ||
## devshell = nix.telosnix.tools.devshell { | ||
## name = "devshell-example"; | ||
## src = ./.; | ||
## quickstart = ./README_quickstart.md; | ||
## docs = [ | ||
## { name = "readme"; title = "Introduction"; path = "./README.md"; } | ||
## { name = "quickstart"; title = "Quickstart"; path = "./README_quickstart.md"; } | ||
## { name = "another-guide"; title = "Another Guide"; path = "./README_guide.ronn"; } | ||
## ]; | ||
## extensions = { | ||
## my-command = { | ||
## help = "Help for my command"; | ||
## exec = "${my-command}/bin/my-command"; | ||
## }; | ||
## }; | ||
## }; | ||
## in | ||
## pkgs.mkShell { | ||
## buildInputs = [ | ||
## devshell | ||
## ] ++ nix.haskell-dev-tools; | ||
## | ||
## shellHook = '' | ||
## devsh welcome | ||
## echo | ||
## devsh exec | ||
## | ||
## ## Make sure that doctest finds correct GHC executable and libraries: | ||
## export NIX_GHC=${nix.ghc}/bin/ghc | ||
## export NIX_GHC_LIBDIR=${nix.ghc}/lib/${nix.ghc.meta.name} | ||
## ''; | ||
## } | ||
## ``` | ||
mkDevshell = { name, src, quickstart, docs ? [ ], extensions ? { } }: | ||
with pkgs; | ||
let | ||
extensionDrvs = lib.attrsets.mapAttrs (name: value: writeShellScriptBin "devsh-extension-${name}" "${value.exec} \"\${@}\"") extensions; | ||
extensionHelp = lib.strings.concatStrings (lib.attrsets.attrValues (lib.attrsets.mapAttrs (name: value: "${name}: ${value.help}\n") extensions)); | ||
extensionHelpFile = writeTextFile { name = "extensions.dat"; text = extensionHelp; }; | ||
binPathDevsh = lib.makeBinPath ([ figlet lolcat rich-cli ] ++ (lib.attrsets.attrValues extensionDrvs)); | ||
in | ||
stdenv.mkDerivation { | ||
name = name; | ||
src = src; | ||
|
||
nativeBuildInputs = [ makeWrapper ]; | ||
|
||
installPhase = '' | ||
## Create output directories: | ||
mkdir -p $out/bin | ||
mkdir -p $out/etc | ||
mkdir -p $out/share/doc/guide/src | ||
mkdir -p $out/share/doc/guide/html | ||
## Copy quickstart guide: | ||
cp "${quickstart}" $out/share/doc/quickstart.md | ||
## Copy devshell extensions help: | ||
cp "${extensionHelpFile}" $out/share/doc/extensions.dat | ||
## Copy the devshell guide sections: | ||
${toString (map ({name, title, path}: "cp \"${path}\" $out/share/doc/guide/src/${name}.md\n") docs)} | ||
## Write devshell guide index: | ||
cat <<EOF > $out/share/doc/guide/src/SUMMARY.md | ||
${toString (map ({name, title, path}: "- [${title}](${name}.md)\n") docs)} | ||
EOF | ||
## Write devshell guide configuration: | ||
cat <<EOF > $out/share/doc/guide/book.toml | ||
[book] | ||
title = "${name}" | ||
description = "This is the Development Shell Guide for ${name}." | ||
[output.html] | ||
default-theme = "light" | ||
preferred-dark-theme = "ayu" | ||
curly-quotes = true | ||
mathjax-support = true | ||
copy-fonts = true | ||
EOF | ||
## Build devshell guide: | ||
"${mdbook}/bin/mdbook" build --dest-dir $out/share/doc/guide/html $out/share/doc/guide | ||
## Copy scripts to the output destination: | ||
cp ${scriptDevsh}/bin/devsh $out/bin/ | ||
## Wrap devsh program: | ||
wrapProgram $out/bin/devsh \ | ||
--prefix PATH : ${binPathDevsh} \ | ||
--set DEVSHELL_NAME "${name}" \ | ||
--set DEVSHELL_DOCS_DIR "$out/share/doc" \ | ||
--set DEVSHELL_QUICKSTART "$out/share/doc/quickstart.md" \ | ||
--set DEVSHELL_EXTENSIONS "$out/share/doc/extensions.dat" | ||
''; | ||
}; | ||
in | ||
mkDevshell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# pyright: reportConstantRedefinition=false | ||
|
||
import argparse | ||
import os | ||
import subprocess as sp | ||
import sys | ||
from typing import Any | ||
|
||
DEVSHELL_NAME = os.environ["DEVSHELL_NAME"] | ||
DEVSHELL_DOCS_DIR = os.environ["DEVSHELL_DOCS_DIR"] | ||
DEVSHELL_QUICKSTART = os.environ["DEVSHELL_QUICKSTART"] | ||
DEVSHELL_EXTENSIONS = os.environ["DEVSHELL_EXTENSIONS"] | ||
DEVSHELL_EXTENSIONS_HELP = "" | ||
|
||
with open(DEVSHELL_EXTENSIONS) as cfile: | ||
provided = cfile.read().strip() | ||
if provided: | ||
DEVSHELL_EXTENSIONS_HELP = f"""List of Extension Commands: | ||
=========================== | ||
{provided} | ||
These extension commands can be executed as: | ||
devsh exec <command> | ||
""" | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser( | ||
description="devshell", | ||
epilog=DEVSHELL_EXTENSIONS_HELP, | ||
formatter_class=argparse.RawTextHelpFormatter, | ||
) | ||
|
||
subparsers = parser.add_subparsers() | ||
|
||
subparser = subparsers.add_parser("banner", help="Print banner") | ||
subparser.set_defaults(func=do_banner) | ||
|
||
subparser = subparsers.add_parser("quickstart", help="Print quickstart guide") | ||
subparser.set_defaults(func=do_quickstart) | ||
|
||
subparser = subparsers.add_parser("welcome", help="Print welcome notice") | ||
subparser.set_defaults(func=do_welcome) | ||
|
||
subparser = subparsers.add_parser("guide", help="Open developer's guide") | ||
subparser.set_defaults(func=do_guide) | ||
|
||
subparser = subparsers.add_parser("exec", help="Execute an extension command") | ||
subparser.add_argument( | ||
"args", | ||
nargs=argparse.REMAINDER, | ||
help="Arguments to pass to the extension command", | ||
) | ||
subparser.set_defaults(func=do_exec) | ||
|
||
args = parser.parse_args(args=None if sys.argv[1:] else ["--help"]) | ||
args.func(args) | ||
|
||
|
||
def do_banner(_args: Any) -> None: | ||
ps = sp.Popen(("figlet", "-c", "-t", DEVSHELL_NAME), stdout=sp.PIPE) | ||
sp.run(("lolcat", "-S", "20", "-p", "1", "-F", "0.02"), stdin=ps.stdout, check=True) | ||
ps.wait() | ||
|
||
|
||
def do_quickstart(_args: Any) -> None: | ||
sp.run(("rich", "-c", "-w", "80", DEVSHELL_QUICKSTART), check=True) | ||
|
||
|
||
def do_welcome(args: Any) -> None: | ||
do_banner(args) | ||
do_quickstart(args) | ||
|
||
|
||
def do_guide(_args: Any) -> None: | ||
sp.run(("xdg-open", f"{DEVSHELL_DOCS_DIR}/guide/html/index.html"), check=True) | ||
|
||
|
||
def do_exec(args: Any) -> None: | ||
if not args.args: | ||
sys.stdout.write(DEVSHELL_EXTENSIONS_HELP) | ||
return | ||
|
||
args.args[0] = f"devsh-extension-{args.args[0]}" | ||
|
||
sp.run(args.args, check=True, stdin=sys.stdin) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters