Пример #1
0
    def run(self):
        """
        Run notebook as an application
        :param params: parameters to inject in the notebook
        :return:
        """
        if not self.args:
            self.parse_args()

        added_cells_func = False
        try:
            if self.args.with_generate_cellsfunc:
                self.add_cells_funcion(self.args.cells)
                added_cells_func = True

            if self.args.log_level:
                logging.getLogger().setLevel(
                    logging.getLevelName(self.args.log_level))
                logging.debug('Enabled {} logging level'.format(
                    self.args.log_level))

            if self.args.import_ipynb:
                check_isfile(self.args.import_ipynb)
                logging.info('Loading Jupyter notebook {}'.format(
                    self.args.import_ipynb))
                self.nb = nbf.read(self.args.import_ipynb, as_version=4)
                uid = self.args.import_ipynb
            else:
                uid = self.load_cells_params()

            logging.debug("Unique id: '{}'".format(uid))
            logging.info('Disable cache: {}'.format(self.args.disable_cache))
            logging.info('Ignore cache: {}'.format(self.args.ignore_cache))

            if self.args.export_pynb and not self.args.no_exec:
                fatal('--export-pynb requires --no-exec')

            if self.args.kernel:
                self.set_kernel(self.args.kernel)

            self.process(uid=uid,
                         add_footer=not self.args.disable_footer,
                         no_exec=self.args.no_exec,
                         disable_cache=self.args.disable_cache,
                         ignore_cache=self.args.ignore_cache)

            if self.args.export_html:
                self.export_html(self.args.export_html)

            if self.args.export_ipynb:
                self.export_ipynb(self.args.export_ipynb)

            if self.args.export_pynb:
                self.export_pynb(self.args.export_pynb)
        finally:
            if added_cells_func:
                self.remove_cells_funcion(self.args.cells)
Пример #2
0
    def run(self):
        """
        Run notebook as an application
        :param params: parameters to inject in the notebook
        :return:
        """

        if not self.args:
            self.parse_args()

        logging.info(self.long_name)

        if self.args.debug:
            logging.getLogger().setLevel(logging.DEBUG)
            logging.debug('Enabled DEBUG logging level')

        if self.args.import_ipynb:
            check_isfile(self.args.import_ipynb)
            logging.info('Loading Jupyter notebook {}'.format(
                self.args.import_ipynb))
            self.nb = nbf.read(self.args.import_ipynb, as_version=4)
            uid = self.args.import_ipynb
        else:
            uid = self.load_cells_params()

        logging.debug("Unique id: '{}'".format(uid))
        logging.info('Disable cache: {}'.format(self.args.disable_cache))
        logging.info('Ignore cache: {}'.format(self.args.ignore_cache))

        if self.args.export_pynb and not self.args.no_exec:
            fatal('--export-pynb requires --no-exec')

        self.process(uid=uid,
                     no_exec=self.args.no_exec,
                     disable_cache=self.args.disable_cache,
                     ignore_cache=self.args.ignore_cache)

        if self.args.export_html:
            self.export_html(self.args.export_html)

        if self.args.export_ipynb:
            self.export_ipynb(self.args.export_ipynb)

        if self.args.export_pynb:
            self.export_pynb(self.args.export_pynb)
Пример #3
0
    def set_cells(self, cells_location):
        """
        Set self.cells to function :cells in file pathname.py
        :param cells_location: cells location, format 'pathname.py:cells'
        :return:
        """

        if ':' in cells_location:
            pathname, func_name = cells_location.split(':')
        else:
            pathname = cells_location
            func_name = 'cells'

        check_isfile(pathname)

        try:
            self.cells = get_func(func_name, pathname)
        except SyntaxError as e:
            fatal(traceback.format_exc(limit=1))

        return pathname, func_name
Пример #4
0
    def set_cells(self, cells_location):
        """
        Set self.cells to function :cells in file pathname.py
        :param cells_location: cells location, format 'pathname.py:cells'
        :return:
        """

        if ':' in cells_location:
            pathname, func_name = cells_location.split(':')
        else:
            pathname = cells_location
            func_name = 'cells'

        check_isfile(pathname)

        try:
            self.cells = get_func(func_name, pathname)
        except Exception as e:
            logging.error(traceback.format_exc())
            fatal("Function '{}' not found in '{}': {}".format(
                func_name, pathname, e))

        return pathname, func_name