def do_makeerror(self, subcmd, opts, what): """${cmd_name}: Make an error. Use -v to see full traceback ${cmd_usage} ${cmd_option_list} """ with self.bootstrapped(): LOG.debug('About to make an error! %s', what) textui.askyesno('Press enter to proceed:', default=True) 1 / 0
def do_makeerror(self, subcmd, opts, what): """${cmd_name}: Make an error. Use -v to see full traceback ${cmd_usage} ${cmd_option_list} """ with self.bootstrapped(): LOG.debug('About to make an error! %s', what) textui.askyesno('Press enter to proceed:', default=True) 1/0
def _pep370_fix_path_unix(): """If ~/.local/bin is not in $PATH, automatically add them Do this only with the user's consent. And do not run this check more than once (i.e., run only when PyPM is *first run*). """ if sys.platform.startswith('win'): return # MSI does this on Windows # Proceed only when the terminal is interactive and was never run before isatty = (sys.stdin.isatty() and sys.stdout.isatty()) firstrun_file = P.join(application.locations.user_cache_dir, '.firstrun-pep370') if (not isatty) or P.exists(firstrun_file): return import site from datetime import datetime pathenv = [ P.abspath(x.strip()) for x in os.environ.get('PATH', '').split(':') ] binpath = P.abspath(P.join(site.USER_BASE, 'bin')) profile = P.expanduser('~/.profile' if sys.platform == 'darwin' else '~/.bashrc') profile_lines = [ '# PEP 370 PATH added by PyPM on %s' % datetime.now(), 'export PATH=%s:$PATH' % binpath, ] already_in_profile = P.exists(profile) and profile_lines[1] in [ l.strip() for l in open(profile).readlines() ] # Proceed only if ~/.local/bin is neither in $PATH, nor added to profile if binpath in pathenv or already_in_profile: return # Add to profile on the user's consent msg = ('Packages will install their script files to "%s" ' '(as per PEP 370). This directory is not yet in your $PATH. ' 'Would you like PyPM to add it by appending to "%s"?') % ( concise_path(binpath), concise_path(profile)) if textui.askyesno(wrapped(msg, '*** '), default=True): if P.exists(profile): sh.cp(profile, profile + '.bak') # take a backup first with open(profile, 'a') as f: f.write('\n%s\n' % '\n'.join(profile_lines)) print('You may now reopen your shell for the changes to take effect.') sh.mkdirs(P.dirname(firstrun_file)) with open(firstrun_file, 'w') as f: pass # prevent future runs
def _pep370_fix_path_unix(): """If ~/.local/bin is not in $PATH, automatically add them Do this only with the user's consent. And do not run this check more than once (i.e., run only when PyPM is *first run*). """ if sys.platform.startswith('win'): return # MSI does this on Windows # Proceed only when the terminal is interactive and was never run before isatty = (sys.stdin.isatty() and sys.stdout.isatty()) firstrun_file = P.join(application.locations.user_cache_dir, '.firstrun-pep370') if (not isatty) or P.exists(firstrun_file): return import site from datetime import datetime pathenv = [P.abspath(x.strip()) for x in os.environ.get('PATH', '').split(':')] binpath = P.abspath(P.join(site.USER_BASE, 'bin')) profile = P.expanduser('~/.profile' if sys.platform == 'darwin' else '~/.bashrc') profile_lines = [ '# PEP 370 PATH added by PyPM on %s' % datetime.now(), 'export PATH=%s:$PATH' % binpath, ] already_in_profile = P.exists(profile) and profile_lines[1] in [ l.strip() for l in open(profile).readlines() ] # Proceed only if ~/.local/bin is neither in $PATH, nor added to profile if binpath in pathenv or already_in_profile: return # Add to profile on the user's consent msg = ( 'Packages install script files to "%s" ' '(as per PEP 370). This directory is not yet in your $PATH. ' 'Would you like PyPM to add it to $PATH by modifying (with backup) "%s"?' ) % (binpath, profile) if textui.askyesno(wrapped(msg, '*** '), default=True): if P.exists(profile): sh.cp(profile, profile+'.bak') # take a backup first with open(profile, 'a') as f: f.write('\n%s\n' % '\n'.join(profile_lines)) print ('You may now reopen your shell for the changes to take effect.') sh.mkdirs(P.dirname(firstrun_file)) with open(firstrun_file, 'w') as f: pass # prevent future runs
def apply(self, depgraph, _requested_rmlist=[]): """Apply marks from the given depgraph This effectly installs/removes/changes packages in ``pyenv`` based on what is marked in the depgraph. `_requested_rmlist` - packages requested to be removed; not to confirm Return the applied marks (``DepGraph.get_marks``); return None if no no change was made. """ marks = depgraph.get_marks() if not marks['install'] and not marks['change'] and not marks['remove']: return None # Display to the user what we are going to do messages = [] def mark_show(verb, list, item_print_func): if not list: return messages.append( 'The following packages will be {verb} {0}:\n{1}'.format( self.pypmenv.pyenv.printable_location, wrapped(' '.join(item_print_func(item) for item in list), prefix=' ', break_on_hyphens=False), verb=verb)) mark_show('installed into', marks['install'], attrgetter('full_name')) def change_printer(p_tup): p1, p2 = p_tup return '{0.name}({0.printable_version}->{1.printable_version})'.format( p1,p2) mark_show('upgraded in', [(p1,p2) for (p1,p2) in marks['change'] if p1.version_key < p2.version_key], change_printer) mark_show('DOWNGRADED in', [(p1,p2) for (p1,p2) in marks['change'] if p1.version_key >= p2.version_key], change_printer) mark_show('UNINSTALLED from', marks['remove'], attrgetter('full_name')) print('\n'.join(messages)) # Confirm if necessary if self.pypmenv.options['interactive']: i, r, c = map(len, [ marks['install'], marks['remove'], marks['change']]) # rdiff: no. of unrequested packages to be removed a = [p.name for p in marks['remove']] b = [Requirement.parse(n).project_name.lower() for n in _requested_rmlist] rdiff = len(set(a).difference(set(b))) trivial_action = any([ (i and not r and not c), # install, without rm/upgrade (not i and r and not rdiff and not c), # no extra uninstalls ]) if not trivial_action: if not askyesno('Continue?', default=True): return None del i, r, c # 1. download packages to_download = sorted( set.union(set(marks['install']), [p2 for p1, p2 in marks['change']]), key=lambda p: p.name) locations = Downloader(self.pypmenv).download_packages(to_download) # 2. uninstall packages for ipkg in marks['remove']: self._uninstall(ipkg) # 3. install new packages for pkg in marks['install']: self._install(pkg, locations[pkg]) # 4. upgrade/downgrade existing packages for ipkg, pkg in marks['change']: # XXX: need transaction here self._uninstall(ipkg) self._install(pkg, locations[pkg]) return marks
def apply(self, depgraph, _requested_rmlist=[]): """Apply marks from the given depgraph This effectly installs/removes/changes packages in ``pyenv`` based on what is marked in the depgraph. `_requested_rmlist` - packages requested to be removed; not to confirm Return the applied marks (``DepGraph.get_marks``); return None if no no change was made. """ marks = depgraph.get_marks() if not marks['install'] and not marks['change'] and not marks['remove']: return None # Display to the user what we are going to do messages = [] def mark_show(verb, list, item_print_func): if not list: return messages.append( 'The following packages will be {verb} {0}:\n{1}'.format( self.pypmenv.pyenv.printable_location, wrapped(' '.join(item_print_func(item) for item in list), prefix=' ', break_on_hyphens=False), verb=verb)) mark_show('installed into', marks['install'], attrgetter('full_name')) def change_printer(p_tup): p1, p2 = p_tup return '{0.name}({0.printable_version}->{1.printable_version})'.format( p1, p2) mark_show('upgraded in', [(p1, p2) for (p1, p2) in marks['change'] if p1.version_key < p2.version_key], change_printer) mark_show('DOWNGRADED in', [(p1, p2) for (p1, p2) in marks['change'] if p1.version_key >= p2.version_key], change_printer) mark_show('UNINSTALLED from', marks['remove'], attrgetter('full_name')) print('\n'.join(messages)) # Confirm if necessary if self.pypmenv.options['interactive']: i, r, c = map(len, [marks['install'], marks['remove'], marks['change']]) # rdiff: no. of unrequested packages to be removed a = [p.name for p in marks['remove']] b = [ Requirement.parse(n).project_name.lower() for n in _requested_rmlist ] rdiff = len(set(a).difference(set(b))) trivial_action = any([ (i and not r and not c), # install, without rm/upgrade (not i and r and not rdiff and not c), # no extra uninstalls ]) if not trivial_action: if not askyesno('Continue?', default=True): return None del i, r, c # 1. download packages to_download = sorted(set.union(set(marks['install']), [p2 for p1, p2 in marks['change']]), key=lambda p: p.name) locations = Downloader(self.pypmenv).download_packages(to_download) # 2. uninstall packages for ipkg in marks['remove']: self._uninstall(ipkg) # 3. install new packages for pkg in marks['install']: self._install(pkg, locations[pkg]) # 4. upgrade/downgrade existing packages for ipkg, pkg in marks['change']: # XXX: need transaction here self._uninstall(ipkg) self._install(pkg, locations[pkg]) return marks