Exemplo n.º 1
0
    def do_install(self, subcmd, opts, *names):
        """${cmd_name}: Install/upgrade packages

        NAME can be one of the following:

          - Name of the package to install (eg: "django")
          - Setuptools-style requirement string (eg: "cherrypy<3")
          - Path to a local .pypm file
          - URL to a remote .pypm file

        Installing a package will automatically install its dependencies that
        are specified via setuptools' "install_requires".
        
        Packages are by default installed to PEP 370 style user directories
        (~/.local or %APPDATA%\Python) unless the -g or -E option is used.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            self._autosync()

            # Read requirement files
            if opts.requirements:
                names = list(names)
                for requirement in opts.requirements:
                    with open(requirement) as f:
                        for r in f:
                            r = r.strip()
                            if r and not r.startswith('#'):
                                names.append(r)
            elif not names:
                raise cmdln.CmdlnUserError(
                    'insufficient arguments; see `pypm help install`')

            # Ask the user if he wants to add user local bin directory to his
            # PATH. Do this only when `pyenv` is a user site environment; not
            # when it is, say, the global one (-g).
            # On Windows, try to expand the unexpanded %APPDATA%
            if isinstance(self.pypmenv.pyenv,
                          python.UserLocalPythonEnvironment):
                pep370_fix_path()

            if len(names) == 1:
                if '://' in names[0]:
                    return install_remote_file(self.pypmenv, names[0])
                elif names[0].endswith(BinaryPackage.EXTENSION) and P.exists(
                        names[0]):
                    return install_local_file(self.pypmenv, names[0])

            return install(self.pypmenv,
                           names,
                           nodeps=opts.nodeps,
                           skip_missing=not opts.no_ignore)
Exemplo n.º 2
0
    def do_uninstall(self, subcmd, opts, *names):
        """${cmd_name}: Uninstall packages

        Removing a package will automatically uninstall other packages that
        depend on the package to be uninstall.
        
        Packages are by default uninstalled from PEP 370 style user directories
        (~/.local or %APPDATA%\Python) unless the -E option is used (type 'pypm
        help virtualenv' for more information).
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            if not names:
                raise cmdln.CmdlnUserError(
                    'insufficient arguments; see `pypm help uninstall`')

            return uninstall(self.pypmenv, names, nodeps=opts.nodeps)
Exemplo n.º 3
0
def require_option(options, option_name, details=None):
    """
    >>> require_option('foo-bar')
    ...
    CmdlnUserError: required option, --foo-bar, is mising

    From http://twitter.com/ActiveState/status/19782350475
	'required options' - conforming to unix standard vs being creative with
	non-positional arguments. http://bit.ly/d2iiUL #python #optparse ^SR
    """
    option_var_name = option_name.replace('-', '_')
    if not hasattr(options, option_var_name):
        raise ValueError("require_option: undefined option '%s'" %
                         option_var_name)
    if getattr(options, option_var_name) is None:
        msg = 'required option "--{0}" is missing'.format(option_name)
        if details:
            msg = '%s (%s)' % (msg, details)
        raise cmdln.CmdlnUserError(msg)