Imports rearrangements, readme reformat, basic stuff.
Smoke tests are 100/100.
This commit is contained in:
+5
-5
@@ -125,17 +125,17 @@ managers), i.e:
|
|||||||
(venv) $ cd ebook-converter
|
(venv) $ cd ebook-converter
|
||||||
(venv) $ pip install --no-binary lxml .
|
(venv) $ pip install --no-binary lxml .
|
||||||
|
|
||||||
Note: the ``--no-binary lxml`` flag is required to ensure ``lxml`` is compiled
|
|
||||||
against the same system ``libxml2`` as ``html5-parser``. Without it, pip may
|
|
||||||
install a pre-built ``lxml`` wheel bundling a different ``libxml2`` version,
|
|
||||||
which causes a ``RuntimeError``.
|
|
||||||
|
|
||||||
Simple as that. And from now on, you can issue converter:
|
Simple as that. And from now on, you can issue converter:
|
||||||
|
|
||||||
.. code:: shell-session
|
.. code:: shell-session
|
||||||
|
|
||||||
(venv) $ ebook-converter book.docx book.lrf
|
(venv) $ ebook-converter book.docx book.lrf
|
||||||
|
|
||||||
|
.. note:: The ``--no-binary lxml`` flag is required to ensure ``lxml`` is
|
||||||
|
compiled against the same system ``libxml2`` as ``html5-parser``. Without
|
||||||
|
it, pip may install a pre-built ``lxml`` wheel bundling a different
|
||||||
|
``libxml2`` version, which causes a ``RuntimeError``.
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import importlib.resources
|
||||||
import mimetypes
|
import mimetypes
|
||||||
from importlib.resources import files
|
|
||||||
|
|
||||||
|
|
||||||
mimetypes.init([str(files('ebook_converter').joinpath('data/mime.types'))])
|
mimetypes.init([str(importlib.resources.
|
||||||
|
files('ebook_converter') / 'data/mime.types')])
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
Command line interface to conversion sub-system
|
Command line interface to conversion sub-system
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
import importlib.resources
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import numbers
|
import numbers
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
from importlib.resources import files
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -351,7 +351,8 @@ def read_sr_patterns(path, log=None):
|
|||||||
|
|
||||||
def main(args=sys.argv):
|
def main(args=sys.argv):
|
||||||
log = logging.default_log
|
log = logging.default_log
|
||||||
mimetypes.init([str(files('ebook_converter').joinpath('data/mime.types'))])
|
mimetypes.init([str(importlib.resources.files('ebook_converter') /
|
||||||
|
'data/mime.types')])
|
||||||
parser, plumber = create_option_parser(args, log)
|
parser, plumber = create_option_parser(args, log)
|
||||||
opts, leftover_args = parser.parse_args(args)
|
opts, leftover_args = parser.parse_args(args)
|
||||||
if len(leftover_args) > 3:
|
if len(leftover_args) > 3:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
Convert .fb2 files to .lrf
|
Convert .fb2 files to .lrf
|
||||||
"""
|
"""
|
||||||
|
import importlib.resources
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
from importlib.resources import files
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@@ -85,8 +85,8 @@ class FB2Input(InputFormatPlugin):
|
|||||||
css = re.sub(r'name\s*=\s*', 'class=', css)
|
css = re.sub(r'name\s*=\s*', 'class=', css)
|
||||||
self.extract_embedded_content(doc)
|
self.extract_embedded_content(doc)
|
||||||
log.debug('Converting XML to HTML...')
|
log.debug('Converting XML to HTML...')
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/fb2.xsl'))) as f:
|
'data/fb2.xsl') as f:
|
||||||
ss = f.read()
|
ss = f.read()
|
||||||
ss = ss.replace("__FB_NS__", fb_ns)
|
ss = ss.replace("__FB_NS__", fb_ns)
|
||||||
if options.no_inline_fb2_toc:
|
if options.no_inline_fb2_toc:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import importlib.resources
|
||||||
import os
|
import os
|
||||||
from importlib.resources import files
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
@@ -92,27 +92,24 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
with open(opts.template_html_index, 'rb') as f:
|
with open(opts.template_html_index, 'rb') as f:
|
||||||
template_html_index_data = f.read()
|
template_html_index_data = f.read()
|
||||||
else:
|
else:
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/html_export_default_index.tmpl'))
|
'data/html_export_default_index.tmpl') as fobj:
|
||||||
) as fobj:
|
|
||||||
template_html_index_data = fobj.read().decode()
|
template_html_index_data = fobj.read().decode()
|
||||||
|
|
||||||
if opts.template_html is not None:
|
if opts.template_html is not None:
|
||||||
with open(opts.template_html, 'rb') as f:
|
with open(opts.template_html, 'rb') as f:
|
||||||
template_html_data = f.read()
|
template_html_data = f.read()
|
||||||
else:
|
else:
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/html_export_default.tmpl'))
|
'data/html_export_default.tmpl') as fobj:
|
||||||
) as fobj:
|
|
||||||
template_html_data = fobj.read().decode()
|
template_html_data = fobj.read().decode()
|
||||||
|
|
||||||
if opts.template_css is not None:
|
if opts.template_css is not None:
|
||||||
with open(opts.template_css, 'rb') as f:
|
with open(opts.template_css, 'rb') as f:
|
||||||
template_css_data = f.read()
|
template_css_data = f.read()
|
||||||
else:
|
else:
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/html_export_default.css'))
|
'data/html_export_default.css') as fobj:
|
||||||
) as fobj:
|
|
||||||
template_css_data = fobj.read().decode()
|
template_css_data = fobj.read().decode()
|
||||||
|
|
||||||
template_html_index_data = template_html_index_data.decode('utf-8')
|
template_html_index_data = template_html_index_data.decode('utf-8')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import importlib.resources
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from importlib.resources import files
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@@ -52,8 +52,8 @@ class LRFInput(InputFormatPlugin):
|
|||||||
|
|
||||||
self.log.info('Converting XML to HTML...')
|
self.log.info('Converting XML to HTML...')
|
||||||
|
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/lrf.xsl'))) as fobj:
|
'data/lrf.xsl') as fobj:
|
||||||
# TODO(gryf): change this nonsense to etree.parse() instead.
|
# TODO(gryf): change this nonsense to etree.parse() instead.
|
||||||
styledoc = etree.fromstring(fobj.read())
|
styledoc = etree.fromstring(fobj.read())
|
||||||
media_type = MediaType()
|
media_type = MediaType()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import importlib.resources
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
from importlib.resources import files
|
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
@@ -288,8 +288,8 @@ class RTFInput(InputFormatPlugin):
|
|||||||
|
|
||||||
self.log.info('Converting XML to HTML...')
|
self.log.info('Converting XML to HTML...')
|
||||||
inline_class = InlineClass(self.log)
|
inline_class = InlineClass(self.log)
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
.joinpath('data/rtf.xsl'))) as fobj:
|
'data/rtf.xsl') as fobj:
|
||||||
styledoc = etree.fromstring(fobj.read())
|
styledoc = etree.fromstring(fobj.read())
|
||||||
extensions = {('calibre', 'inline-class'): inline_class}
|
extensions = {('calibre', 'inline-class'): inline_class}
|
||||||
transform = etree.XSLT(styledoc, extensions=extensions)
|
transform = etree.XSLT(styledoc, extensions=extensions)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
|
import importlib.resources
|
||||||
import operator
|
import operator
|
||||||
from importlib.resources import files
|
|
||||||
import re
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
@@ -719,8 +719,8 @@ def commit_nav_toc(container, toc, lang=None, landmarks=None,
|
|||||||
if previous_nav is not None:
|
if previous_nav is not None:
|
||||||
root = previous_nav[1]
|
root = previous_nav[1]
|
||||||
else:
|
else:
|
||||||
with open(str(files('ebook_converter')
|
with open(importlib.resources.file('ebook_converter') /
|
||||||
.joinpath('data/new_nav.html'))) as fobj:
|
'data/new_nav.html') as fobj:
|
||||||
root = container.parse_xhtml(fobj.read())
|
root = container.parse_xhtml(fobj.read())
|
||||||
container.replace(tocname, root)
|
container.replace(tocname, root)
|
||||||
else:
|
else:
|
||||||
@@ -873,7 +873,8 @@ def toc_to_html(toc, container, toc_name, title, lang=None):
|
|||||||
|
|
||||||
E = ElementMaker(namespace=const.XHTML_NS, nsmap={None: const.XHTML_NS})
|
E = ElementMaker(namespace=const.XHTML_NS, nsmap={None: const.XHTML_NS})
|
||||||
# TODO(gryf): revisit lack of css.
|
# TODO(gryf): revisit lack of css.
|
||||||
css_f = str(files('ebook_converter').joinpath('data/inline_toc_styles.css'))
|
css_f = str(importlib.resources.files('ebook_converter') /
|
||||||
|
'data/inline_toc_styles.css')
|
||||||
html = E.html(E.head(E.title(title),
|
html = E.html(E.head(E.title(title),
|
||||||
E.style(css_f, type='text/css')),
|
E.style(css_f, type='text/css')),
|
||||||
E.body(E.h2(title), E.ul(),
|
E.body(E.h2(title), E.ul(),
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
"""
|
"""
|
||||||
CSS property propagation class.
|
CSS property propagation class.
|
||||||
"""
|
"""
|
||||||
import os, re, logging, copy, unicodedata, numbers
|
import copy
|
||||||
from importlib.resources import files
|
import importlib.resources
|
||||||
|
import logging
|
||||||
|
import numbers
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from weakref import WeakKeyDictionary
|
from weakref import WeakKeyDictionary
|
||||||
from xml.dom import SyntaxErr as CSSSyntaxError
|
from xml.dom import SyntaxErr as CSSSyntaxError
|
||||||
@@ -28,7 +34,8 @@ _html_css_stylesheet = None
|
|||||||
def html_css_stylesheet():
|
def html_css_stylesheet():
|
||||||
global _html_css_stylesheet
|
global _html_css_stylesheet
|
||||||
if _html_css_stylesheet is None:
|
if _html_css_stylesheet is None:
|
||||||
with open(str(files('ebook_converter').joinpath('data/html.css')), 'rb') as f:
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
|
'data/html.css', 'rb') as f:
|
||||||
html_css = f.read().decode('utf-8')
|
html_css = f.read().decode('utf-8')
|
||||||
_html_css_stylesheet = parseString(html_css, validate=False)
|
_html_css_stylesheet = parseString(html_css, validate=False)
|
||||||
return _html_css_stylesheet
|
return _html_css_stylesheet
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Read content from txt file.
|
Read content from txt file.
|
||||||
"""
|
"""
|
||||||
import os, re
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||||
|
|
||||||
@@ -101,7 +102,6 @@ DEFAULT_MD_EXTENSIONS = ('footnotes', 'tables', 'toc')
|
|||||||
|
|
||||||
|
|
||||||
def create_markdown_object(extensions):
|
def create_markdown_object(extensions):
|
||||||
# Need to load markdown extensions without relying on pkg_resources
|
|
||||||
import importlib
|
import importlib
|
||||||
from ebook_converter.ebooks.markdown import Markdown
|
from ebook_converter.ebooks.markdown import Markdown
|
||||||
from markdown import Extension
|
from markdown import Extension
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
import importlib.resources
|
||||||
import json
|
import json
|
||||||
from importlib.resources import files
|
|
||||||
|
|
||||||
from ebook_converter.utils.localization import canonicalize_lang
|
from ebook_converter.utils.localization import canonicalize_lang
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ ccodes, ccodemap, country_names = None, None, None
|
|||||||
def get_codes():
|
def get_codes():
|
||||||
global ccodes, ccodemap, country_names
|
global ccodes, ccodemap, country_names
|
||||||
if ccodes is None:
|
if ccodes is None:
|
||||||
src = str(files('ebook_converter').joinpath('data/iso_3166-1.json'))
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
with open(src, 'rb') as f:
|
'data/iso_3166-1.json', 'rb') as f:
|
||||||
db = json.load(f)
|
db = json.load(f)
|
||||||
codes = set()
|
codes = set()
|
||||||
three_map = {}
|
three_map = {}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import collections
|
|||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
|
import importlib.resources
|
||||||
import json
|
import json
|
||||||
import numbers
|
import numbers
|
||||||
import os
|
import os
|
||||||
@@ -10,8 +11,6 @@ import pickle
|
|||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from importlib.resources import files as _resource_files
|
|
||||||
|
|
||||||
from ebook_converter.constants_old import config_dir
|
from ebook_converter.constants_old import config_dir
|
||||||
from ebook_converter.constants_old import filesystem_encoding
|
from ebook_converter.constants_old import filesystem_encoding
|
||||||
from ebook_converter.constants_old import preferred_encoding
|
from ebook_converter.constants_old import preferred_encoding
|
||||||
@@ -591,7 +590,8 @@ def exec_tweaks(path):
|
|||||||
|
|
||||||
|
|
||||||
def default_tweaks_raw():
|
def default_tweaks_raw():
|
||||||
return str(_resource_files('ebook_converter').joinpath('data/default_tweaks.py'))
|
return str(importlib.resources.files('ebook_converter') /
|
||||||
|
'data/default_tweaks.py')
|
||||||
|
|
||||||
|
|
||||||
def read_tweaks():
|
def read_tweaks():
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import importlib.resources
|
||||||
import json
|
import json
|
||||||
from importlib.resources import files
|
|
||||||
|
|
||||||
|
|
||||||
def get_lang():
|
def get_lang():
|
||||||
@@ -39,9 +39,8 @@ def _load_iso639():
|
|||||||
# excerpt form Calibre transform code which is executed during Calibre
|
# excerpt form Calibre transform code which is executed during Calibre
|
||||||
# build).
|
# build).
|
||||||
if _iso639 is None:
|
if _iso639 is None:
|
||||||
src = str(files('ebook_converter').joinpath('data/iso_639-3.json'))
|
with open(importlib.resources.files('ebook_converter') /
|
||||||
|
'data/iso_639-3.json', 'rb') as f:
|
||||||
with open(src, 'rb') as f:
|
|
||||||
root = json.load(f)
|
root = json.load(f)
|
||||||
|
|
||||||
entries = root['639-3']
|
entries = root['639-3']
|
||||||
|
|||||||
Reference in New Issue
Block a user