installation instructions, tzk preflight

This commit is contained in:
Soren I. Bjornstad
2021-08-27 10:28:53 -05:00
parent 97a4611d56
commit e0ce707894
6 changed files with 117 additions and 11 deletions

View File

@@ -1,7 +1,6 @@
from abc import ABC, abstractmethod, abstractclassmethod
import argparse
import os
import shutil
import sys
import traceback
from typing import Optional
@@ -9,7 +8,7 @@ from typing import Optional
from tzk.config import cm
from tzk import git
from tzk import tw
from tzk.util import BuildError, fail, numerize
from tzk.util import BuildError, fail, numerize, require_dependencies
class CliCommand(ABC):
@@ -141,13 +140,7 @@ class InitCommand(CliCommand):
)
def _precheck(self):
if shutil.which("npm") is None:
fail("TZK requires NPM. Please install NPM and make it available on your PATH.\n"
"https://docs.npmjs.com/downloading-and-installing-node-js-and-npm")
if shutil.which("git") is None:
fail("TZK requires Git. Please install Git and make it available on your PATH.\n"
"https://git-scm.com/book/en/v2/Getting-Started-Installing-Git")
require_dependencies()
if os.path.exists("package.json"):
fail("A 'package.json' file already exists in the current directory. "
@@ -158,6 +151,20 @@ class InitCommand(CliCommand):
tw.install(args.wiki_name, args.tiddlywiki_version_spec, args.author)
class PreflightCommand(CliCommand):
cmd = "preflight"
help = "Check if tzk and all its dependencies are correctly installed."
@classmethod
def setup_arguments(cls, parser: argparse.ArgumentParser) -> None:
pass
def execute(self, args: argparse.Namespace) -> None:
require_dependencies()
print("You're all set! Change into a directory you want to "
"turn into your tzk repository and run 'tzk init'.")
class BuildCommand(CliCommand):
cmd = "build"
help = ("Build another wiki or derivative product, "

View File

@@ -3,6 +3,7 @@ util.py - miscellaneous utility functions
"""
from contextlib import contextmanager
import os
import shutil
import sys
from typing import NoReturn
@@ -40,3 +41,17 @@ def pushd(directory: str):
yield
finally:
os.chdir(old_directory)
def require_dependencies() -> None:
"""
Raise an exception if dependencies of tzk aren't available.
"""
if shutil.which("npm") is None:
fail("npm is not available. "
"Please install NPM and make it available on your PATH.\n"
"https://docs.npmjs.com/downloading-and-installing-node-js-and-npm")
if shutil.which("git") is None:
fail("Git is not available. "
"Please install Git and make it available on your PATH.\n"
"https://git-scm.com/book/en/v2/Getting-Started-Installing-Git")