Completed
Push — master ( 1a2d15...4d49a3 )
by Björn
57s
created

neovim_gui.main()   C

Complexity

Conditions 9

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 9
dl 0
loc 55
rs 5.4159

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
"""CLI for accessing the gtk/tickit UIs implemented by this package."""
2
import shlex
3
4
import click
0 ignored issues
show
Configuration introduced by
The import click could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
6
from .ui_bridge import UIBridge
7
from neovim import attach
0 ignored issues
show
Configuration introduced by
The import neovim could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
8
from neovim.compat import IS_PYTHON3
0 ignored issues
show
Configuration introduced by
The import neovim.compat could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
Unused Code introduced by
Unused IS_PYTHON3 imported from neovim.compat
Loading history...
9
10
11
@click.command(context_settings=dict(allow_extra_args=True))
12
@click.option('--prog')
13
@click.option('--notify', '-n', default=False, is_flag=True)
14
@click.option('--listen', '-l')
15
@click.option('--connect', '-c')
16
@click.option('--profile',
17
              default='disable',
18
              type=click.Choice(['ncalls', 'tottime', 'percall', 'cumtime',
19
                                 'name', 'disable']))
20
@click.pass_context
21
def main(ctx, prog, notify, listen, connect, profile):
22
    """Entry point."""
23
    address = connect or listen
24
25
    if address:
26
        import re
27
        p = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\:\d{1,5})?$')
28
29
        if p.match(address):
30
            args = ('tcp',)
31
            kwargs = {'address': address}
32
        else:
33
            args = ('socket',)
34
            kwargs = {'path': address}
35
36
    if connect:
37
        # connect to existing instance listening on address
38
        nvim = attach(*args, **kwargs)
39
    elif listen:
40
        # spawn detached instance listening on address and connect to it
41
        import os
42
        import time
43
        from subprocess import Popen
44
        os.environ['NVIM_LISTEN_ADDRESS'] = address
45
        nvim_argv = shlex.split(prog or 'nvim --headless') + ctx.args
46
        # spawn the nvim with stdio redirected to /dev/null.
47
        dnull = open(os.devnull)
48
        p = Popen(nvim_argv, stdin=dnull, stdout=dnull, stderr=dnull)
49
        dnull.close()
50
        while p.poll() or p.returncode is None:
51
            try:
52
                nvim = attach(*args, **kwargs)
53
                break
54
            except IOError:
55
                # socket not ready yet
56
                time.sleep(0.050)
57
    else:
58
        # spawn embedded instance
59
        nvim_argv = shlex.split(prog or 'nvim --embed') + ctx.args
60
        nvim = attach('child', argv=nvim_argv)
61
62
    from .gtk_ui import GtkUI
63
    ui = GtkUI()
64
    bridge = UIBridge()
65
    bridge.connect(nvim, ui, profile if profile != 'disable' else None, notify)
66
67
68
if __name__ == '__main__':
69
    main()
0 ignored issues
show
Bug introduced by
It seems like a value for argument ctx is missing in the function call.
Loading history...
Bug introduced by
It seems like a value for argument prog is missing in the function call.
Loading history...
Bug introduced by
It seems like a value for argument notify is missing in the function call.
Loading history...
Bug introduced by
It seems like a value for argument listen is missing in the function call.
Loading history...
Bug introduced by
It seems like a value for argument connect is missing in the function call.
Loading history...
Bug introduced by
It seems like a value for argument profile is missing in the function call.
Loading history...
70