Skip to content

Commit

Permalink
making import_module private and deprecating public method (pytorch#6…
Browse files Browse the repository at this point in the history
…7990)

Summary:
Pull Request resolved: pytorch#67990

Duplicate of the following PR which was merged by mistake without ghimport
pytorch#67914

cc albanD NicolasHug

Test Plan: Imported from OSS

Reviewed By: H-Huang

Differential Revision: D32247560

Pulled By: jdsgomes

fbshipit-source-id: 8ba5ba7d17fc3d0d2c377da467ea805822e21ec1
  • Loading branch information
jdsgomes authored and facebook-github-bot committed Nov 9, 2021
1 parent 0a9cd6d commit 577a4d3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions torch/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):


# Copied from tools/shared/module_loader to be included in torch package
def import_module(name, path):
def _import_module(name, path):
import importlib.util
from importlib.abc import Loader
spec = importlib.util.spec_from_file_location(name, path)
Expand All @@ -77,6 +77,11 @@ def import_module(name, path):
return module


def import_module(name, path):
warnings.warn('The use of torch.hub.import_module is deprecated in v0.11 and will be removed in v0.12', DeprecationWarning)
return _import_module(name, path)


def _remove_if_exists(path):
if os.path.exists(path):
if os.path.isfile(path):
Expand Down Expand Up @@ -293,7 +298,7 @@ def list(github, force_reload=False, skip_validation=False):
sys.path.insert(0, repo_dir)

hubconf_path = os.path.join(repo_dir, MODULE_HUBCONF)
hub_module = import_module(MODULE_HUBCONF, hubconf_path)
hub_module = _import_module(MODULE_HUBCONF, hubconf_path)

sys.path.remove(repo_dir)

Expand Down Expand Up @@ -327,7 +332,7 @@ def help(github, model, force_reload=False, skip_validation=False):
sys.path.insert(0, repo_dir)

hubconf_path = os.path.join(repo_dir, MODULE_HUBCONF)
hub_module = import_module(MODULE_HUBCONF, hubconf_path)
hub_module = _import_module(MODULE_HUBCONF, hubconf_path)

sys.path.remove(repo_dir)

Expand Down Expand Up @@ -422,7 +427,7 @@ def _load_local(hubconf_dir, model, *args, **kwargs):
sys.path.insert(0, hubconf_dir)

hubconf_path = os.path.join(hubconf_dir, MODULE_HUBCONF)
hub_module = import_module(MODULE_HUBCONF, hubconf_path)
hub_module = _import_module(MODULE_HUBCONF, hubconf_path)

entry = _load_entry_from_hubconf(hub_module, model)
model = entry(*args, **kwargs)
Expand Down

0 comments on commit 577a4d3

Please sign in to comment.