Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cae753

Browse files
committed
sys.platform is normalized to "linux" on Py3.
... so we can just do an equality check. (Likewise, for Windows, sys.platform is *always* "win32".) (https://docs.python.org/3/library/sys.html#sys.platform)
1 parent ef5d01a commit 3cae753

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

lib/matplotlib/backends/_backend_tk.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,10 @@ def button_press_event(self, event, dblclick=False):
336336
y = self.figure.bbox.height - event.y
337337
num = getattr(event, 'num', None)
338338

339-
if sys.platform=='darwin':
340-
# 2 and 3 were reversed on the OSX platform I
341-
# tested under tkagg
342-
if num==2: num=3
343-
elif num==3: num=2
339+
if sys.platform == 'darwin':
340+
# 2 and 3 were reversed on the OSX platform I tested under tkagg.
341+
if num == 2: num = 3
342+
elif num == 3: num = 2
344343

345344
FigureCanvasBase.button_press_event(self, x, y, num, dblclick=dblclick, guiEvent=event)
346345

@@ -354,11 +353,10 @@ def button_release_event(self, event):
354353

355354
num = getattr(event, 'num', None)
356355

357-
if sys.platform=='darwin':
358-
# 2 and 3 were reversed on the OSX platform I
359-
# tested under tkagg
360-
if num==2: num=3
361-
elif num==3: num=2
356+
if sys.platform == 'darwin':
357+
# 2 and 3 were reversed on the OSX platform I tested under tkagg.
358+
if num == 2: num = 3
359+
elif num == 3: num = 2
362360

363361
FigureCanvasBase.button_release_event(self, x, y, num, guiEvent=event)
364362

@@ -387,8 +385,8 @@ def _get_key(self, event):
387385
val = event.keysym_num
388386
if val in self.keyvald:
389387
key = self.keyvald[val]
390-
elif val == 0 and sys.platform == 'darwin' and \
391-
event.keycode in self._keycode_lookup:
388+
elif (val == 0 and sys.platform == 'darwin'
389+
and event.keycode in self._keycode_lookup):
392390
key = self._keycode_lookup[event.keycode]
393391
elif val < 256:
394392
key = chr(val)

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# create a list of system fonts, all of these should work with xe/lua-latex
3232
system_fonts = []
33-
if sys.platform.startswith('win'):
33+
if sys.platform == 'win32':
3434
from matplotlib import font_manager
3535
for f in font_manager.win32InstalledFonts():
3636
try:

lib/matplotlib/cbook/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,34 +829,34 @@ def report_memory(i=0): # argument may go away
829829
pid = os.getpid()
830830
if sys.platform == 'sunos5':
831831
try:
832-
a2 = Popen(str('ps -p %d -o osz') % pid, shell=True,
832+
a2 = Popen('ps -p %d -o osz' % pid, shell=True,
833833
stdout=PIPE).stdout.readlines()
834834
except OSError:
835835
raise NotImplementedError(
836836
"report_memory works on Sun OS only if "
837837
"the 'ps' program is found")
838838
mem = int(a2[-1].strip())
839-
elif sys.platform.startswith('linux'):
839+
elif sys.platform == 'linux':
840840
try:
841-
a2 = Popen(str('ps -p %d -o rss,sz') % pid, shell=True,
841+
a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
842842
stdout=PIPE).stdout.readlines()
843843
except OSError:
844844
raise NotImplementedError(
845845
"report_memory works on Linux only if "
846846
"the 'ps' program is found")
847847
mem = int(a2[1].split()[1])
848-
elif sys.platform.startswith('darwin'):
848+
elif sys.platform == 'darwin':
849849
try:
850-
a2 = Popen(str('ps -p %d -o rss,vsz') % pid, shell=True,
850+
a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
851851
stdout=PIPE).stdout.readlines()
852852
except OSError:
853853
raise NotImplementedError(
854854
"report_memory works on Mac OS only if "
855855
"the 'ps' program is found")
856856
mem = int(a2[1].split()[0])
857-
elif sys.platform.startswith('win'):
857+
elif sys.platform == 'win32':
858858
try:
859-
a2 = Popen([str("tasklist"), "/nh", "/fi", "pid eq %d" % pid],
859+
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
860860
stdout=PIPE).stdout.read()
861861
except OSError:
862862
raise NotImplementedError(

setupext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def _try_managers(*managers):
565565
.format(url, self.name))
566566
elif sys.platform == "darwin":
567567
message = _try_managers("brew", "port")
568-
elif sys.platform.startswith("linux"):
568+
elif sys.platform == "linux":
569569
release = platform.linux_distribution()[0].lower()
570570
if release in ('debian', 'ubuntu'):
571571
message = _try_managers('apt-get')
@@ -1421,7 +1421,7 @@ def add_flags(self, ext):
14211421
if sys.platform == 'win32':
14221422
# PSAPI library needed for finding Tcl / Tk at run time
14231423
ext.libraries.extend(['psapi'])
1424-
elif sys.platform.startswith('linux'):
1424+
elif sys.platform == 'linux':
14251425
ext.libraries.extend(['dl'])
14261426

14271427

0 commit comments

Comments
 (0)