Skip to content

Commit 960b265

Browse files
authored
Make HTML transformation dependencies optional (#190)
* Make HTML transformation dependencies optional pip install emails - lightweight, only message building and sending pip install emails[html] - full install with HTML transformer (lxml, cssutils, premailer, chardet, requests) Move heavy dependencies (lxml, cssutils, premailer, chardet, requests) from install_requires to extras_require['html']. Make requests import lazy in utils.py so that `import emails` works without it. * Document optional html dependencies in install docs and README
1 parent 7d40007 commit 960b265

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ and more:
2525
* DKIM signature
2626
* Render body from template
2727
* Flask extension and Django integration
28-
* Message body transformation methods
28+
* HTML transformation with CSS inlining (``pip install emails[html]``)
2929
* Load message from url or from file
3030

3131
|

docs/install.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ Install from pypi:
77
.. code-block:: bash
88
99
$ pip install emails
10+
11+
This installs the lightweight core for building and sending email messages.
12+
13+
To use HTML transformation features (CSS inlining, image embedding, loading from URL/file):
14+
15+
.. code-block:: bash
16+
17+
$ pip install emails[html]

emails/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
from email.header import Header, decode_header as decode_header_
1616
from email.utils import parseaddr, formatdate, escapesre, specialsre
1717

18-
import requests
19-
2018
from . import USER_AGENT
2119
from .exc import HTTPLoaderError
2220

@@ -270,6 +268,7 @@ def __init__(self, _subtype='mixed', boundary=None, _subparts=None, encoding=Non
270268

271269

272270
def fetch_url(url, valid_http_codes=(200, ), requests_args=None):
271+
import requests
273272
args = {}
274273
args.update(DEFAULT_REQUESTS_PARAMS)
275274
args.update(requests_args or {})

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def find_version(*file_paths):
127127
'emails.packages.dkim'
128128
],
129129
scripts=['scripts/make_rfc822.py'],
130-
install_requires=['cssutils', 'lxml', 'chardet', 'python-dateutil', 'requests', 'premailer'],
130+
install_requires=['python-dateutil'],
131+
extras_require={
132+
'html': ['cssutils', 'lxml', 'chardet', 'requests', 'premailer'],
133+
},
131134
zip_safe=False,
132135
classifiers=(
133136
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)