Merge "Updated py_pkgs to index requirement files"
This commit is contained in:
commit
211dd9baa1
@ -37,6 +37,7 @@ GIT_PACKAGE_DEFAULT_PARTS = dict()
|
|||||||
|
|
||||||
|
|
||||||
ROLE_PACKAGES = dict()
|
ROLE_PACKAGES = dict()
|
||||||
|
ROLE_REQUIREMENTS = dict()
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS_FILE_TYPES = [
|
REQUIREMENTS_FILE_TYPES = [
|
||||||
@ -283,15 +284,18 @@ class DependencyFileProcessor(object):
|
|||||||
# Process everything simply by calling the method
|
# Process everything simply by calling the method
|
||||||
self._process_files()
|
self._process_files()
|
||||||
|
|
||||||
def _py_pkg_extend(self, packages):
|
def _py_pkg_extend(self, packages, py_package=None):
|
||||||
|
if py_package is None:
|
||||||
|
py_package = self.pip['py_package']
|
||||||
for pkg in packages:
|
for pkg in packages:
|
||||||
pkg_name = _pip_requirement_split(pkg)[0]
|
pkg_name = _pip_requirement_split(pkg)[0]
|
||||||
for py_pkg in self.pip['py_package']:
|
for py_pkg in py_package:
|
||||||
py_pkg_name = _pip_requirement_split(py_pkg)[0]
|
py_pkg_name = _pip_requirement_split(py_pkg)[0]
|
||||||
if pkg_name == py_pkg_name:
|
if pkg_name == py_pkg_name:
|
||||||
self.pip['py_package'].remove(py_pkg)
|
py_package.remove(py_pkg)
|
||||||
else:
|
else:
|
||||||
self.pip['py_package'].extend([i.lower() for i in packages])
|
py_package.extend([i.lower() for i in packages])
|
||||||
|
return py_package
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _filter_files(file_names, ext):
|
def _filter_files(file_names, ext):
|
||||||
@ -443,23 +447,24 @@ class DependencyFileProcessor(object):
|
|||||||
git_data=git_data
|
git_data=git_data
|
||||||
)
|
)
|
||||||
|
|
||||||
def _package_build_index(self, packages, role_name, var_name):
|
def _package_build_index(self, packages, role_name, var_name,
|
||||||
|
pkg_index=ROLE_PACKAGES):
|
||||||
self._py_pkg_extend(packages)
|
self._py_pkg_extend(packages)
|
||||||
if role_name:
|
if role_name:
|
||||||
if role_name in ROLE_PACKAGES:
|
if role_name in pkg_index:
|
||||||
role_pkgs = ROLE_PACKAGES[role_name]
|
role_pkgs = pkg_index[role_name]
|
||||||
else:
|
else:
|
||||||
role_pkgs = ROLE_PACKAGES[role_name] = dict()
|
role_pkgs = pkg_index[role_name] = dict()
|
||||||
|
|
||||||
pkgs = role_pkgs.get(var_name, list())
|
pkgs = role_pkgs.get(var_name, list())
|
||||||
if 'optional' not in var_name:
|
if 'optional' not in var_name:
|
||||||
pkgs.extend(packages)
|
pkgs.extend(packages)
|
||||||
ROLE_PACKAGES[role_name][var_name] = pkgs
|
pkg_index[role_name][var_name] = self._py_pkg_extend(packages, pkgs)
|
||||||
else:
|
else:
|
||||||
for k, v in ROLE_PACKAGES.items():
|
for k, v in pkg_index.items():
|
||||||
for item_name in v.keys():
|
for item_name in v.keys():
|
||||||
if var_name == item_name:
|
if var_name == item_name:
|
||||||
ROLE_PACKAGES[k][item_name].extend(packages)
|
pkg_index[k][item_name] = self._py_pkg_extend(packages, pkg_index[k][item_name])
|
||||||
|
|
||||||
def _process_files(self):
|
def _process_files(self):
|
||||||
"""Process files."""
|
"""Process files."""
|
||||||
@ -511,6 +516,8 @@ class DependencyFileProcessor(object):
|
|||||||
role_name=role_name,
|
role_name=role_name,
|
||||||
var_name=key
|
var_name=key
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
role_name = None
|
||||||
|
|
||||||
return_list = self._filter_files(self.file_names, 'txt')
|
return_list = self._filter_files(self.file_names, 'txt')
|
||||||
for file_name in return_list:
|
for file_name in return_list:
|
||||||
@ -523,15 +530,28 @@ class DependencyFileProcessor(object):
|
|||||||
for file_name in return_list:
|
for file_name in return_list:
|
||||||
if file_name.endswith('other-requirements.txt'):
|
if file_name.endswith('other-requirements.txt'):
|
||||||
continue
|
continue
|
||||||
|
if 'roles' in file_name:
|
||||||
|
_role_name = file_name.split('roles%s' % os.sep)[-1]
|
||||||
|
role_name = _role_name.split(os.sep)[0]
|
||||||
|
if not role_name:
|
||||||
|
role_name = 'default'
|
||||||
with open(file_name, 'r') as f:
|
with open(file_name, 'r') as f:
|
||||||
packages = [
|
packages = [
|
||||||
i.split()[0] for i in f.read().splitlines()
|
i.split()[0].lower() for i in f.read().splitlines()
|
||||||
if i
|
if i
|
||||||
if not i.startswith('#')
|
if not i.startswith('#')
|
||||||
]
|
]
|
||||||
self._py_pkg_extend(packages)
|
base_file_name = os.path.basename(file_name)
|
||||||
|
if base_file_name.endswith('test-requirements.txt'):
|
||||||
|
continue
|
||||||
|
self._package_build_index(
|
||||||
|
packages=packages,
|
||||||
|
role_name=role_name,
|
||||||
|
var_name='txt_file_packages',
|
||||||
|
pkg_index=ROLE_REQUIREMENTS
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
role_name = None
|
||||||
def _abs_path(path):
|
def _abs_path(path):
|
||||||
return os.path.abspath(
|
return os.path.abspath(
|
||||||
os.path.expanduser(
|
os.path.expanduser(
|
||||||
@ -596,6 +616,7 @@ class LookupModule(BASECLASS):
|
|||||||
for key, value in return_data.items():
|
for key, value in return_data.items():
|
||||||
if isinstance(value, (list, set)):
|
if isinstance(value, (list, set)):
|
||||||
return_data[key] = sorted(value)
|
return_data[key] = sorted(value)
|
||||||
|
return_data['role_requirement_files'] = ROLE_REQUIREMENTS
|
||||||
return [return_data]
|
return [return_data]
|
||||||
|
|
||||||
def run_v1(self, terms, inject=None, **kwargs):
|
def run_v1(self, terms, inject=None, **kwargs):
|
||||||
@ -644,6 +665,7 @@ class LookupModule(BASECLASS):
|
|||||||
for key, value in return_data.items():
|
for key, value in return_data.items():
|
||||||
if isinstance(value, (list, set)):
|
if isinstance(value, (list, set)):
|
||||||
return_data[key] = sorted(value)
|
return_data[key] = sorted(value)
|
||||||
|
return_data['role_requirement_files'] = ROLE_REQUIREMENTS
|
||||||
return [return_data]
|
return [return_data]
|
||||||
|
|
||||||
# Used for testing and debuging usage: `python plugins/lookups/py_pkgs.py ../`
|
# Used for testing and debuging usage: `python plugins/lookups/py_pkgs.py ../`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user