How to use the cruft.exceptions.NoCruftFound function in cruft

To help you get started, we’ve selected a few cruft examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timothycrosley / cruft / tests / test_exceptions.py View on Github external
def test_no_cruft():
    instance = exceptions.NoCruftFound(".")
    assert instance.directory == "."
    assert isinstance(instance, exceptions.CruftError)
github timothycrosley / cruft / tests / test_api.py View on Github external
def test_update_examples(project_dir, tmpdir):
    tmpdir.chdir()
    with pytest.raises(exceptions.NoCruftFound):
        verify_and_test_examples(api.update)

    os.chdir(project_dir)
    verify_and_test_examples(api.update)
github timothycrosley / cruft / cruft / api.py View on Github external
def check(expanded_dir: str = ".") -> bool:
    """Checks to see if there have been any updates to the Cookiecutter template used
    to generate this project.
    """
    expanded_dir_path = Path(expanded_dir)
    cruft_file = expanded_dir_path / ".cruft.json"
    if not cruft_file.is_file():
        raise NoCruftFound(expanded_dir_path.resolve())

    cruft_state = json.loads(cruft_file.read_text())
    with TemporaryDirectory() as cookiecutter_template_dir:
        repo = Repo.clone_from(cruft_state["template"], cookiecutter_template_dir)
        last_commit = repo.head.object.hexsha
        if last_commit == cruft_state["commit"] or not repo.index.diff(cruft_state["commit"]):
            return True

    return False
github timothycrosley / cruft / cruft / api.py View on Github external
def update(
    expanded_dir: str = ".",
    cookiecutter_input: bool = False,
    skip_apply_ask: bool = False,
    skip_update: bool = False,
) -> bool:
    """Update specified project's cruft to the latest and greatest release."""
    expanded_dir_path = Path(expanded_dir)
    pyproject_file = expanded_dir_path / "pyproject.toml"
    cruft_file = expanded_dir_path / ".cruft.json"
    if not cruft_file.is_file():
        raise NoCruftFound(cruft_file)

    cruft_state = json.loads(cruft_file.read_text())

    skip_cruft = cruft_state.get("skip", [])
    if toml and pyproject_file.is_file():
        pyproject_cruft = toml.loads(pyproject_file.read_text()).get("tool", {}).get("cruft", {})
        skip_cruft.extend(pyproject_cruft.get("skip", []))

    with TemporaryDirectory() as compare_directory_str:
        compare_directory = Path(compare_directory_str)
        template_dir = compare_directory / "template"

        try:
            repo = Repo.clone_from(cruft_state["template"], template_dir)
            last_commit = repo.head.object.hexsha
        except Exception as e:  # pragma: no cover