Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MANIFEST.in to workaround pip install failure when building a wheel #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ __pycache__/
*mkepub/tests/test.log
build/
dist/
venv/
.coverage
.cache
.eggs/
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include LICENSE
include README.rst
include include *.md
include setup.py
recursive-include mkepub *.py
graft mkpub/template
graft mkpub/tests
global-exclude *.py[cod]
19 changes: 16 additions & 3 deletions mkepub/mkepub.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@
# Module Imports
###############################################################################

# Python standard modules
import collections
import datetime
import imghdr
import itertools
import jinja2
import pathlib
import tempfile
import uuid
import zipfile

# third-party dependencies
import jinja2

# PEP 594 proposes deprecation of `imghdr` in Python 3.11
# https://peps.python.org/pep-0594/#imghdr
# a suggested replacement is `filetype`
#import imghdr
import filetype


###############################################################################

def mediatype(name):
# NB: some of this could be replaced by `filetype.guess_mime()`
ext = name.split('.')[-1].lower()
if ext not in ('png', 'jpg', 'jpeg', 'gif', 'svg'):
raise ValueError('Image format "{}" is not supported.'.format(ext))
Expand Down Expand Up @@ -110,7 +119,11 @@ def add_font(self, name, data):

def set_cover(self, data):
"""Set the cover image to the given data."""
self._cover = 'cover.' + imghdr.what(None, h=data)
# workaround for PEP 594 deprecation of `imghdr`
#extension = imghdr.what(None, h=data)
extension = filetype.guess_extension(data)

self._cover = 'cover.' + extension
self._add_file(pathlib.Path('covers') / self._cover, data)
self._write('cover.xhtml', 'EPUB/cover.xhtml', cover=self._cover)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='mkepub',
version='1.2',
version='1.3',
description='Simple minimalistic library for creating EPUB3 files',
long_description=readme,
url='https://github.com/anqxyr/mkepub/',
Expand All @@ -23,5 +23,5 @@
packages=['mkepub'],
package_data={'mkepub': ['templates/*']},
tests_require=['epubcheck', 'pytest', 'pytest-cov', 'python-coveralls'],
install_requires=['jinja2'],
install_requires=['filetype', 'jinja2'],
)