in azdev/utilities/path.py [0:0]
def get_path_table(include_only=None, include_whl_extensions=False):
""" Returns a table containing the long and short names of different modules and extensions and the path to them.
The structure looks like:
{
'core': {
NAME: PATH,
...
},
'mod': {
NAME: PATH,
...
},
'ext': {
NAME: PATH,
...
}
}
"""
from azure.cli.core.extension import EXTENSIONS_DIR # pylint: disable=import-error
# determine whether the call will filter or return all
if isinstance(include_only, str):
include_only = [include_only]
get_all = not include_only
table = {}
cli_repo_path = get_cli_repo_path()
ext_repo_paths = get_ext_repo_paths()
paths = os.path.normcase(
os.path.join(
cli_repo_path, 'src', 'azure-cli', 'azure', 'cli', 'command_modules', '*', '__init__.py'
)
)
modules_paths = glob(paths)
core_paths = glob(os.path.normcase(os.path.join(cli_repo_path, 'src', '*', 'setup.py')))
ext_paths = [x for x in find_files(ext_repo_paths, '*.*-info') if 'site-packages' not in x]
whl_ext_paths = [x for x in find_files(EXTENSIONS_DIR, '*.*-info') if 'site-packages' not in x]
def _update_table(package_paths, key):
if key not in table:
table[key] = {}
for path in package_paths:
folder = os.path.dirname(path)
base_name = os.path.basename(folder)
if key == 'ext':
short_name = base_name
long_name = next((item for item in os.listdir(folder) if item.startswith(EXTENSION_PREFIX)), None)
else:
short_name = base_name
long_name = '{}{}'.format(COMMAND_MODULE_PREFIX, base_name)
if get_all:
table[key][long_name if key == 'ext' else short_name] = folder
elif not include_only:
return # nothing left to filter
else:
# check and update filter
if short_name in include_only:
include_only.remove(short_name)
table[key][short_name] = folder
if long_name in include_only:
# long name takes precedence to ensure path doesn't appear twice
include_only.remove(long_name)
table[key].pop(short_name, None)
table[key][long_name] = folder
# Since include_only.remove will delete the found name
# Adjust the order of _update_table to ensure that extension is updated first.
# When the extension name and module name are the same
# Let azdev style tests the extension instead of the main module.
_update_table(ext_paths, 'ext')
if include_whl_extensions:
_update_table(whl_ext_paths, 'ext')
_update_table(modules_paths, 'mod')
_update_table(core_paths, 'core')
if include_only:
whl_extensions = [mod for whl_ext_path in whl_ext_paths for mod in include_only if mod in whl_ext_path]
if whl_extensions:
err = 'extension(s): [ {} ] installed from a wheel may need --include-whl-extensions option'.format(
', '.join(whl_extensions))
raise CLIError(err)
raise CLIError('unrecognized modules: [ {} ]'.format(', '.join(include_only)))
return table