Skip to content

Commit 337c499

Browse files
authored
Merge pull request #824 from r3wretrhy/fix-win-cmd-crlf
install: keep explicit CRLF in Windows .cmd wrappers
2 parents 04cfa08 + d538cb4 commit 337c499

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎flit/install.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def install_scripts(self, script_defs, scripts_dir):
189189
cmd_file = script_file.with_suffix('.cmd')
190190
cmd = f'@echo off\r\n"{self.python}" "%~dp0\\{name}" %*\r\n'
191191
log.debug("Writing script wrapper to %s", cmd_file)
192-
with cmd_file.open('w') as f:
192+
# newline='' keeps the explicit CRLF; on Windows text mode would
193+
# otherwise translate `\n` again and write `\r\r\n`.
194+
with cmd_file.open('w', encoding='utf-8', newline='') as f:
193195
f.write(cmd)
194196

195197
self.installed_files.append(cmd_file)

‎tests/test_install.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def test_install_package(self):
8080
assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
8181
with (self.tmpdir / 'scripts' / 'pkg_script').open() as f:
8282
assert f.readline().strip() == "#!" + sys.executable
83+
if sys.platform == 'win32':
84+
cmd_path = self.tmpdir / 'scripts' / 'pkg_script.cmd'
85+
assert_isfile(cmd_path)
86+
raw = cmd_path.read_bytes()
87+
assert b'\r\r\n' not in raw
88+
assert raw.startswith(b'@echo off\r\n')
89+
assert sys.executable.encode('utf-8') in raw
8390
self._assert_direct_url(
8491
samples_dir / 'package1', 'package1', '0.1', expected_editable=False
8592
)

0 commit comments

Comments
 (0)