How to use the argcomplete._check_module.ArgcompleteMarkerNotFound function in argcomplete

To help you get started, we’ve selected a few argcomplete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kislyuk / argcomplete / argcomplete / _check_console_script.py View on Github external
script_path = sys.argv[1]

    # Find the module and function names that correspond to this
    # assuming it is actually a console script.
    name = os.path.basename(script_path)
    entry_points = [ep for ep in importlib_entry_points()["console_scripts"] if ep.name == name]
    if not entry_points:
        raise ArgcompleteMarkerNotFound('no entry point found matching script')
    entry_point = entry_points[0]
    module_name, function_name = entry_point.value.split(":", 1)

    # Check this looks like the script we really expected.
    with open(script_path) as f:
        script = f.read()
    if 'from {} import {}'.format(module_name, function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')
    if 'sys.exit({}())'.format(function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')

    # Look for the argcomplete marker in the script it imports.
    with open(find(module_name, return_package=True)) as f:
        head = f.read(1024)
    if 'PYTHON_ARGCOMPLETE_OK' not in head:
        raise ArgcompleteMarkerNotFound('marker not found')
github kislyuk / argcomplete / argcomplete / _check_console_script.py View on Github external
def main():
    # Argument is the full path to the console script.
    script_path = sys.argv[1]

    # Find the module and function names that correspond to this
    # assuming it is actually a console script.
    name = os.path.basename(script_path)
    entry_points = [ep for ep in importlib_entry_points()["console_scripts"] if ep.name == name]
    if not entry_points:
        raise ArgcompleteMarkerNotFound('no entry point found matching script')
    entry_point = entry_points[0]
    module_name, function_name = entry_point.value.split(":", 1)

    # Check this looks like the script we really expected.
    with open(script_path) as f:
        script = f.read()
    if 'from {} import {}'.format(module_name, function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')
    if 'sys.exit({}())'.format(function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')

    # Look for the argcomplete marker in the script it imports.
    with open(find(module_name, return_package=True)) as f:
        head = f.read(1024)
    if 'PYTHON_ARGCOMPLETE_OK' not in head:
        raise ArgcompleteMarkerNotFound('marker not found')
github kislyuk / argcomplete / argcomplete / _check_console_script.py View on Github external
entry_point = entry_points[0]
    module_name, function_name = entry_point.value.split(":", 1)

    # Check this looks like the script we really expected.
    with open(script_path) as f:
        script = f.read()
    if 'from {} import {}'.format(module_name, function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')
    if 'sys.exit({}())'.format(function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')

    # Look for the argcomplete marker in the script it imports.
    with open(find(module_name, return_package=True)) as f:
        head = f.read(1024)
    if 'PYTHON_ARGCOMPLETE_OK' not in head:
        raise ArgcompleteMarkerNotFound('marker not found')
github kislyuk / argcomplete / argcomplete / _check_console_script.py View on Github external
if 'from {} import {}'.format(module_name, function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')
    if 'sys.exit({}())'.format(function_name) not in script:
        raise ArgcompleteMarkerNotFound('does not appear to be a console script')

    # Look for the argcomplete marker in the script it imports.
    with open(find(module_name, return_package=True)) as f:
        head = f.read(1024)
    if 'PYTHON_ARGCOMPLETE_OK' not in head:
        raise ArgcompleteMarkerNotFound('marker not found')


if __name__ == '__main__':
    try:
        main()
    except ArgcompleteMarkerNotFound as e:
        sys.exit(e)
github kislyuk / argcomplete / argcomplete / _check_module.py View on Github external
def find(name, return_package=False):
    names = name.split('.')
    spec = find_spec(names[0])
    if spec is None:
        raise ArgcompleteMarkerNotFound(
            'no module named "{}"'.format(names[0]))
    if not spec.has_location:
        raise ArgcompleteMarkerNotFound('cannot locate file')
    if spec.submodule_search_locations is None:
        if len(names) != 1:
            raise ArgcompleteMarkerNotFound(
                '{} is not a package'.format(names[0]))
        return spec.origin
    if len(spec.submodule_search_locations) != 1:
        raise ArgcompleteMarkerNotFound('expecting one search location')
    path = os.path.join(spec.submodule_search_locations[0], *names[1:])
    if os.path.isdir(path):
        filename = '__main__.py'
        if return_package:
            filename = '__init__.py'
        return os.path.join(path, filename)
    else:
        return path + '.py'
github kislyuk / argcomplete / argcomplete / _check_module.py View on Github external
def find(name, return_package=False):
    names = name.split('.')
    spec = find_spec(names[0])
    if spec is None:
        raise ArgcompleteMarkerNotFound(
            'no module named "{}"'.format(names[0]))
    if not spec.has_location:
        raise ArgcompleteMarkerNotFound('cannot locate file')
    if spec.submodule_search_locations is None:
        if len(names) != 1:
            raise ArgcompleteMarkerNotFound(
                '{} is not a package'.format(names[0]))
        return spec.origin
    if len(spec.submodule_search_locations) != 1:
        raise ArgcompleteMarkerNotFound('expecting one search location')
    path = os.path.join(spec.submodule_search_locations[0], *names[1:])
    if os.path.isdir(path):
        filename = '__main__.py'
        if return_package:
            filename = '__init__.py'
        return os.path.join(path, filename)
github kislyuk / argcomplete / argcomplete / _check_module.py View on Github external
def find(name, return_package=False):
    names = name.split('.')
    spec = find_spec(names[0])
    if spec is None:
        raise ArgcompleteMarkerNotFound(
            'no module named "{}"'.format(names[0]))
    if not spec.has_location:
        raise ArgcompleteMarkerNotFound('cannot locate file')
    if spec.submodule_search_locations is None:
        if len(names) != 1:
            raise ArgcompleteMarkerNotFound(
                '{} is not a package'.format(names[0]))
        return spec.origin
    if len(spec.submodule_search_locations) != 1:
        raise ArgcompleteMarkerNotFound('expecting one search location')
    path = os.path.join(spec.submodule_search_locations[0], *names[1:])
    if os.path.isdir(path):
        filename = '__main__.py'
        if return_package:
            filename = '__init__.py'
        return os.path.join(path, filename)
    else:
        return path + '.py'
github kislyuk / argcomplete / argcomplete / _check_module.py View on Github external
filename = find(name)
    if hasattr(tokenize, 'open'):
        open_func = tokenize.open
    else:
        open_func = open

    try:
        fp = open_func(filename)
    except OSError:
        raise ArgcompleteMarkerNotFound('cannot open file')

    with fp:
        head = fp.read(1024)

    if 'PYTHON_ARGCOMPLETE_OK' not in head:
        raise ArgcompleteMarkerNotFound('marker not found')