Skip to content

Commit

Permalink
Use newer importlib APIs when loading module for docstring & __version__
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jan 2, 2022
1 parent 68ed852 commit 291e928
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
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 291e928

Please sign in to comment.