Exemple #1
0
def build_docs(open_docs):
    """Build the project documentation."""
    static_data = get_static_project_data(Path.cwd())
    source_path = static_data["source_dir"]
    package_name = (static_data.get("package_name")
                    or _load_project_context().package_name)

    python_call("pip", ["install", str(source_path / "[docs]")])
    python_call("pip",
                ["install", "-r",
                 str(source_path / "requirements.txt")])
    python_call("ipykernel", ["install", "--user", f"--name={package_name}"])
    shutil.rmtree("docs/build", ignore_errors=True)
    call([
        "sphinx-apidoc",
        "--module-first",
        "-o",
        "docs/source",
        str(source_path / package_name),
    ])
    call(["sphinx-build", "-M", "html", "docs/source", "docs/build", "-a"])
    if open_docs:
        docs_page = (Path.cwd() / "docs" / "build" / "html" /
                     "index.html").as_uri()
        secho(f"Opening {docs_page}")
        webbrowser.open(docs_page)
Exemple #2
0
def lint(files, check_only):
    """Run flake8, isort and black."""
    static_data = get_static_project_data(Path.cwd())
    source_path = static_data["source_dir"]
    package_name = (static_data.get("package_name")
                    or _load_project_context().package_name)
    files = files or (str(
        source_path / "tests"), str(source_path / package_name))

    if "PYTHONPATH" not in os.environ:
        # isort needs the source path to be in the 'PYTHONPATH' environment
        # variable to treat it as a first-party import location
        os.environ["PYTHONPATH"] = str(source_path)  # pragma: no cover

    for module_name in ("flake8", "isort", "black"):
        try:
            _check_module_importable(module_name)
        except KedroCliError as exc:
            raise KedroCliError(
                NO_DEPENDENCY_MESSAGE.format(module=module_name,
                                             src=str(source_path))) from exc

    python_call("black", ("--check", ) + files if check_only else files)
    python_call("flake8", ("--max-line-length=88", ) + files)

    check_flag = ("-c", ) if check_only else ()
    python_call("isort",
                (*check_flag, "-rc", "-tc", "-up", "-fgw=0", "-m=3", "-w=88") +
                files)
Exemple #3
0
def ipython(env, args):
    """Open IPython with project specific variables loaded."""
    context = _load_project_context(env=env)
    _check_module_importable("IPython")

    os.environ["IPYTHONDIR"] = str(context.project_path / ".ipython")
    if env:
        os.environ["KEDRO_ENV"] = env
    if "-h" not in args and "--help" not in args:
        ipython_message()
    call(["ipython"] + list(args))