示例#1
0
    def __call__(self) -> bool:
        # get and create venv
        venvs = VEnvs(path=self.config['venv'])
        venv = venvs.get(Path(self.config['project']), env=self.config.env)
        if not venv.exists():
            self.logger.info('Creating venv for project...')
            python = get_python(self.config)
            self.logger.debug('choosen python',
                              extra=dict(version=python.version))
            venv.create(python_path=python.path)

        # get env vars
        env_vars = os.environ.copy()
        if 'vars' in self.config:
            env_vars.update(self.config['vars'])
        env_vars = read_dotenv(
            path=Path(self.config['dotenv']),
            env_vars=env_vars,
        )

        shells = Shells(bin_path=venv.bin_path)
        with override_env_vars(env_vars):
            shells.run()
        self.logger.info('shell closed')
        return True
示例#2
0
    def __call__(self) -> bool:
        venv = get_venv(config=self.config)
        shells = Shells(bin_path=venv.bin_path)

        data = dict(
            exists=venv.exists(),
            venv=str(venv.path),
            project=self.config['project'],
        )

        if venv.exists():
            data.update(dict(
                activate=str(venv.bin_path / shells.current.activate),
                bin=str(venv.bin_path),
                lib=str(venv.lib_path),
                lib_size=format_size(get_path_size(venv.lib_path)),
                python=str(venv.python_path),
            ))
        print(make_json(
            data=data,
            key=self.config.get('filter'),
            colors=not self.config['nocolors'],
            table=self.config['table'],
        ))
        return True
示例#3
0
    def __call__(self):
        shell = Shells(bin_path=None).shell_name
        msg = 'Autocompletion installed. Please, reload your shell'

        if shell == 'bash':
            self._bash()
            self.logger.info(msg)
            return True

        if shell == 'zsh':
            self._zsh()
            self.logger.info(msg)
            return True

        self.logger.error('unsupported shell', extra=dict(shell=shell))
        return False
示例#4
0
    def __call__(self) -> bool:
        venv = get_venv(config=self.config)
        shells = Shells(bin_path=venv.bin_path)

        data = dict(
            exists=venv.exists(),
            paths=dict(
                venv=str(venv.path),
                project=self.config['project'],
            ),
        )

        if venv.exists():
            data['paths'].update(
                dict(
                    activate=str(venv.bin_path / shells.current.activate),
                    bin=str(venv.bin_path),
                    lib=str(venv.lib_path),
                    python=str(venv.python_path),
                ))
            impl = venv.python.implementation
            if impl == 'python':
                impl = 'cpython'
            data.update(
                dict(
                    sizes=dict(
                        lib=format_size(get_path_size(venv.lib_path)),
                        venv=format_size(get_path_size(venv.path)),
                    ),
                    python=dict(
                        version=str(venv.python.version),
                        implementation=impl,
                    ),
                ))
        print(
            make_json(
                data=data,
                key=self.config.get('filter'),
                colors=not self.config['nocolors'],
                table=self.config['table'],
            ))
        return True
示例#5
0
def test_name():
    shells = Shells(bin_path=None)
    name = shells.shell_name
    assert type(name) is str
    assert name in shells.shells
示例#6
0
def test_path():
    shells = Shells(bin_path=None)
    path = shells.shell_path
    assert isinstance(path, Path)
    assert path.exists() is True
    assert path.stem == shells.shell_name
示例#7
0
def test_command():
    shells = Shells(bin_path=None)
    for cls in shells.shells.values():
        shell = cls(bin_path=Path(), shell_path=None)
        assert isinstance(shell.command, (list, str))
示例#8
0
def test_args():
    shells = Shells(bin_path=None)
    for cls in shells.shells.values():
        shell = cls(bin_path=Path(), shell_path=None)
        assert isinstance(shell.args, list)