Skip to content

Commit a5adf1e

Browse files
committed
Make sure pyright is happy with external deps
1 parent c8fc7b7 commit a5adf1e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ def test_pyright_works_in_standard_typing_mode(tmp_path: Path):
256256
run(f".venv/bin/pyright {tmp_path}")
257257

258258

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

0 commit comments

Comments
 (0)