Skip to content

Commit 637777b

Browse files
authored
Minor python code cleanup (#1008)
Regarding the change to `content_exists`, we only support tools that are directories full of files, there is no such thing as a tool that is just a single file and not a directory.
1 parent 8cea378 commit 637777b

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

emsdk.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,30 +483,24 @@ def sdk_path(path):
483483
# Removes a single file, suppressing exceptions on failure.
484484
def rmfile(filename):
485485
debug_print('rmfile(' + filename + ')')
486-
try:
486+
if os.path.lexists(filename):
487487
os.remove(filename)
488-
except:
489-
pass
490488

491489

492490
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
493491
def mkdir_p(path):
494492
debug_print('mkdir_p(' + path + ')')
495-
if os.path.exists(path):
496-
return
497493
try:
498494
os.makedirs(path)
499495
except OSError as exc: # Python >2.5
500-
if exc.errno == errno.EEXIST and os.path.isdir(path):
501-
pass
502-
else:
496+
if exc.errno != errno.EEXIST or not os.path.isdir(path):
503497
raise
504498

505499

506-
def num_files_in_directory(path):
500+
def is_nonempty_directory(path):
507501
if not os.path.isdir(path):
508-
return 0
509-
return len([name for name in os.listdir(path) if os.path.exists(os.path.join(path, name))])
502+
return False
503+
return len(os.listdir(path)) != 0
510504

511505

512506
def run(cmd, cwd=None, quiet=False):
@@ -1813,7 +1807,7 @@ def is_installed(self, skip_version_check=False):
18131807
# This tool does not contain downloadable elements, so it is installed by default.
18141808
return True
18151809

1816-
content_exists = os.path.exists(self.installation_path()) and (os.path.isfile(self.installation_path()) or num_files_in_directory(self.installation_path()) > 0)
1810+
content_exists = is_nonempty_directory(self.installation_path())
18171811

18181812
# For e.g. fastcomp clang from git repo, the activated PATH is the
18191813
# directory where the compiler is built to, and installation_path is

0 commit comments

Comments
 (0)