pyg.parser.parser.init_parser

Here are the examples of the python api pyg.parser.parser.init_parser taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: pyg Source File: inst.py
    @staticmethod
    def from_req_file(filepath):
        path = os.path.abspath(filepath)
        not_installed = set()
        parser = init_parser()
        with open(path) as f:
            logger.info('{0}:', path)
            for line in f:
                line = line.strip()
                if line.startswith('#'):
                    logger.debug('debug: Comment found: {0}', line)
                    continue
                try:
                    logger.indent = 8
                    logger.info('Installing: {0}', line)
                    logger.indent = 16
                    parser.dispatch(argv=['install'] + line.split())
                except AlreadyInstalled:
                    continue
                except InstallationError:
                    not_installed.add(line)
                except SystemExit as e:
                    if e.code != 0:
                        logger.warn('W: {0} tried to raise SystemExit: skipping installation')
                    else:
                        logger.info('{0} tried to raise SystemExit, but the exit code was 0')
        if not_installed:
            logger.warn('These packages have not been installed:')
            logger.indent = 8
            for req in not_installed:
                logger.warn(req)
            logger.indent = 0
            raise InstallationError()

Example 2

Project: pyg Source File: shell.py
Function: init
    def __init__(self, *args, **kwargs):
        self.startdir = os.getcwd()
        self.prompt = 'pyg:{0}$ '.format(self.startdir)
        self.parser = init_parser(__import__('pyg').__version__)
        super(PygShell, self).__init__(*args, **kwargs)

Example 3

Project: pyg Source File: __init__.py
def main(argv=None):
    import sys
    import urllib2

    try:
        ## If Python fails to import pyg we just add this directory to
        ## sys.path so we don't have to worry whether Pyg is installed or not.
        __import__('pyg')
    except ImportError:
        sys.path.insert(0, '..')
    from pyg.parser.parser import init_parser, load_options
    from pyg.core import PygError, InstallationError, AlreadyInstalled, args_manager
    from pyg.log import logger

    try:
        # Output Pyg version when `-v, --version` is specified
        if len(sys.argv) == 2 and sys.argv[-1] in ('-v', '--version'):
            logger.info(__version__)
            sys.exit(0)
        parser = init_parser(__version__)
        argv = argv or sys.argv[1:]
        # we have to remove -d, --debug and --verbose to make
        # _suggest_cmd work
        _clean_argv(argv)
        _suggest_cmd(argv)
        args = parser.parse_args(argv)
        load_options()
        parser.dispatch(argv=argv)
    except (PygError, InstallationError, ValueError) as e:
        sys.exit(1)
    except AlreadyInstalled:
        sys.exit(0)
    except urllib2.HTTPError as e:
        logger.exit('HTTPError: {0}'.format(e.msg))
    except urllib2.URLError as e:
        logger.exit('urllib error: {0}'.format(e.reason if hasattr(e, 'reason') else e.msg))
    except KeyboardInterrupt:
        logger.exit('Process interrupted...')
    except Exception as e:
        if logger.level == logger.DEBUG:
            raise
        logger.exit('Unknown error occurred: {0}'.format(e))

    sys.exit(0)