diff --git a/python-project-template/.gitignore b/python-project-template/.gitignore.jinja similarity index 97% rename from python-project-template/.gitignore rename to python-project-template/.gitignore.jinja index 50990fe..5ab90d0 100644 --- a/python-project-template/.gitignore +++ b/python-project-template/.gitignore.jinja @@ -148,3 +148,7 @@ _html/ # Project initialization script .initialize_new_project.sh +{% if custom_install == 'library' %} +# uv +uv.lock +{% endif %} diff --git a/tests/test_package_creation.py b/tests/test_package_creation.py index 28529fe..315c204 100644 --- a/tests/test_package_creation.py +++ b/tests/test_package_creation.py @@ -231,3 +231,31 @@ def test_github_workflows_schema(copie, default_answers): "include_docs": True, } create_project_with_basic_checks(copie, extra_answers) + + +@pytest.mark.parametrize( + "custom_install,uv_lock_ignored", + [ + ("library", True), + ("command", False), + ("notebook", False), + ("custom", False), + ], +) +def test_uv_lock_in_gitignore(copie, default_answers, custom_install, uv_lock_ignored): + """Confirm that uv.lock is added to .gitignore only for library projects.""" + extra_answers = default_answers | {"custom_install": custom_install} + result = copie.copy(extra_answers=extra_answers) + + assert result.exit_code == 0 and result.exception is None + + gitignore_path = result.project_dir / ".gitignore" + assert gitignore_path.is_file() + + with open(gitignore_path, encoding="utf-8") as f: + gitignore_content = f.read() + + if uv_lock_ignored: + assert "uv.lock" in gitignore_content + else: + assert "uv.lock" not in gitignore_content