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

Use newer importlib APIs when loading module for docstring & __version__ #499

Merged
merged 1 commit into from Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions flit_core/flit_core/common.py
Expand Up @@ -163,10 +163,13 @@ def get_docstring_and_version_via_import(target):
_import_i += 1

log.debug("Loading module %s", target.file)
from importlib.machinery import SourceFileLoader
sl = SourceFileLoader('flit_core.dummy.import%d' % _import_i, str(target.file))
from importlib.util import spec_from_file_location, module_from_spec
mod_name = 'flit_core.dummy.import%d' % _import_i
spec = spec_from_file_location(mod_name, target.file)
with _module_load_ctx():
m = sl.load_module()
m = module_from_spec(spec)
spec.loader.exec_module(m)

docstring = m.__dict__.get('__doc__', None)
version = m.__dict__.get('__version__', None)
return docstring, version
Expand Down