Ejemplo n.º 1
0
def main():
    if not get_config_value('general.jedi', False):
        log.warn(
            'find_usages disabled, you can enable it by setting general.jedi to True'
        )
        return

    path = editor.get_path()
    if path is None:
        return

    if not path.endswith('.py'):
        return

    tab.save()

    text = editor.get_text()
    if not text:
        return

    line = source.get_line_number()
    column = source.get_column_index()

    if line is None or column is None:
        return

    script = jedi.api.Script(text, line, column, path)
    definitions = [d for d in script.usages() if d.module_path and d.line]

    if not definitions:
        console.hud_alert('Definition not found', 'error')
        return

    _select_location(definitions)
Ejemplo n.º 2
0
def main():
    path = editor.get_path()

    if not path:
        return

    if not path.endswith('.py'):
        return

    save(all=True)
    _run_unit_tests(path)
Ejemplo n.º 3
0
def main():
    from rope.base.project import Project
    from rope.base import libutils
    from rope.refactor.rename import Rename
    from rope.base.exceptions import RopeError

    path = editor.get_path()
    selection = editor.get_selection()

    if not path or not selection:
        console.hud_alert('Not a Python file', 'error')
        return

    tab.save()

    project = None
    try:
        project = Project(os.path.dirname(path), ropefolder=None)
        resource = libutils.path_to_resource(project, path)
        if not libutils.is_python_file(project, resource):
            console.hud_alert('Not a Python file', 'error')
            return

        renamer = Rename(project, resource, selection[0])
        old_name = renamer.get_old_name()

        if not old_name:
            console.hud_alert('Unable to get identifier name', 'error')
            return

        new_name = _ask_for_new_name(old_name)

        change_set = renamer.get_changes(new_name,
                                         docs=True,
                                         resources=[resource])
        if not change_set:
            console.hud_alert('No changes required')
            return

        if refactoring.ask_if_apply_change_set(change_set):
            refactoring.apply_change_set(change_set, path, selection)
            console.hud_alert('Identifier renamed')

    except RopeError as e:
        console.hud_alert(str(e), 'error')

    except KeyboardInterrupt:
        pass

    finally:
        if project:
            project.close()
Ejemplo n.º 4
0
def main(mock):
    import libfuturize.main

    path = editor.get_path()
    if not path or not path.endswith('.py'):
        console.hud_alert('Not a Python file', 'error')
        return

    tab.save()
    args = ['-1', '-n', '-w', '--all-imports', '--add-suffix', _SUFFIX, path]

    result = libfuturize.main.main(args)
    if result == 0 and _replace_file_content(path):
        console.hud_alert('Futurized')
    else:
        console.hud_alert('Failed to futurize', 'error')
Ejemplo n.º 5
0
def _editor_text():
    text = editor.get_text()

    range_end = len(text)

    if _remove_whitespaces():
        text = _remove_trailing_whitespaces(text)
        text = _remove_trailing_lines(text)
        editor.replace_text(0, range_end, text)
        tab.save()
        # Pythonista is adding '\n' automatically, so, if we removed them
        # all we have to simulate Pythonista behavior by adding '\n'
        # for pyflakes & pep8 analysis
        return text + '\n'

    tab.save()
    return text
Ejemplo n.º 6
0
def main():
    from rope.base.project import Project
    from rope.base import libutils
    from rope.refactor.importutils import ImportOrganizer
    from rope.base.exceptions import RopeError

    path = editor.get_path()
    selection = editor.get_selection()

    if not path or not selection:
        console.hud_alert('Not a Python file', 'error')
        return

    tab.save()

    project = None
    try:
        project = Project(os.path.dirname(path), ropefolder=None)
        resource = libutils.path_to_resource(project, path)
        if not libutils.is_python_file(project, resource):
            console.hud_alert('Not a Python file', 'error')
            return

        organizer = ImportOrganizer(project)
        change_set = organizer.organize_imports(resource)

        if not change_set:
            console.hud_alert('No changes required')
            return

        if refactoring.ask_if_apply_change_set(change_set):
            refactoring.apply_change_set(change_set, path, selection)
            console.hud_alert('Imports organized')

    except RopeError as e:
        console.hud_alert(str(e), 'error')

    except KeyboardInterrupt:
        pass

    finally:
        if project:
            project.close()
Ejemplo n.º 7
0
 def save_all():
     tab.save(True)
Ejemplo n.º 8
0
def main():
    tab.save(True)
    view = DragAndDropView()
    view.present('sheet')