site.py uses os.sep to determine platform

On august 7th, 1998, Guido committed https://github.com/python/cpython/commit/d89fa0c5761254c970af72e5abcea420fd2 3e893 to python, adding the quit() and exit() built-ins. He decided to determine the platform python was running on by checking os.sep. I don't understand the rationale behind this choice in 1998, but I assume that there was one. It's 2017. We have sys.platform, and the standard library is tested against everything that vanilla cpython (unpatched by a vendor) will ever put in cpython. Is there any reason not to change os.sep == '\\' to sys.platform == 'win32' in 2017?

On Sun, Feb 12, 2017 at 07:26:29AM -0500, Alex Walters <tritium-list@sdamon.com> wrote:
Is there any reason not to change...
Do not change things that work for the sake of a change. Isn't it a good reason? Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

It depends on what the code beneath the if is doing. "Windows" may be a shorthand for "uses backslash", in which case the check is correct. We should certainly match the check to the intent, but we need to determine the intent first. Cheers, Steve Top-posted from my Windows Phone -----Original Message----- From: "Alex Walters" <tritium-list@sdamon.com> Sent: 2/12/2017 4:35 To: "python-ideas@python.org" <python-ideas@python.org> Subject: [Python-ideas] site.py uses os.sep to determine platform On august 7th, 1998, Guido committed https://github.com/python/cpython/commit/d89fa0c5761254c970af72e5abcea420fd2 3e893 to python, adding the quit() and exit() built-ins. He decided to determine the platform python was running on by checking os.sep. I don't understand the rationale behind this choice in 1998, but I assume that there was one. It's 2017. We have sys.platform, and the standard library is tested against everything that vanilla cpython (unpatched by a vendor) will ever put in cpython. Is there any reason not to change os.sep == '\\' to sys.platform == 'win32' in 2017? _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Well to be pedantic, the code is obviously wrong since it assumes EOF is generated by ctrl-D, but the user could have changed that with stty. It should query the terminal settings instead... Yeah I know, people who do that don't need the message. Op 12 feb. 2017 4:26 p.m. schreef "Steve Dower" <steve.dower@python.org>:

On 12 February 2017 at 16:05, Steve Dower <steve.dower@python.org> wrote:
It depends on what the code beneath the if is doing. "Windows" may be a shorthand for "uses backslash", in which case the check is correct.
In this case, it's to decide whether the default way of entering EOF at the terminal is by pressing Ctrl-D (POSIX-style) or Ctrl-Z+Enter (Windows-style). There's another case in site.py where "os.sep='/'" is used to decide whether or not the site-packages path should be qualified with the python version. In the cases where it is used, the separator is likely to give you the right answer under things like Cygwin, MinGW and WSL (all of which should use "/" for the default path separator and Ctrl-D to enter EOF even though you're actually running on a Windows machine), but I wouldn't place any bets on it being easy to replicate the separator setting (and os.path module selection) logic that figures that out in the first place. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Sun, Feb 12, 2017 at 07:26:29AM -0500, Alex Walters <tritium-list@sdamon.com> wrote:
Is there any reason not to change...
Do not change things that work for the sake of a change. Isn't it a good reason? Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

It depends on what the code beneath the if is doing. "Windows" may be a shorthand for "uses backslash", in which case the check is correct. We should certainly match the check to the intent, but we need to determine the intent first. Cheers, Steve Top-posted from my Windows Phone -----Original Message----- From: "Alex Walters" <tritium-list@sdamon.com> Sent: 2/12/2017 4:35 To: "python-ideas@python.org" <python-ideas@python.org> Subject: [Python-ideas] site.py uses os.sep to determine platform On august 7th, 1998, Guido committed https://github.com/python/cpython/commit/d89fa0c5761254c970af72e5abcea420fd2 3e893 to python, adding the quit() and exit() built-ins. He decided to determine the platform python was running on by checking os.sep. I don't understand the rationale behind this choice in 1998, but I assume that there was one. It's 2017. We have sys.platform, and the standard library is tested against everything that vanilla cpython (unpatched by a vendor) will ever put in cpython. Is there any reason not to change os.sep == '\\' to sys.platform == 'win32' in 2017? _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Well to be pedantic, the code is obviously wrong since it assumes EOF is generated by ctrl-D, but the user could have changed that with stty. It should query the terminal settings instead... Yeah I know, people who do that don't need the message. Op 12 feb. 2017 4:26 p.m. schreef "Steve Dower" <steve.dower@python.org>:

On 12 February 2017 at 16:05, Steve Dower <steve.dower@python.org> wrote:
It depends on what the code beneath the if is doing. "Windows" may be a shorthand for "uses backslash", in which case the check is correct.
In this case, it's to decide whether the default way of entering EOF at the terminal is by pressing Ctrl-D (POSIX-style) or Ctrl-Z+Enter (Windows-style). There's another case in site.py where "os.sep='/'" is used to decide whether or not the site-packages path should be qualified with the python version. In the cases where it is used, the separator is likely to give you the right answer under things like Cygwin, MinGW and WSL (all of which should use "/" for the default path separator and Ctrl-D to enter EOF even though you're actually running on a Windows machine), but I wouldn't place any bets on it being easy to replicate the separator setting (and os.path module selection) logic that figures that out in the first place. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (6)
-
Alex Walters
-
Nick Coghlan
-
Oleg Broytman
-
Random832
-
Stephan Houben
-
Steve Dower