Improve auto package detection

This commit is contained in:
allegroai 2019-08-07 00:05:51 +03:00
parent 3ab1c261e7
commit 1d6727d2c0
3 changed files with 32 additions and 5 deletions

View File

@ -24,6 +24,28 @@ class ScriptRequirements(object):
def __init__(self, root_folder):
self._root_folder = root_folder
@staticmethod
def get_installed_pkgs_detail(reqs):
"""
HACK: bugfix of the original pigar get_installed_pkgs_detail
Get mapping for import top level name
and install package name with version.
"""
mapping = dict()
for path in sys.path:
if os.path.isdir(path) and path.rstrip('/').endswith(
('site-packages', 'dist-packages')):
new_mapping = reqs._search_path(path)
# BUGFIX:
# override with previous, just like python resolves imports, the first match is the one used.
# unlike the original implementation, where the last one is used.
new_mapping.update(mapping)
mapping = new_mapping
return mapping
def get_requirements(self):
try:
from pigar import reqs
@ -31,7 +53,11 @@ class ScriptRequirements(object):
from pigar.__main__ import GenerateReqs
from pigar.log import logger
logger.setLevel(logging.WARNING)
installed_pkgs = reqs.get_installed_pkgs_detail()
try:
# first try our version, if we fail revert to the internal implantation
installed_pkgs = self.get_installed_pkgs_detail(reqs)
except Exception:
installed_pkgs = reqs.get_installed_pkgs_detail()
gr = GenerateReqs(save_path='', project_path=self._root_folder, installed_pkgs=installed_pkgs,
ignores=['.git', '.hg', '.idea', '__pycache__', '.ipynb_checkpoints'])
reqs, try_imports, guess = gr.extract_reqs()

View File

@ -3,7 +3,7 @@ import sys
import six
from pathlib2 import Path
from trains.binding.frameworks.base_bind import PatchBaseModelIO
from ...binding.frameworks.base_bind import PatchBaseModelIO
from ..frameworks import _patched_call, WeightsFileHandler, _Empty
from ..import_bind import PostImportHookPatching
from ...config import running_remotely

View File

@ -989,13 +989,14 @@ class Task(_Task):
# check if we crashed, ot the signal is not interrupt (manual break)
task_status = ('stopped', )
if self.__exit_hook:
if self.__exit_hook.exception is not None or \
(not self.__exit_hook.remote_user_aborted and self.__exit_hook.signal not in (None, 2)):
if (self.__exit_hook.exception and not isinstance(self.__exit_hook.exception, KeyboardInterrupt)) \
or (not self.__exit_hook.remote_user_aborted and self.__exit_hook.signal not in (None, 2)):
task_status = ('failed', 'Exception')
wait_for_uploads = False
else:
wait_for_uploads = (self.__exit_hook.remote_user_aborted or self.__exit_hook.signal is None)
if not self.__exit_hook.remote_user_aborted and self.__exit_hook.signal is None:
if not self.__exit_hook.remote_user_aborted and self.__exit_hook.signal is None and \
not self.__exit_hook.exception:
task_status = ('completed', )
else:
task_status = ('stopped', )