Skip to content

Commit

Permalink
Replaced usages of deprecated pkg_resources module (#1675)
Browse files Browse the repository at this point in the history
* Replaced usages of deprecated pkg_resources module with updated importlib module

---------

Signed-off-by: Eric Reinecke <[email protected]>
Signed-off-by: Eric Reinecke <[email protected]>
  • Loading branch information
reinecke committed Oct 29, 2023
1 parent bd7ae17 commit 17e9297
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
15 changes: 5 additions & 10 deletions src/py-opentimelineio/opentimelineio/console/otioconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,11 @@ def _parsed_args():
if result.version:
print(f"OpenTimelineIO version: {otio.__version__}")

if pkg_resources:
pkg_resource_plugins = list(
pkg_resources.iter_entry_points("opentimelineio.plugins")
)
if pkg_resource_plugins:
print("Plugins from pkg_resources:")
for plugin in pkg_resource_plugins:
print(f" {plugin.dist}")
else:
print("No pkg_resource plugins installed.")
entry_points = otio.plugins.manifest.plugin_entry_points()
if entry_points:
print("Plugins from installed packages:")
for plugin in entry_points:
print(f" {plugin.dist.name} {plugin.dist.version}")
parser.exit()

if not result.input:
Expand Down
24 changes: 7 additions & 17 deletions src/py-opentimelineio/opentimelineio/console/otiopluginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
import argparse
import fnmatch
import textwrap
import opentimelineio as otio

# on some python interpreters, pkg_resources is not available
try:
import pkg_resources
except ImportError:
pkg_resources = None
import opentimelineio as otio

OTIO_PLUGIN_TYPES = ['all'] + otio.plugins.manifest.OTIO_PLUGIN_TYPES

Expand Down Expand Up @@ -68,7 +63,7 @@ def _parsed_args():
default=False,
action="store_true",
help=(
"Print the otio and pkg_resource installed plugin version "
"Print the otio and installed plugin package version "
"information to the commandline."
),
)
Expand Down Expand Up @@ -183,16 +178,11 @@ def main():
if args.version:
print(f"OpenTimelineIO version: {otio.__version__}")

if pkg_resources:
pkg_resource_plugins = list(
pkg_resources.iter_entry_points("opentimelineio.plugins")
)
if pkg_resource_plugins:
print("Plugins from pkg_resources:")
for plugin in pkg_resource_plugins:
print(f" {plugin.dist}")
else:
print("No pkg_resource plugins installed.")
entry_points = otio.plugins.manifest.plugin_entry_points()
if entry_points:
print("Plugins from installed packages:")
for plugin in entry_points:
print(f" {plugin.dist.name} {plugin.dist.version}")

# list the loaded manifests
print("Manifests loaded:")
Expand Down
21 changes: 16 additions & 5 deletions src/py-opentimelineio/opentimelineio/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
]


def plugin_entry_points():
"""Returns the list of entry points for all available OpenTimelineIO
plugins.
"""
try:
entry_points = metadata.entry_points(group='opentimelineio.plugins')
except TypeError:
# For python <= 3.9
entry_points = metadata.entry_points().get(
'opentimelineio.plugins', []
)

return entry_points


def manifest_from_file(filepath):
"""Read the .json file at filepath into a :py:class:`Manifest` object."""

Expand Down Expand Up @@ -247,11 +262,7 @@ def load_manifest():
result.extend(manifest_from_file(json_path))

if not os.environ.get("OTIO_DISABLE_ENTRYPOINTS_PLUGINS"):
try:
entry_points = metadata.entry_points(group='opentimelineio.plugins')
except TypeError:
# For python <= 3.9
entry_points = metadata.entry_points().get('opentimelineio.plugins', [])
entry_points = plugin_entry_points()

for plugin in entry_points:
plugin_name = plugin.name
Expand Down

0 comments on commit 17e9297

Please sign in to comment.