This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: python -m venv activate.bat has weird mix of line endings
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: Josh Wilson, evan_, paul.moore, python-dev, steve.dower, tim.golden, vinay.sajip, zach.ware
Priority: normal Keywords: patch

Created on 2017-01-09 14:12 by Josh Wilson, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue-29213-01.diff vinay.sajip, 2017-01-13 11:13 Initial patch for this issue - against the 3.5 branch. review
Messages (10)
msg285043 - (view) Author: Josh Wilson (Josh Wilson) * Date: 2017-01-09 14:12
The activate.bat file generated by python -m venv somevirtualenv seems to have a mix of line ending styles.  Sometimes using Carriage Return (CR) and Line Feed (LF) and other times using only CR.

This seems to cause unexpected behavior when trying to modify the file to set additional environment variables.  Since this is a Windows-specific file it seems like it should use Windows-style line endings of CRLF

Deactivate.bat has the same issue.
msg285104 - (view) Author: Evan Andrews (evan_) * Date: 2017-01-10 10:51
The scripts are being read in with mode 'rb', decoded, modified, then written back out with mode 'w'. This means the EOL conversion doesn't happen on the way in, but does happen on the way out, and so '\r\n' becomes '\r\r\n'. One fix would be to always use binary mode and encode the contents back to bytes instead. However since there are no longer any binary files in venv/Scripts/*, perhaps a better fix is to remove the binary handling entirely and always use text mode?
msg285253 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-01-11 18:23
Although we don't currently have binaries under venv/scripts, that might change in the future. The logic could be changed to:

    with open(srcfile, 'rb') as f:
        data = f.read()
    if not srcfile.endswith('.exe'):
        try:
            data = data.decode('utf-8')
            data = self.replace_variables(data, context)
            data = data.encode('utf-8')
        except UnicodeError as e:
            data = None
            logger.warning('unable to copy script %r, '
                           'may be binary: %s', srcfile, e)
    if data is not None:
        with open(dstfile, 'wb') as f:
            f.write(data)
        shutil.copymode(srcfile, dstfile)

All the files in the nt subdirectory have CRLF endings, and the above should preserve them (whatever they are).
msg285383 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-01-13 11:13
I've added a patch, can you confirm if it resolves the issue?
msg286813 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-02 19:27
New changeset 2b9e5cbdb0b1 by Vinay Sajip in branch '3.5':
Fixes #29213: regularised EOLs of venv scripts.
https://hg.python.org/cpython/rev/2b9e5cbdb0b1

New changeset 0f3ebeb389fe by Vinay Sajip in branch '3.6':
Fixes #29213: merged fix from 3.5.
https://hg.python.org/cpython/rev/0f3ebeb389fe
msg286815 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-02 19:33
New changeset c23224ebc9e5 by Vinay Sajip in branch 'default':
Closes #29213: Merged fix from 3.6.
https://hg.python.org/cpython/rev/c23224ebc9e5
msg286818 - (view) Author: Roundup Robot (python-dev) (Python triager) Date:
New changeset ef0264af4d1a1844c2feb32714870d636e583b3a by Vinay Sajip in branch 'master':
Closes #29213: Merged fix from 3.6.
https://github.com/python/cpython/commit/ef0264af4d1a1844c2feb32714870d636e583b3a
msg286820 - (view) Author: Roundup Robot (python-dev) (Python triager) Date:
New changeset a7dc69b8956ad223ff6c239299896dd5195ce430 by Vinay Sajip in branch '3.5':
Fixes #29213: regularised EOLs of venv scripts.
https://github.com/python/cpython/commit/a7dc69b8956ad223ff6c239299896dd5195ce430
msg286822 - (view) Author: Roundup Robot (python-dev) (Python triager) Date:
New changeset a7dc69b8956ad223ff6c239299896dd5195ce430 by Vinay Sajip in branch '3.6':
Fixes #29213: regularised EOLs of venv scripts.
https://github.com/python/cpython/commit/a7dc69b8956ad223ff6c239299896dd5195ce430

New changeset 1b105fac40b341980b290729a7ed403c73f5cf61 by Vinay Sajip in branch '3.6':
Fixes #29213: merged fix from 3.5.
https://github.com/python/cpython/commit/1b105fac40b341980b290729a7ed403c73f5cf61
msg286840 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-03 04:00
New changeset a7dc69b8956ad223ff6c239299896dd5195ce430 by Vinay Sajip in branch 'master':
Fixes #29213: regularised EOLs of venv scripts.
https://github.com/python/cpython/commit/a7dc69b8956ad223ff6c239299896dd5195ce430

New changeset 1b105fac40b341980b290729a7ed403c73f5cf61 by Vinay Sajip in branch 'master':
Fixes #29213: merged fix from 3.5.
https://github.com/python/cpython/commit/1b105fac40b341980b290729a7ed403c73f5cf61
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73399
2017-02-03 04:00:26python-devsetmessages: + msg286840
2017-02-02 20:02:40python-devsetmessages: + msg286822
2017-02-02 20:02:39python-devsetmessages: + msg286820
2017-02-02 20:02:38python-devsetmessages: + msg286818
2017-02-02 19:33:50python-devsetstatus: open -> closed
resolution: fixed
messages: + msg286815

stage: patch review -> resolved
2017-02-02 19:27:51python-devsetnosy: + python-dev
messages: + msg286813
2017-01-13 11:13:23vinay.sajipsetfiles: + issue-29213-01.diff
messages: + msg285383

assignee: vinay.sajip
keywords: + patch
stage: patch review
2017-01-11 18:23:00vinay.sajipsetmessages: + msg285253
2017-01-10 10:51:18evan_setnosy: + evan_, vinay.sajip

messages: + msg285104
versions: + Python 3.6
2017-01-09 14:12:17Josh Wilsoncreate