Fix requirements detection:

- multiple -e packages were not detected (only the first one)
- trains installed from git + running with trains in python path resulted in double entry of trains
- Do not add -e to packages installed from git repositories, Trains-Agent doesn't like it
This commit is contained in:
allegroai 2020-07-30 15:12:46 +03:00
parent 1d277d01d3
commit 619be3dc75
3 changed files with 25 additions and 8 deletions

View File

@ -128,7 +128,10 @@ class ScriptRequirements(object):
name = 'torch'
k, v = reqs_lower.get(name, (None, None))
if k and v is not None:
conda_requirements += '{0} {1} {2}\n'.format(k, '==', v.version)
if v.version:
conda_requirements += '{0} {1} {2}\n'.format(k, '==', v.version)
else:
conda_requirements += '{0}\n'.format(k)
except Exception:
conda_requirements = ''
@ -147,7 +150,10 @@ class ScriptRequirements(object):
if local_pks:
requirements_txt += '\n# Local modules found - skipping:\n'
for k, v in local_pks.sorted_items():
requirements_txt += '# {0} == {1}\n'.format(k, v.version)
if v.version:
requirements_txt += '# {0} == {1}\n'.format(k, v.version)
else:
requirements_txt += '# {0}\n'.format(k)
# requirement summary
requirements_txt += '\n'
@ -158,9 +164,11 @@ class ScriptRequirements(object):
if forced_version:
version = forced_version
# requirements_txt += ''.join(['# {0}\n'.format(c) for c in v.comments.sorted_items()])
if k == '-e':
requirements_txt += '{0} {1}\n'.format(k, version)
elif v:
if k == '-e' and version:
requirements_txt += '{0}\n'.format(version)
elif k.startswith('-e '):
requirements_txt += '{0} {1}\n'.format(k.replace('-e ', '', 1), version or '')
elif version:
requirements_txt += '{0} {1} {2}\n'.format(k, '==', version)
else:
requirements_txt += '{0}\n'.format(k)

View File

@ -73,6 +73,7 @@ class GenerateReqs(object):
candidates |= set(self._force_modules_reqs.keys())
logger.info('Check module in local environment.')
reqs_module_name = []
for name in candidates:
logger.info('Checking module: %s', name)
if name in self._installed_pkgs:
@ -80,15 +81,17 @@ class GenerateReqs(object):
if name not in modules:
modules.add(name, name, 0)
reqs.add(pkg_name, version, modules[name])
reqs_module_name.append(name)
elif name in modules:
guess.add(name, 0, modules[name])
# add local modules, so we know what is used but not installed.
project_path = os.path.realpath(self._project_path)
for name in self._local_mods:
if name in modules:
if name in modules and name not in reqs_module_name:
if name in self._force_modules_reqs:
reqs.add(name, self._force_modules_reqs[name], modules[name])
reqs_module_name.append(name)
continue
# if this is a base module, we have it in installed modules but package name is None

View File

@ -373,7 +373,11 @@ def _search_path(path):
git_url = '{vcs}+{url}@{commit}#egg={package}'.format(
vcs=vcs_info['vcs_info']['vcs'], url=vcs_info['url'],
commit=vcs_info['vcs_info']['commit_id'], package=pkg_name)
mapping[pkg_name] = ('-e', git_url)
# Bugfix: package name should be the URL link, because we need it unique
# mapping[pkg_name] = ('-e', git_url)
mapping[pkg_name] = ('-e {}'.format(git_url), '')
continue
except Exception:
pass
@ -434,6 +438,8 @@ def _search_path(path):
git_url = 'git+{0}@{1}#egg={2}'.format(url, branch, pkg_name)
with open(top_level, 'r') as f:
for line in f:
mapping[line.strip()] = ('-e', git_url)
# Bugfix: package name should be the URL link, because we need it unique
# mapping[line.strip()] = ('-e', git_url)
mapping[line.strip()] = ('-e {}'.format(git_url), '')
return mapping