Dont crash if __file__ is not set by importer

This commit is contained in:
John Vandenberg
2021-04-30 10:18:56 +08:00
parent ab976847c9
commit a730554030

View File

@@ -4131,8 +4131,13 @@ def add_import_hook(additional_paths=[]):
# Automatically include the system and built-in capnp paths # Automatically include the system and built-in capnp paths
# Highest priority at position 0 # Highest priority at position 0
extra_paths = [ try:
_os.path.join(_os.path.dirname(__file__), '..'), # Built-in (only used if bundled) this_file_path = __file__
except NameError:
this_file_path = None
extra_paths = ([
_os.path.join(_os.path.dirname(this_file_path), '..'), # Built-in (only used if bundled)
] if this_file_path else []) + [
# Common macOS brew location # Common macOS brew location
'/usr/local/include/capnp', '/usr/local/include/capnp',
'/usr/local/include', '/usr/local/include',