Skip to content

Commit

Permalink
fix: nox.session.run-ing commands with pathlib.Path arguments
Browse files Browse the repository at this point in the history
Previously this should have worked in theory, but the string
which is logged for debugging calls shlex.quote, which was
blowing up trying to quote the pathlib.Path.

I'm slightly surprised shlex.quote doesn't support pathlib.Path
objects (yet?) but for now here this just falls back to a cruder
representation when quoting fails.
  • Loading branch information
Julian committed Sep 4, 2022
1 parent ffb4fca commit 3275143
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nox/command.py
Expand Up @@ -92,7 +92,10 @@ def run(
success_codes = [0]

cmd, args = args[0], args[1:]
full_cmd = f"{cmd} {_shlex_join(args)}"
try:
full_cmd = f"{cmd} {_shlex_join(args)}"
except TypeError:
full_cmd = f"{cmd} {args}"

cmd_path = which(cmd, paths)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_command.py
Expand Up @@ -22,6 +22,7 @@
import subprocess
import sys
import time
from pathlib import Path
from textwrap import dedent
from unittest import mock

Expand Down Expand Up @@ -112,6 +113,15 @@ def test_run_verbosity_failed_command(capsys, caplog):
assert not logs


def test_run_non_str():
result = nox.command.run(
[Path(PYTHON), "-c", "import sys; print(sys.argv)", Path(PYTHON)],
silent=True,
)

assert PYTHON in result


def test_run_env_unicode():
result = nox.command.run(
[PYTHON, "-c", 'import os; print(os.environ["SIGIL"])'],
Expand Down

0 comments on commit 3275143

Please sign in to comment.