Skip to content

Commit d220299

Browse files
authored
fix: tox / pyright python environment (#320)
Use native tox environment variable expansion to pass $VIRTUAL_ENV Fix whitespace
1 parent c52b391 commit d220299

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

template/pyproject.toml.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ commands = [
104104
[
105105
"{{ type_checker }}",
106106
{% if type_checker=="pyright" %}"--pythonpath",
107-
".venv/bin/python",
107+
"{env:VIRTUAL_ENV}/bin/python",
108108
{% endif %}"src",
109109
"tests",
110110
{ replace = "posargs", default = [
@@ -116,7 +116,7 @@ commands = [
116116
description = "Run tests with coverage"
117117
commands = [
118118
[
119-
"pytest",
119+
"pytest",
120120
"--cov={{ package_name }}",
121121
"--cov-report",
122122
"term",

tests/test_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import json
3+
import os
34
import shlex
45
import subprocess
56
import tomllib
@@ -27,12 +28,13 @@ def copy_project(project_path: Path, **kwargs):
2728
run_pipe("git add .", cwd=str(project_path))
2829

2930

30-
def run_pipe(cmd: str, cwd=None) -> str:
31+
def run_pipe(cmd: str, cwd=None, venv="") -> str:
3132
sp = subprocess.run(
3233
shlex.split(cmd),
3334
stdout=subprocess.PIPE,
3435
stderr=subprocess.STDOUT,
3536
cwd=cwd,
37+
env=dict(os.environ, UV_PROJECT_ENVIRONMENT="", VIRTUAL_ENV=venv),
3638
)
3739
output = sp.stdout.decode()
3840
assert sp.returncode == 0, output
@@ -41,7 +43,7 @@ def run_pipe(cmd: str, cwd=None) -> str:
4143

4244
def make_venv(project_path: Path) -> Callable[[str], str]:
4345
venv_path = project_path / ".venv"
44-
run = functools.partial(run_pipe, cwd=str(project_path))
46+
run = functools.partial(run_pipe, cwd=str(project_path), venv=venv_path)
4547
run("uv sync") # Create a lockfile and install packages
4648

4749
for exe_path in [

0 commit comments

Comments
 (0)