Skip to content

Commit

Permalink
cleanup: Refactor DLL loading and remove metadata from __init__.py
Browse files Browse the repository at this point in the history
Simplified the DLL loading process for Windows platform by removing version-specific conditions. Also, removed unnecessary metadata such as status, author, email, license, and copyright from the file. All that stuff can be retrieved with importlib.metadata.

Signed-off-by: Zach Lewis <[email protected]>
  • Loading branch information
zachlewis committed Oct 30, 2024
1 parent babfa59 commit 6d8ceb5
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,19 @@
# Python wheel module is dynamically linked to the OIIO DLL present in the bin folder.
_bin_dir = os.path.join(_here, "bin")
if os.path.exists(_bin_dir):
if sys.version_info >= (3, 8):
os.add_dll_directory(_bin_dir)
else:
os.environ['PATH'] = '{0};{1}'.format(_bin_dir, os.getenv('PATH', ''))

#TODO: Remove. Python 3.8 stopped loading DLLs from PATH on Windows for security reasons.
if sys.version_info >= (3, 8):
os.add_dll_directory(_bin_dir)
elif sys.version_info >= (3, 8):
# This works around the python 3.8 change to stop loading DLLs from PATH on Windows.
# We reproduce the old behavior by manually tokenizing PATH, checking that the
# directories exist and are not ".", then add them to the DLL load path.
# Set the environment variable "OIIO_LOAD_DLLS_FROM_PATH" to "0" to disable this behavior.
if os.getenv("OIIO_LOAD_DLLS_FROM_PATH", "1") == "1":
logger.warning(
"Adding DLL directories to PATH. This behavior will be removed in "
"a future version. Set the environment variable OIIO_LOAD_DLLS_FROM_PATH "
"to 0 to disable this behavior."
)
for path in os.getenv("PATH", "").split(os.pathsep):
if os.path.exists(path) and path != ".":
os.add_dll_directory(path)

from .OpenImageIO import * # type: ignore # noqa: F401, F403, E402

__status__ = "production"

__author__ = "OpenImageIO Contributors"

__email__ = "[email protected]"

__license__ = "SPDX-License-Identifier: Apache-2.0"

__copyright__ = "Copyright Contributors to the OpenImageIO Project"

__doc__ = """
OpenImageIO is a toolset for reading, writing, and manipulating image files of
any image file format relevant to VFX / animation via a format-agnostic API
Expand Down

0 comments on commit 6d8ceb5

Please sign in to comment.