From 076d4ad47e3b1a8a3433478ecf4971c4dadb4030 Mon Sep 17 00:00:00 2001 From: Andriy Kornatskyy Date: Wed, 4 Nov 2020 20:40:10 +0200 Subject: [PATCH] Dropped python 3.5 and below. --- .travis.yml | 4 +-- README.md | 7 ++--- requirements/dev-py2.txt | 37 ---------------------- requirements/{dev-py3.txt => dev.txt} | 4 +-- setup.py | 12 ++------ src/wheezy/html/boost.c | 44 --------------------------- src/wheezy/html/comp.py | 26 ---------------- src/wheezy/html/ext/template.py | 3 +- src/wheezy/html/utils.py | 10 +++--- tox.ini | 12 ++++---- 10 files changed, 20 insertions(+), 139 deletions(-) delete mode 100644 requirements/dev-py2.txt rename requirements/{dev-py3.txt => dev.txt} (88%) delete mode 100644 src/wheezy/html/comp.py diff --git a/.travis.yml b/.travis.yml index aba5d2f..501e4ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ language: python matrix: include: - - python: 2.7 - env: TOXENV=py27 + - python: 3.6 + env: TOXENV=py36 - python: 3.7 env: TOXENV=py37 - python: 3.8 diff --git a/README.md b/README.md index d19d378..9eaa8fc 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Resources: ## Install [wheezy.html](https://pypi.org/project/wheezy.html) requires -[python](http://www.python.org) version 2.4 to 2.7 or 3.2+. It is -independent of operating system. You can install it from -[pypi](https://pypi.org/project/wheezy.html) site: +[python](http://www.python.org) version 3.6+. It is independent of operating +system. You can install it from [pypi](https://pypi.org/project/wheezy.html) +site: ```sh pip install -U wheezy.html @@ -39,7 +39,6 @@ If you would like take a benefit of template preprocessing for Mako, Jinja2, Tenjin or Wheezy.Template engines specify extra requirements: ```sh -pip install wheezy.html[jinja2] pip install wheezy.html[wheezy.template] ``` diff --git a/requirements/dev-py2.txt b/requirements/dev-py2.txt deleted file mode 100644 index 895fa10..0000000 --- a/requirements/dev-py2.txt +++ /dev/null @@ -1,37 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile --output-file=requirements/dev-py2.txt requirements/dev.in -# -atomicwrites==1.4.0 # via pytest -attrs==20.3.0 # via pytest -backports.functools-lru-cache==1.6.1 # via wcwidth -click==7.1.2 # via pip-tools -colorama==0.4.4 # via pytest -configparser==4.0.2 # via importlib-metadata -contextlib2==0.6.0.post1 # via importlib-metadata -coverage==5.3 # via pytest-cov -funcsigs==1.0.2 # via pytest -importlib-metadata==2.0.0 # via pluggy, pytest -jinja2==2.11.2 # via -r requirements/dev.in -mako==1.1.3 # via -r requirements/dev.in -markupsafe==1.1.1 # via jinja2, mako -more-itertools==5.0.0 # via pytest -packaging==20.4 # via pytest -pathlib2==2.3.5 # via importlib-metadata, pytest -pip-tools==5.3.1 # via -r requirements/dev.in -pluggy==0.13.1 # via pytest -py==1.9.0 # via pytest -pyparsing==2.4.7 # via packaging -pytest-cov==2.10.1 # via -r requirements/dev.in -pytest==4.6.11 # via -r requirements/dev.in, pytest-cov -scandir==1.10.0 # via pathlib2 -six==1.15.0 # via more-itertools, packaging, pathlib2, pip-tools, pytest -tenjin==1.1.1 # via -r requirements/dev.in -wcwidth==0.2.5 # via pytest -wheezy.template==2.0.0 # via -r requirements/dev.in -zipp==1.2.0 # via importlib-metadata - -# The following packages are considered to be unsafe in a requirements file: -# pip diff --git a/requirements/dev-py3.txt b/requirements/dev.txt similarity index 88% rename from requirements/dev-py3.txt rename to requirements/dev.txt index 3770a06..64271dc 100644 --- a/requirements/dev-py3.txt +++ b/requirements/dev.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile # To update, run: # -# pip-compile --output-file=requirements/dev-py3.txt requirements/dev.in +# pip-compile --output-file=requirements/dev.txt requirements/dev.in # atomicwrites==1.4.0 # via pytest attrs==20.3.0 # via pytest @@ -23,7 +23,7 @@ pytest==6.1.2 # via -r requirements/dev.in, pytest-cov six==1.15.0 # via packaging, pip-tools tenjin==1.1.1 # via -r requirements/dev.in toml==0.10.2 # via pytest -wheezy.template==3.0.0 # via -r requirements/dev.in +wheezy.template==3.0.1 # via -r requirements/dev.in # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/setup.py b/setup.py index 3a12f19..61334c7 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ os.path.join(p, "ext", "__init__.py"), ], nthreads=2, + compiler_directives={"language_level": 3}, quiet=True, ) except ImportError: @@ -72,6 +73,7 @@ def warn(self): setup( name="wheezy.html", version=VERSION, + python_requires=">=3.6", description="A lightweight html rendering library", long_description=README, long_description_content_type="text/markdown", @@ -86,16 +88,6 @@ def warn(self): "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.4", - "Programming Language :: Python :: 2.5", - "Programming Language :: Python :: 2.6", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.2", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", diff --git a/src/wheezy/html/boost.c b/src/wheezy/html/boost.c index fa59b98..ec9e90a 100644 --- a/src/wheezy/html/boost.c +++ b/src/wheezy/html/boost.c @@ -1,14 +1,6 @@ #include -#if PY_VERSION_HEX < 0x02050000 -typedef int Py_ssize_t; -#endif - -#if PY_VERSION_HEX < 0x02060000 -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#endif - static PyObject* escape_html_unicode(PyUnicodeObject *s) { @@ -86,11 +78,7 @@ escape_html_unicode(PyUnicodeObject *s) static PyObject* escape_html_string(PyObject *s) { -#if PY_MAJOR_VERSION < 3 - const Py_ssize_t s_size = PyString_GET_SIZE(s); -#else const Py_ssize_t s_size = PyBytes_GET_SIZE(s); -#endif if (s_size == 0) { Py_INCREF(s); @@ -98,11 +86,7 @@ escape_html_string(PyObject *s) } Py_ssize_t count = 0; -#if PY_MAJOR_VERSION < 3 - char *start = PyString_AS_STRING(s); -#else char *start = PyBytes_AS_STRING(s); -#endif const char *end = start + s_size; char *p = start; while(p < end) @@ -127,22 +111,14 @@ escape_html_string(PyObject *s) return (PyObject*)s; } -#if PY_MAJOR_VERSION < 3 - PyObject *result = PyString_FromStringAndSize(NULL, s_size + count); -#else PyObject *result = PyBytes_FromStringAndSize(NULL, s_size + count); -#endif if (! result) { return NULL; } p = start; -#if PY_MAJOR_VERSION < 3 - char *r = PyString_AS_STRING(result); -#else char *r = PyBytes_AS_STRING(result); -#endif while(p < end) { char ch = *p++; @@ -186,21 +162,13 @@ escape_html(PyObject *self, PyObject *args) return escape_html_unicode((PyUnicodeObject*)s); } -#if PY_MAJOR_VERSION < 3 - if (PyString_CheckExact(s)) -#else if (PyBytes_CheckExact(s)) -#endif { return escape_html_string(s); } if (s == Py_None) { -#if PY_MAJOR_VERSION < 3 - return PyString_FromStringAndSize(NULL, 0); -#else return PyUnicode_FromStringAndSize(NULL, 0); -#endif } PyErr_Format(PyExc_TypeError, @@ -217,16 +185,6 @@ static PyMethodDef module_methods[] = { }; -#if PY_MAJOR_VERSION < 3 - -PyMODINIT_FUNC -initboost(void) -{ - Py_InitModule("wheezy.html.boost", module_methods); -} - -#else - static struct PyModuleDef module_definition = { PyModuleDef_HEAD_INIT, "wheezy.html.boost", @@ -240,5 +198,3 @@ PyInit_boost(void) { return PyModule_Create(&module_definition); } - -#endif diff --git a/src/wheezy/html/comp.py b/src/wheezy/html/comp.py deleted file mode 100644 index 6f2baad..0000000 --- a/src/wheezy/html/comp.py +++ /dev/null @@ -1,26 +0,0 @@ -""" ``comp`` module. -""" - -import sys - -PY3 = sys.version_info[0] >= 3 - - -if PY3: # pragma: nocover - str_type = str - xrange = range -else: # pragma: nocover - str_type = unicode # noqa: F821 - xrange = xrange - - -if PY3: # pragma: nocover - - def iteritems(d): - return d.items() - - -else: # pragma: nocover - - def iteritems(d): - return d.iteritems() # noqa: B301 diff --git a/src/wheezy/html/ext/template.py b/src/wheezy/html/ext/template.py index 60084ee..ec0052c 100644 --- a/src/wheezy/html/ext/template.py +++ b/src/wheezy/html/ext/template.py @@ -3,7 +3,6 @@ import re -from wheezy.html.comp import xrange from wheezy.html.ext.lexer import ( InlinePreprocessor, Preprocessor, @@ -133,7 +132,7 @@ class WidgetExtension(object): def whitespace_postprocessor(tokens): - for i in xrange(len(tokens)): + for i in range(len(tokens)): lineno, token, value = tokens[i] if token == "markup": value = whitespace_preprocessor(value) diff --git a/src/wheezy/html/utils.py b/src/wheezy/html/utils.py index 38af3b4..15a4300 100644 --- a/src/wheezy/html/utils.py +++ b/src/wheezy/html/utils.py @@ -3,8 +3,6 @@ from datetime import date, datetime -from wheezy.html.comp import str_type - def escape_html(s): """Escapes a string so it is valid within HTML. Converts `None` @@ -66,7 +64,7 @@ def my_formatter(value, format_spec): >>> format_value([]) () - If format provider is unknown apply str_type. + If format provider is unknown apply str. >>> str(format_value({})) '{}' @@ -87,12 +85,12 @@ def my_formatter(value, format_spec): if formatter_name in format_providers: format_provider = format_providers[formatter_name] else: - return str_type(value) + return str(value) return format_provider(value, format_spec) def str_format_provider(value, format_spec): - return str_type(value) + return str(value) min_date = date(1900, 1, 1) @@ -138,7 +136,7 @@ def datetime_format_provider(value, format_spec=None): format_providers = { - "str": lambda value, format_spec: html_escape(str_type(value)), + "str": lambda value, format_spec: html_escape(str(value)), "unicode": lambda value, format_spec: html_escape(value), "int": str_format_provider, "Decimal": str_format_provider, diff --git a/tox.ini b/tox.ini index 7c488da..d68196f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,15 @@ [tox] -envlist = py27,py37,py38,py39,pypy3,lint,docs +envlist = py36,py37,py38,py39,pypy3,lint,docs skipsdist = True [testenv] usedevelop = True deps = - py27: -r requirements/dev-py2.txt - py37: -r requirements/dev-py3.txt - py38: -r requirements/dev-py3.txt - py39: -r requirements/dev-py3.txt - pypy3: -r requirements/dev-py3.txt + py36: -r requirements/dev.txt + py37: -r requirements/dev.txt + py38: -r requirements/dev.txt + py39: -r requirements/dev.txt + pypy3: -r requirements/dev.txt commands = pytest -q -x --disable-pytest-warnings --doctest-modules \ --cov-report term-missing --cov wheezy.html