Exemplo n.º 1
0
 def remove(self, packages):
     for name in packages:
         pkg = self.graph.find(name)
         if pkg:
             yield RemoveAction(pkg)
         elif not self.quiet:
             ui.error(ui.bold(name), 'is not installed')
Exemplo n.º 2
0
Arquivo: main.py Projeto: jayvdb/grip
def cli(glob=False, cwd=None, interactive=False, requirements_path=None):
    if requirements_path:
        requirements_path = os.path.abspath(requirements_path)

    if cwd:
        os.chdir(cwd)
        ui.debug('Working in', os.getcwd())

    app.interactive = interactive
    '''
    if glob:
        if app.virtualenv:
            ui.error('Cannot act on the global site when running inside a virtualenv shell.')
            ui.error('Run `deactivate` first.')
            sys.exit(1)
    '''

    if requirements_path:
        if not os.path.exists(requirements_path):
            ui.error(requirements_path, 'does not exist')
            sys.exit(1)

        requirements = TxtRequirements(requirements_path)
    else:
        requirements = app.locate_requirements()

    if requirements:
        app.set_requirements(requirements)
        ui.debug('Requirements file:', app.requirements)
Exemplo n.º 3
0
Arquivo: main.py Projeto: jayvdb/grip
def cmd_install(packages=None, save=False, upgrade=False):
    '''
    Installs listed dependencies

    Specific dependencies:

      grip install django celery==4.0.0

     From the requirements.txt file:

      grip install

     From a different file:

      grip -r reqs-test.txt install
    '''
    app.ensure_virtualenv()
    if len(packages):
        parent = Package(PackageGraph.USER_PKG, None)
        app.perform_install(
            [Dependency(spec, parent=parent) for spec in packages],
            save=save,
            upgrade=upgrade)
    elif app.requirements:
        app.perform_install_requirements()
    else:
        ui.error('No packages specified and no requirements file found')
        sys.exit(1)
    app.perform_check(silent=True)
Exemplo n.º 4
0
 def perform_run(self, binary, args):
     if not self.virtualenv:
         ui.error('No virtualenv available')
         sys.exit(1)
     path = os.path.join(self.virtualenv, 'bin', binary)
     if not os.path.exists(path):
         ui.error(path, 'does not exist')
         sys.exit(1)
     os.execvp(path, [binary] + list(args))
Exemplo n.º 5
0
 def perform_why(self, package):
     pkgs = self.load_dependency_graph()
     pkg = pkgs.find(package)
     if not pkg:
         ui.error(package, 'is not installed')
         sys.exit(1)
     for dep in pkg.incoming:
         print(ui.pkg(pkg), end='')
         while dep:
             print(' ←', ui.pkg(dep.parent), end='')
             dep = (dep.parent.incoming + [None])[0]
         print()
Exemplo n.º 6
0
    def perform_download(self, deps, source=False):
        for dep in deps:
            candidates = self.index.candidates_for(dep, source=source)
            best_candidate = self.index.best_candidate_of(dep, candidates)
            if not best_candidate:
                ui.error('No packages available for', ui.dep(dep))
                sys.exit(1)

            url = best_candidate.location.url
            name = os.path.basename(urlparse(url).path)
            ui.info('Downloading', ui.bold(name))
            urlretrieve(url, name)
Exemplo n.º 7
0
    def ensure_virtualenv(self):
        virtualenv = self.locate_virtualenv()
        if virtualenv:
            self.set_virtualenv(virtualenv)
        else:
            ui.warn('Could not find a local virtualenv.')
            if self.interactive and ui.yn('Create one?'):
                def validate_interpreter(name):
                    try:
                        subprocess.check_call([name, '-V'])
                    except:
                        raise Exception('Could not find %s' % name)

                name = ui.prompt('Folder name', default='venv')
                interpreter = ui.prompt('Interpreter', default='python3', validate=validate_interpreter)
                path = os.path.join(os.getcwd(), name)
                self.create_virtualenv(path, interpreter)
                self.set_virtualenv(path)
            else:
                ui.error('Aborting.')
                sys.exit(1)
Exemplo n.º 8
0
import grip.ui as ui

ui.info('asd')
ui.warn('asd')
ui.error('asd')

print('1.2.3', ui.yellow('->'), '4.5.6')

print(ui.yn('yeah, nope?'))

#print(ui.prompt('Name', validate=lambda x: int(x)))
Exemplo n.º 9
0
    def install(self, dep, upgrade=False, downgrade=False, save=False):
        installed_pkg = self.graph.find(dep.name)
        if installed_pkg and dep.matches_version(
                installed_pkg.version) and not upgrade:
            if not self.quiet:
                ui.info(ui.dep(dep), 'is already installed as',
                        ui.pkg(installed_pkg))
            if save:
                resolved_dep = Dependency.exact(installed_pkg)
                yield SaveAction(resolved_dep)
            return

        if dep.url:
            resolved_dep = dep
        else:
            candidates = self.index.candidates_for(dep)
            best_candidate = self.index.best_candidate_of(dep, candidates)
            if not best_candidate:
                if not self.quiet:
                    ui.error('No packages available for', ui.dep(dep))
                latest = self.index.best_candidate_of(None, candidates)
                if not self.quiet:
                    if latest:
                        ui.error('latest:', latest.version)
                    ui.error(
                        f'all: https://pypi.org/project/{dep.name}/#history')
                yield FailAction()

            resolved_dep = Dependency.exact(
                Package(dep.name, best_candidate.version))

        if not dep.url and installed_pkg and not dep.matches_version(
                installed_pkg.version):
            if not self.quiet:
                ui.warn('Dependency mismatch')
                print(' -', ui.pkg(installed_pkg), '(installed)')
                if len(installed_pkg.incoming):
                    print(
                        '   └ required by',
                        ui.pkg(installed_pkg.incoming[0].parent,
                               version=False))
                print(' -', ui.dep(dep), '(requested)')
                print('   └ required by', ui.pkg(dep.parent, version=False))

            if installed_pkg.version < best_candidate.version:
                if not self.quiet:
                    ui.warn('Will upgrade')
            elif not downgrade:
                if not self.quiet:
                    ui.warn('Will not downgrade')
                return
            else:
                if not self.quiet:
                    ui.warn('Will downgrade')

        if installed_pkg:
            yield RemoveAction(installed_pkg)

        yield InstallAction(resolved_dep)
        if save:
            yield SaveAction(resolved_dep)