Don't check for 'linux2' value in sys.platform #549

Closed
fperez opened this Issue Jul 1, 2011 · 7 comments

Comments

Projects
None yet
3 participants
Owner

fperez commented Jul 1, 2011

The linux kernel is transitioning to version 3.0, and this means that the sys.platform string will become on such machines 'linux3' instead. Right now, we have explicit checks for linux2:

(master)amirbar[IPython]> grin linux2
./quarantine/InterpreterExec.py:
  139 :         sys.platform is: linux2
./testing/decorators.py:
  300 : skip_linux = skipif(sys.platform == 'linux2',
  308 : skip_if_not_linux = skipif(sys.platform != 'linux2',
./testing/tests/test_decorators.py:
  179 :     nt.assert_not_equals(sys.platform,'linux2',"This test can't run under linux")
./utils/sysinfo.py:
  129 :      'sys_platform': 'linux2',

All these should become variants of 'foo[:5] == 'linux'.

I'll tag this as 0.11 in case we can make it, as it's an easy fix and it would be nice to run out of the box for people who upgrade kernels early. But it's not super critical.

Contributor

rkern commented Jul 1, 2011

A more idiomatic version:

foo.startswith('linux')
Owner

fperez commented Jul 1, 2011

I suggested the uglier one b/c it's a little faster, I had checked both:

In [2]: timeit sys.platform.startswith('linux')
1000000 loops, best of 3: 294 ns per loop

In [3]: timeit sys.platform[:5] == 'linux'
1000000 loops, best of 3: 210 ns per loop

I know that 85ns may be a silly thing to worry about, but I tend to be a bit anal about avoiding slowdowns everywhere. Do you see another reason for sticking with the startswith form?

Contributor

rkern commented Jul 1, 2011

Just general clean-code, DRY principles, nothing major.

Owner

fperez commented Jul 1, 2011

Sure. I do tend to use startswith in general, to be honest. 80ns isn't really worth worrying about, and the functional version does read more cleanly, so let's go with that. I need to get back on my OCD meds... :)

Owner

minrk commented Jul 1, 2011

I've got this locally using startswith, should I just push to master?

Owner

fperez commented Jul 1, 2011

On Thu, Jun 30, 2011 at 10:04 PM, minrk
reply@reply.github.com
wrote:

I've got this locally using startswith, should I just push to master?

Go for it, thanks!

minrk closed this in e1d1d8e Jul 1, 2011

Owner

minrk commented Jul 1, 2011

pushed and closed

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

@minrk minrk check linux with startswith('linux') instead of =='linux2'
This allows for sys.platform=='linux3'.

closes gh-549
459a3da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment