-
Notifications
You must be signed in to change notification settings - Fork 33
Eliminate dependency on deprecated setuptools.pkg_resources #280
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes.
import traceback | ||
|
||
from backports.entry_points_selectable import entry_points | ||
|
||
from hotdoc.core.links import Link | ||
from hotdoc.utils.loggable import info, debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are added simply because they're used in the get_language_classes()
function later on, but would have been undefined if they'd actually been called.
group='hotdoc.extensions.gi.languages', | ||
name='get_language_classes'): | ||
try: | ||
ep_name = entry_point.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here (despite ep_name
never being used) because the results of importlib.metadata.entry_points()
are documented as not being validated; invoking any property is the suggested means of triggering validation.
# pylint: disable=broad-except | ||
except Exception as exc: | ||
info("Failed to load %s" % entry_point.module_name, exc) | ||
info("Failed to load %s" % str(entry_point), exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the same token, entry_point.name
(the equivalent of entry_point.module_name
from pkg_resources
isn't necessarily going to exist on every result from entry_points()
, so we can't rely on it for logging. Logging the string value of entry_point
ensures that it'll be logged even if it isn't a valid EntryPoint
object.
hotdoc/utils/utils.py
Outdated
if entry_point.module_name == 'hotdoc_c_extension.extensions': | ||
continue | ||
try: | ||
if entry_point.module == 'hotdoc_c_extension.extensions': | ||
continue | ||
ep_name = entry_point.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same validation issue here; since we can't be sure entry_point
has a .module
property, we need to check it inside the try:
.
For the record, I didn't regenerate the pinned In this case, Fortunately, |
Thanks A TON for looking at this :) |
I believe this is now fixed. I also added (I'm now importing it explicitly to access its |
68b0c5c
to
0f7ded7
Compare
lgtm now, huge thanks again for performing maintenance on this project :) |
This PR eliminates use of setuptools' deprecated
pkg_resources
inhotdoc.utils.utils
andhotdoc.extensions.gi.utils
, substituting equivalent APIs provided byimportlib.metadata.entry_points()
.The
entry_points()
function used is actually imported frombackports.entry_points_selectable
(a new dependency, added tosetup.py
), which ensures that calls toentry_points()
can take filtering arguments even in Python < 3.10, whereimportlib.metadata
didn't natively support such usage.(In practice, for recent Python 3.10+ releases,
backports.entry_points_selectable.entry_points
will beimportlib.metadata.entry_points
.)The resulting
hotdoc
package passes all unit tests inhotdoc.tests
on Python 3.12, even in a virtual environment with thesetuptools
package removed:hotdoc
from themaster
branch, in that same situation, fails several tests outright, and skips over 80% of them: