Skip to content

Commit

Permalink
Remove sys.version_info check from __main__
Browse files Browse the repository at this point in the history
  • Loading branch information
dbieber committed Sep 20, 2024
1 parent 5d0706d commit c235876
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions fire/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

import importlib
from importlib import util
import os
import sys

Expand Down Expand Up @@ -57,27 +58,13 @@ def import_from_file_path(path):

module_name = os.path.basename(path)

if sys.version_info.major == 3 and sys.version_info.minor < 5:
loader = importlib.machinery.SourceFileLoader( # pylint: disable=no-member
fullname=module_name,
path=path,
)
spec = util.spec_from_file_location(module_name, path)

module = loader.load_module(module_name) # pylint: disable=deprecated-method
if spec is None:
raise IOError('Unable to load module from specified path.')

elif sys.version_info.major == 3:
from importlib import util # pylint: disable=g-import-not-at-top,import-outside-toplevel,no-name-in-module
spec = util.spec_from_file_location(module_name, path)

if spec is None:
raise IOError('Unable to load module from specified path.')

module = util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module) # pytype: disable=attribute-error

else:
import imp # pylint: disable=g-import-not-at-top,import-outside-toplevel,deprecated-module,import-error
module = imp.load_source(module_name, path)
module = util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module) # pytype: disable=attribute-error

return module, module_name

Expand Down

0 comments on commit c235876

Please sign in to comment.