From a5adf1ecd35902621c43e1d7a3049de6a674e7c5 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Wed, 1 Oct 2025 10:20:06 +0000 Subject: [PATCH 1/2] Make sure pyright is happy with external deps --- template/pyproject.toml.jinja | 4 +++- tests/test_example.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 1d0cdd49..747c3eda 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -103,7 +103,9 @@ description = "Run {{ type_checker }}" commands = [ [ "{{ type_checker }}", - "src", + {% if type_checker=="pyright" %}"--pythonpath", + ".venv/bin/python", + {% endif %}"src", "tests", { replace = "posargs", default = [ ], extend = true }, diff --git a/tests/test_example.py b/tests/test_example.py index f7ba96a1..32746ab0 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -256,6 +256,27 @@ def test_pyright_works_in_standard_typing_mode(tmp_path: Path): run(f".venv/bin/pyright {tmp_path}") +def test_pyright_works_with_external_deps(tmp_path: Path): + copy_project(tmp_path) + # Add an external dependency + pyproject_toml = tmp_path / "pyproject.toml" + text = pyproject_toml.read_text().replace( + "dependencies = []", 'dependencies = ["numpy"]' + ) + pyproject_toml.write_text(text) + # And some code that uses it + src_file = tmp_path / "src" / "python_copier_template_example" / "example.py" + src_file.write_text(""" +import numpy as np + +def is_big(arr: np.ndarray) -> bool: + return arr.size > 0 +""") + # Ensure pyright is still happy + run = make_venv(tmp_path) + run(".venv/bin/tox -e type-checking") + + def test_ignores_mypy_strict_mode(tmp_path: Path): copy_project(tmp_path, type_checker="mypy", strict_typing=True) pyproject_toml = tmp_path / "pyproject.toml" From 9b9ff606d69c45140cec0b9f2a1da7298926a555 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Wed, 1 Oct 2025 10:48:52 +0000 Subject: [PATCH 2/2] Allow uv.lock to be different in the example --- tests/test_example.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_example.py b/tests/test_example.py index 32746ab0..3de6a826 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -180,6 +180,8 @@ def test_example_repo_updates(tmp_path: Path): output = run( # Git directory expected to be different "diff -ur --exclude=.git " + # uv lock expected to be different + "--exclude=uv.lock " # The commit hash is different for some reason "--ignore-matching-lines='^_commit: ' " # If we tag an existing commit that has been pushed to main, then the copier