Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced usages of deprecated pkg_resources module #1675

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 18 additions & 5 deletions src/py-opentimelineio/opentimelineio/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
from pathlib import Path
from typing import Union

try:
from importlib import metadata
Expand All @@ -32,6 +33,22 @@
]


def plugin_entry_points(
) -> Union[metadata.EntryPoints, metadata.SelectableGroups]:
"""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 +264,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
Loading