Skip to content

Commit

Permalink
Merge pull request #499 from pypa/importlib-warning
Browse files Browse the repository at this point in the history
Use newer importlib APIs when loading module for docstring & __version__
  • Loading branch information
takluyver committed Feb 21, 2022
2 parents 4794dce + 291e928 commit a63f42b
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit a63f42b

Please sign in to comment.