Skip to content

Commit

Permalink
fix for python-module-list for edge-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 17, 2024
1 parent d5ba6b3 commit 516f7b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ max-attributes=12
max-bool-expr=5

# Maximum number of branch for function / method body.
max-branches=12
max-branches=14

# Maximum number of locals for function / method body.
max-locals=15
Expand All @@ -311,7 +311,7 @@ max-parents=7
max-public-methods=20

# Maximum number of return / yield for function / method body.
max-returns=6
max-returns=7

# Maximum number of statements in function / method body.
max-statements=50
Expand Down
25 changes: 19 additions & 6 deletions src/ansible-webui/aw/views/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ def _parsed_ansible_collections() -> dict:
if result['rc'] != 0:
return {}

collections_raw = result['stdout']
collections = {}
col_counter = {}
collection_path = ''
for line in collections_raw.split('\n'):
for line in result['stdout'].split('\n'):
if line.startswith('#'):
collection_path = line[1:]
continue
Expand Down Expand Up @@ -103,10 +102,24 @@ def _parsed_ansible_version(python_modules) -> dict:

def _parsed_python_modules() -> dict:
modules = OrderedDict()
module_list = [m[0] for m in metadata.packages_distributions().values()]
try:
module_list = [m[0] for m in metadata.packages_distributions().values()]

for module in sorted(module_list):
modules[module.lower()] = {'name': module, 'version': metadata.distribution(module).version}

except (ImportError, AttributeError):
result = process(['pip', 'list'])
if result['rc'] != 0:
return {}

for line in result['stdout'].split('\n'):
if line.find('.') == -1:
continue

for module in sorted(module_list):
modules[module.lower()] = {'name': module, 'version': metadata.distribution(module).version}
name, version = line.split(' ', 1)
name = name.strip()
modules[name.lower()] = {'name': name, 'version': version.strip()}

return modules

Expand All @@ -130,7 +143,7 @@ def system_environment(request) -> HttpResponse:
'env_jinja': ansible_version['jinja'],
'env_libyaml': ansible_version['libyaml'],
'env_python': f"{version_info.major}.{version_info.minor}.{version_info.micro}",
'env_python_modules': dict(sorted(python_modules.items())),
'env_python_modules': python_modules,
'env_ansible_config': _parsed_ansible_config(),
# 'env_ansible_roles': get_role_list(),
'env_ansible_collections': _parsed_ansible_collections(),
Expand Down

0 comments on commit 516f7b3

Please sign in to comment.