Skip to content

Commit af256fe

Browse files
committed
Windows support
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 24a61d9 commit af256fe

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/tox/config/loader/ini/replace.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
# split alongside :, unless it's escaped, or it's preceded by a single capital letter (Windows drive letter in paths)
2222
ARGS_GROUP = re.compile(r"(?<!\\\\|:[A-Z]):")
23-
NOT_ESCAPED_COMMENT = re.compile(r"(?<!\\)#")
2423

2524

2625
def replace(conf: "Config", name: Optional[str], loader: "IniLoader", value: str, chain: List[str]) -> str:
@@ -124,8 +123,7 @@ def replace_reference(
124123
return loader.process_raw(conf, current_env, src[key])
125124
value = src.load(key, chain)
126125
as_str, _ = stringify(value)
127-
# escape unescaped comment characters to preserve them during processing
128-
as_str = NOT_ESCAPED_COMMENT.sub("\\#", as_str)
126+
as_str = as_str.replace("#", r"\#") # escape comment characters as these will be stripped
129127
return as_str
130128
except KeyError as exc: # if fails, keep trying maybe another source can satisfy
131129
exception = exc

src/tox/config/loader/str_convert.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def to_dict(value: str, of_type: Tuple[Type[Any], Type[Any]]) -> Iterator[Tuple[
4747
@staticmethod
4848
def to_command(value: str) -> Command:
4949
is_win = sys.platform == "win32"
50+
value = value.replace(r"\#", "#")
5051
splitter = shlex.shlex(value, posix=not is_win)
5152
splitter.whitespace_split = True
53+
splitter.commenters = "" # comments handled earlier, and the shlex does not know escaped comment characters
5254
args: List[str] = []
5355
pos = 0
5456
try:

tests/session/cmd/test_show_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_show_config_ini_comment_path(tox_project: ToxProjectCreator, tmp_path:
168168
set_env =
169169
A=1 # comment
170170
# more comment
171-
commands = {envpython} -c 'import os; print(os.linesep.join(f"{k}={v!r}" for k, v in os.environ.items()))'
171+
commands = {envpython} -c 'import os; print(os.linesep.join(f"{k}={v}" for k, v in os.environ.items()))'
172172
[testenv:py]
173173
set_env =
174174
{[testenv]set_env}
@@ -178,6 +178,6 @@ def test_show_config_ini_comment_path(tox_project: ToxProjectCreator, tmp_path:
178178
result = project.run("r", "-e", "py")
179179
result.assert_success()
180180
a_line = next(i for i in result.out.splitlines() if i.startswith("A=")) # pragma: no branch # not found raises
181-
assert a_line == "A='1'"
181+
assert a_line == "A=1"
182182
b_line = next(i for i in result.out.splitlines() if i.startswith("B=")) # pragma: no branch # not found raises
183-
assert b_line == f"B='{prj_path}'"
183+
assert b_line == f"B={prj_path}"

whitelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ chdir
2727
cmd
2828
codec
2929
colorama
30+
commenters
3031
conf
3132
configs
3233
conftest

0 commit comments

Comments
 (0)