Skip to content

Commit 3dd2e5b

Browse files
adam-grant-hendryLee-W
authored andcommitted
test(bump): handle Windows path separator
Windows uses `\` for path separation, causing python to see the `\U` in `C:\Users` as a Unicode string. Replace `\\` with `/` in file path strings. Also, the colon in drive paths on Windows causes the `partition` logic in `bump.py` and `commands/bump.py` to fail. Perform the logic on the path without the drive portion.
1 parent 651b174 commit 3dd2e5b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

commitizen/bump.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from collections import OrderedDict
34
from itertools import zip_longest
@@ -155,7 +156,9 @@ def update_version_in_files(
155156
"""
156157
# TODO: separate check step and write step
157158
for location in files:
158-
filepath, _, regex = location.partition(":")
159+
drive, tail = os.path.splitdrive(location)
160+
path, _, regex = tail.partition(":")
161+
filepath = drive + path
159162
if not regex:
160163
regex = _version_to_regex(current_version)
161164

commitizen/commands/bump.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from logging import getLogger
23
from typing import List, Optional
34

@@ -230,9 +231,15 @@ def __call__(self): # noqa: C901
230231
},
231232
)
232233
changelog_cmd()
234+
file_names = []
235+
for file_name in version_files:
236+
drive, tail = os.path.splitdrive(file_name)
237+
path, _, regex = tail.partition(":")
238+
path = drive + path if path != "" else drive + regex
239+
file_names.append(path)
233240
git_add_changelog_and_version_files_command = (
234241
f"git add {changelog_cmd.file_name} "
235-
f"{' '.join(file_name.partition(':')[0] for file_name in version_files)}"
242+
f"{' '.join(name for name in file_names)}"
236243
)
237244
c = cmd.run(git_add_changelog_and_version_files_command)
238245

tests/test_bump_update_version_in_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
def _copy_sample_file_to_tmpdir(
1616
tmpdir: LocalPath, source_filename: str, dest_filename: str
1717
) -> str:
18-
tmp_file = tmpdir.join(dest_filename)
19-
copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file))
20-
return str(tmp_file)
18+
tmp_file = str(tmpdir.join(dest_filename)).replace("\\", "/")
19+
copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", tmp_file)
20+
return tmp_file
2121

2222

2323
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)