Skip to content

Commit c27e57b

Browse files
authored
use contextlib.suppress (#37)
Signed-off-by: Dirk Thomas <[email protected]>
1 parent b8bc28f commit c27e57b

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

colcon_python_setup_py/package_identification/python_setup_py.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
# Licensed under the Apache License, Version 2.0
33

44
import ast
5+
from contextlib import suppress
56
import distutils.core
67
import os
78
from pathlib import Path
89
import runpy
9-
try:
10+
with suppress(ImportError):
1011
import setuptools
11-
except ImportError:
12-
pass
1312
import subprocess
1413
import sys
1514
from threading import Lock
@@ -121,19 +120,15 @@ def get_setup_arguments(setup_py):
121120
try:
122121
distutils_setup = distutils.core.setup
123122
distutils.core.setup = mock_setup
124-
try:
123+
with suppress(NameError):
125124
setuptools_setup = setuptools.setup
126125
setuptools.setup = mock_setup
127-
except NameError:
128-
pass
129126
# evaluate the setup.py file
130127
runpy.run_path(str(setup_py))
131128
finally:
132129
distutils.core.setup = distutils_setup
133-
try:
130+
with suppress(NameError):
134131
setuptools.setup = setuptools_setup
135-
except NameError:
136-
pass
137132
# filter out any data which doesn't work with ast.literal_eval
138133
for key, value in list(data.items()):
139134
try:

test/spell_check.words

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apache
22
chdir
33
colcon
4+
contextlib
45
distclass
56
hashable
67
iterdir

0 commit comments

Comments
 (0)