Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the OEM encoding for bat files #943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,22 @@ def copyfile(src, dest, symlink=True):
logger.info('Copying to %s', dest)
copyfileordir(src, dest, symlink)

def writefile(dest, content, overwrite=True):
def writefile(dest, content, overwrite=True, encoding='utf-8'):
if not os.path.exists(dest):
logger.info('Writing %s', dest)
with open(dest, 'wb') as f:
f.write(content.encode('utf-8'))
f.write(content.encode(encoding))
return
else:
with open(dest, 'rb') as f:
c = f.read()
if c != content.encode("utf-8"):
if c != content.encode(encoding):
if not overwrite:
logger.notify('File %s exists with different content; not overwriting', dest)
return
logger.notify('Overwriting %s with new content', dest)
with open(dest, 'wb') as f:
f.write(content.encode('utf-8'))
f.write(content.encode(encoding))
else:
logger.info('Content %s already in place', dest)

Expand Down Expand Up @@ -1472,7 +1472,10 @@ def install_files(home_dir, bin_dir, prompt, files):
content = content.replace('__VIRTUAL_ENV__', home_dir)
content = content.replace('__VIRTUAL_NAME__', vname)
content = content.replace('__BIN_NAME__', os.path.basename(bin_dir))
writefile(os.path.join(bin_dir, name), content)
# BAT files must be written in the OEM encoding, which can
# be determined as the encoding of sys.stdout.
writefile(os.path.join(bin_dir, name), content,
encoding=sys.stdout.encoding if name.endswith('.bat') else 'utf-8')

def install_python_config(home_dir, bin_dir, prompt=None):
if sys.platform == 'win32' or is_jython and os._name == 'nt':
Expand Down