pypa / readme_renderer

Safely render long_description/README files in Warehouse
Apache License 2.0
158 stars 89 forks source link

Remove dependency on `python-future`? #128

Closed asottile closed 6 years ago

asottile commented 6 years ago

python-future is notorious for breaking modules which use try: / except: to import version specific modules: (a few examples from things I've encounted: 1 2)

let me know if you'd be interested in me making a PR along these lines -- it seems future is only being used for html.escape right now:

diff --git a/readme_renderer/txt.py b/readme_renderer/txt.py
index 0c0c533..3218922 100644
--- a/readme_renderer/txt.py
+++ b/readme_renderer/txt.py
@@ -13,10 +13,18 @@
 # limitations under the License.
 from __future__ import absolute_import, division, print_function

-from html import escape as html_escape
+import sys

 from .clean import clean

+if sys.version_info >= (3,):
+    from html import escape as html_escape
+else:
+    from cgi import escape
+
+    def html_escape(s):
+        return escape(s, quote=True).replace("'", ''')
+

 def render(raw, **kwargs):
     rendered = html_escape(raw).replace("\n", "<br>")
diff --git a/setup.py b/setup.py
index 5f2b64a..16fa18c 100644
--- a/setup.py
+++ b/setup.py
@@ -63,7 +63,6 @@ setuptools.setup(
         "bleach>=2.1.0",
         "cmarkgfm>=0.2.0",
         "docutils>=0.13.1",
-        "future",
         "Pygments",
         "six",
     ],
theacodes commented 6 years ago

Would definitely welcome a PR.

asottile commented 6 years ago

:tada: #134