Skip to content

Commit 73c31e3

Browse files
authored
fix: make sure pyright is happy with external deps (#296)
Fixes #295
1 parent c8fc7b7 commit 73c31e3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

template/pyproject.toml.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ description = "Run {{ type_checker }}"
103103
commands = [
104104
[
105105
"{{ type_checker }}",
106-
"src",
106+
{% if type_checker=="pyright" %}"--pythonpath",
107+
".venv/bin/python",
108+
{% endif %}"src",
107109
"tests",
108110
{ replace = "posargs", default = [
109111
], extend = true },

tests/test_example.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def test_example_repo_updates(tmp_path: Path):
180180
output = run(
181181
# Git directory expected to be different
182182
"diff -ur --exclude=.git "
183+
# uv lock expected to be different
184+
"--exclude=uv.lock "
183185
# The commit hash is different for some reason
184186
"--ignore-matching-lines='^_commit: ' "
185187
# If we tag an existing commit that has been pushed to main, then the copier
@@ -256,6 +258,27 @@ def test_pyright_works_in_standard_typing_mode(tmp_path: Path):
256258
run(f".venv/bin/pyright {tmp_path}")
257259

258260

261+
def test_pyright_works_with_external_deps(tmp_path: Path):
262+
copy_project(tmp_path)
263+
# Add an external dependency
264+
pyproject_toml = tmp_path / "pyproject.toml"
265+
text = pyproject_toml.read_text().replace(
266+
"dependencies = []", 'dependencies = ["numpy"]'
267+
)
268+
pyproject_toml.write_text(text)
269+
# And some code that uses it
270+
src_file = tmp_path / "src" / "python_copier_template_example" / "example.py"
271+
src_file.write_text("""
272+
import numpy as np
273+
274+
def is_big(arr: np.ndarray) -> bool:
275+
return arr.size > 0
276+
""")
277+
# Ensure pyright is still happy
278+
run = make_venv(tmp_path)
279+
run(".venv/bin/tox -e type-checking")
280+
281+
259282
def test_ignores_mypy_strict_mode(tmp_path: Path):
260283
copy_project(tmp_path, type_checker="mypy", strict_typing=True)
261284
pyproject_toml = tmp_path / "pyproject.toml"

0 commit comments

Comments
 (0)