Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cruft_already_present():
instance = exceptions.CruftAlreadyPresent(".")
assert instance.file_location == "."
assert isinstance(instance, exceptions.CruftError)
def test_link_examples(project_dir, tmpdir):
os.chdir(project_dir)
with pytest.raises(exceptions.CruftAlreadyPresent):
verify_and_test_examples(api.link)
tmpdir.chdir()
Repo.clone_from("https://github.com/timothycrosley/cruft", str(tmpdir))
os.remove(os.path.join(tmpdir, ".cruft.json"))
verify_and_test_examples(api.link)
def link(
template_git_url: str,
project_dir: str = ".",
use_latest: bool = False,
no_input: bool = False,
config_file: Optional[str] = None,
default_config: bool = False,
extra_context: Optional[dict] = None,
) -> bool:
"""Links an existing project created from a template, to the template it was created from."""
project_dir_path = Path(project_dir)
cruft_file = project_dir_path / ".cruft.json"
if cruft_file.is_file():
raise CruftAlreadyPresent(cruft_file)
with TemporaryDirectory() as cookiecutter_template_dir_str:
cookiecutter_template_dir = Path(cookiecutter_template_dir_str)
try:
repo = Repo.clone_from(template_git_url, cookiecutter_template_dir)
last_commit = repo.head.object.hexsha
except Exception as e: # pragma: no cover
raise InvalidCookiecutterRepository(e)
main_cookiecutter_directory: Optional[Path] = None
for dir_item in cookiecutter_template_dir.glob("*cookiecutter.*"):
if dir_item.is_dir() and "{{" in dir_item.name and "}}" in dir_item.name:
main_cookiecutter_directory = dir_item
break
if not main_cookiecutter_directory: # pragma: no cover