Example #1
0
    def run(self, filename, style_language, encoding, **options):
        if style_language == 'bibtex':
            from pybtex import bibtex as engine
        elif style_language == 'python':
            import pybtex as engine
        else:
            self.opt_parser.error('unknown style language %s' % style_language)

        not_supported_by_bibtex = {
            'output_backend': 'output backends',
            'label_style': 'label styles',
            'name_style': 'name styles',
            'sorting_style': 'sorting styles',
            'abbreviate_names': 'abbreviated names',
        }
        if style_language != 'python':
            for option, what_is_not_supported in not_supported_by_bibtex.iteritems(
            ):
                if options[option]:
                    self.opt_parser.error(
                        '%s are only supported by the Pythonic style engine (-l python)'
                        % what_is_not_supported)

        for encoding_option in 'bib_encoding', 'bst_encoding', 'output_encoding':
            if not options[encoding_option]:
                options[encoding_option] = encoding

        ext = path.splitext(filename)[1]
        if ext != '.aux':
            filename = path.extsep.join([filename, 'aux'])
        engine.make_bibliography(filename, **options)
Example #2
0
    def run(self, filename, style_language, encoding, **options):
        if style_language == 'bibtex':
            from pybtex import bibtex as engine
        elif style_language == 'python':
            import pybtex as engine
        else:
            self.opt_parser.error('unknown style language %s' % style_language)

        not_supported_by_bibtex = {
            'output_backend': 'output backends',
            'label_style': 'label styles',
            'name_style': 'name styles',
            'sorting_style': 'sorting styles',
            'abbreviate_names': 'abbreviated names',
        }
        if style_language != 'python':
            for option, what_is_not_supported in not_supported_by_bibtex.iteritems():
                if options[option]:
                    self.opt_parser.error(
                        '%s are only supported by the Pythonic style engine (-l python)' % what_is_not_supported
                    )

        for encoding_option in 'bib_encoding', 'bst_encoding', 'output_encoding':
            if not options[encoding_option]:
                options[encoding_option] = encoding

        ext = path.splitext(filename)[1]
        if ext != '.aux':
            filename = path.extsep.join([filename, 'aux'])
        engine.make_bibliography(filename, **options)
Example #3
0
def check_make_bibliography(bib_name, bst_name):
    with cd_tempdir() as tempdir:
        copy_files(bib_name, bst_name)
        write_aux('test.aux', bib_name, bst_name)
        with errors.capture() as stderr:  # FIXME check error messages
            bibtex.make_bibliography('test.aux')
        with io.open_unicode('test.bbl', 'r') as result_file:
            result = result_file.read()
        correct_result_name = '{0}_{1}.bbl'.format(bib_name, bst_name)
        correct_result = pkgutil.get_data('pybtex.tests.data', correct_result_name).decode(io.get_default_encoding())
        assert result == correct_result, diff(correct_result, result)
Example #4
0
    def run(self, options, args):
        from pybtex.plugin import find_plugin

        filename = args[0]
        ext = path.splitext(filename)[1]
        if ext != '.aux':
            filename = path.extsep.join([filename, 'aux'])

        not_supported_by_bibtex = {
            'output_backend': 'output backends',
            'label_style': 'label styles',
            'name_style': 'name styles',
            'abbreviate_names': 'abbreviated names',
        }
        if options.style_language != 'python':
            for option, what_is_not_supported in not_supported_by_bibtex.items():
                if getattr(options, option):
                    self.opt_parser.error(
                        '%s are only supported by the Pythonic style engine (-l python)' % what_is_not_supported
                    )


        kwargs = {}
        if options.label_style:
            kwargs['label_style'] = find_plugin('pybtex.style.labels', options.label_style)
        if options.name_style:
            kwargs['name_style'] = find_plugin('pybtex.style.names', options.name_style)
        if options.output_backend:
            kwargs['output_backend'] = find_plugin('pybtex.backends', options.output_backend)
        if options.bib_format:
            kwargs['bib_format'] = find_plugin('pybtex.database.input', options.bib_format)
        kwargs['abbreviate_names'] = bool(options.abbreviate_names)
        kwargs['min_crossrefs'] = options.min_crossrefs
        for option in ('bib_encoding', 'output_encoding', 'bst_encoding'):
            value = getattr(options, option) or options.encoding
            if value:
                kwargs[option] = value

        if options.style_language == 'bibtex':
            from pybtex import bibtex as engine
        elif options.style_language == 'python':
            import pybtex as engine
        else:
            self.opt_parser.error('unknown style language %s' % options.style_language)

        engine.make_bibliography(filename, **kwargs)
Example #5
0
    def run(self, options, args):
        from pybtex.plugin import find_plugin

        filename = args[0]
        ext = path.splitext(filename)[1]
        if ext != '.aux':
            filename = path.extsep.join([filename, 'aux'])

        not_supported_by_bibtex = {
            'output_backend': 'output backends',
            'label_style': 'label styles',
            'name_style': 'name styles',
            'sorting_style': 'sorting styles',
            'abbreviate_names': 'abbreviated names',
        }
        if options.style_language != 'python':
            for option, what_is_not_supported in not_supported_by_bibtex.iteritems():
                if getattr(options, option):
                    self.opt_parser.error(
                        '%s are only supported by the Pythonic style engine (-l python)' % what_is_not_supported
                    )

        if options.style_language == 'bibtex':
            from pybtex import bibtex as engine
        elif options.style_language == 'python':
            import pybtex as engine
        else:
            self.opt_parser.error('unknown style language %s' % options.style_language)

        for encoding_option in 'bib_encoding', 'bst_encoding', 'output_encoding':
            if not getattr(options, encoding_option):
                setattr(options, encoding_option, options.encoding)

        kwargs = {}
        uninteresting_options = 'verbose', 'style_language'
        kwargs = dict(
            (key, value) for (key, value) in options.__dict__.iteritems()
            if key not in uninteresting_options
        )
        engine.make_bibliography(filename, **kwargs)