- Make sure to close the import_failed.map file after the exception

has been raised in order to avoid ResourceWarnings when the
  failing import is part of a try...except block.

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:Factory/python39?expand=0&rev=65
This commit is contained in:
2021-05-02 17:10:11 +00:00
committed by Git OBS Bridge
parent 40e9d58763
commit ac13143082
2 changed files with 13 additions and 5 deletions

View File

@@ -8,11 +8,12 @@ if __spec__:
else:
failed_name = __name__
for line in open(failed_map_path):
package = line.split(':')[0]
imports = line.split(':')[1]
if failed_name in imports:
raise ImportError(f"""Module '{failed_name}' is not installed.
with open(failed_map_path) as fd:
for line in fd:
package = line.split(':')[0]
imports = line.split(':')[1]
if failed_name in imports:
raise ImportError(f"""Module '{failed_name}' is not installed.
Use:
sudo zypper install {package}
to install it.""")