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