From 8e360aed732fb0c902e78885c4be89e4048a2d2d Mon Sep 17 00:00:00 2001 From: Val Neekman Date: Sun, 25 Mar 2018 09:39:21 -0400 Subject: support for text-unidecode --- .travis.yml | 10 +++++----- CHANGELOG.md | 8 ++++++++ README.rst | 37 ++++++++++++++++--------------------- alt_requirements.txt | 1 - pep8.sh | 11 ----------- pycodestyle.sh | 11 +++++++++++ requirements_alt.txt | 1 + setup.py | 2 +- slugify/__init__.py | 2 +- slugify/slugify.py | 4 ++-- test.py | 1 + 11 files changed, 46 insertions(+), 42 deletions(-) delete mode 100644 alt_requirements.txt delete mode 100755 pep8.sh create mode 100755 pycodestyle.sh create mode 100644 requirements_alt.txt diff --git a/.travis.yml b/.travis.yml index 737fa21..4bf2dd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,19 +11,19 @@ python: - pypy env: - - WITH_TEXTUNIDECODE=yes - - WITH_UNIDECODE=yes # this is redundant but otherwise travis will only trigger one build type + - SLUGIFY_USES_TEXT_UNIDECODE=yes + - SLUGIFY_USES_UNIDECODE=yes # dummy: tell travis to run more than one build types install: - pip install pip -U - - if [[ -z "${WITH_TEXTUNIDECODE}" ]]; then pip install -q -r requirements.txt; else pip install -q -r alt_requirements.txt; fi + - if [[ -z "${SLUGIFY_USES_TEXT_UNIDECODE}" ]]; then pip install -q -r requirements.txt; else pip install -q -r requirements_alt.txt; fi - pip install -e . - - pip install pep8 + - pip install pycodestyle - pip install coveralls - pip install https://github.com/un33k/pyflakes/tarball/master before_script: - - "bash pep8.sh" + - "bash pycodestyle.sh" - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pyflakes -x W slugify; fi script: coverage run --source=slugify test.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a16c72a..e292880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,15 @@ +## 1.2.5 + - Add support for using text-unidecode (@bolkedebruin) + - Switch to pycodestyle instead of pep8 + ## 1.2.4 - Remove build artifacts during packaging - Simplify the setup.py file (@reece) +## 1.2.3 + - Remove build artifacts during packaging + - Simplify the setup.py file (@reece) + ## 1.2.3 - Republish - possible corrupt 1.2.2 build diff --git a/README.rst b/README.rst index 29b6e27..9604965 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ From sources via ``git``: $ git clone http://github.com/un33k/python-slugify $ cd python-slugify - $ python setup.py + $ python setup.py install From sources: @@ -39,7 +39,16 @@ From sources: $ wget https://github.com/un33k/python-slugify/zipball/master # unzip the downloaded file # cd into python-slugify-* directory - $ python setup.py + $ python setup.py install + +Note: + +By default *python-slugify* installs **unidecode** (GPL) for its decoding needs. + +Alternatively *python-slugify* can install and use **text-unidecode** (GPL & Perl Artistic) instead. This is done by setting up +an environment variable *SLUGIFY_USES_TEXT_UNIDECODE=yes* prior to installing and/or upgrading `python-slugify`. + +In cases where both **unidecode** and **text-unidecode** are installed, *python-slugify* always defaults to using **unidecode** regardless of the *SLUGIFY_USES_TEXT_UNIDECODE=yes* environment variable. How to use @@ -117,10 +126,6 @@ How to use r = slugify(txt, max_length=20, word_boundary=True, separator=".") self.assertEqual(r, "jaja.lol.mememeoo.a") - txt = 'jaja---lol-méméméoo--a' - r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ") - self.assertEqual(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa") - txt = 'one two three four five' r = slugify(txt, max_length=13, word_boundary=True, save_order=True) self.assertEqual(r, "one-two-three") @@ -186,6 +191,11 @@ License Released under a (`MIT`_) license. +**Note:** + +*python-slugify* relies on thirdparty **API** for decoding unicode strings. This dependency is kept at the public **API** ONLY in +order to ensure that *python-slugify* never becomes a **derivative work** of any other packages. MIT license holds. + Version ------- @@ -212,18 +222,3 @@ X.Y.Z Version .. _MIT: https://github.com/un33k/python-slugify/blob/master/LICENSE - -GPL ---- - -By default python-slugify depends on **unidecode** which is released under GPL. In case this is -a concern to you it is possible to install slugify with **text-unidecode** which is dual licensed -Perl Artistic and GPL. This can be done by: - -.. code:: bash - - $ export WITH_TEXTUNIDECODE=yes - -And then proceed with the normal installation instructions. Please note that this needs to be specified -for every upgrade. Also be aware that in case **unidecode* is present on the system python-slugify will -still default to using it. diff --git a/alt_requirements.txt b/alt_requirements.txt deleted file mode 100644 index 980e50a..0000000 --- a/alt_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -text-unidecode>=1.2 \ No newline at end of file diff --git a/pep8.sh b/pep8.sh deleted file mode 100755 index a8e960a..0000000 --- a/pep8.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Ignoring autogenerated files -# -- Migration directories -# Ignoring error codes -# -- E128 continuation line under-indented for visual indent -# -- E261 at least two spaces before inline comment -# -- E225 missing whitespace around operator -# -- E501 line too long - -pep8 --ignore=E128,E261,E225,E501 slugify test.py setup.py diff --git a/pycodestyle.sh b/pycodestyle.sh new file mode 100755 index 0000000..ab6766e --- /dev/null +++ b/pycodestyle.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Ignoring autogenerated files +# -- Migration directories +# Ignoring error codes +# -- E128 continuation line under-indented for visual indent +# -- E261 at least two spaces before inline comment +# -- E225 missing whitespace around operator +# -- E501 line too long + +pycodestyle --ignore=E128,E261,E225,E501 slugify test.py setup.py diff --git a/requirements_alt.txt b/requirements_alt.txt new file mode 100644 index 0000000..980e50a --- /dev/null +++ b/requirements_alt.txt @@ -0,0 +1 @@ +text-unidecode>=1.2 \ No newline at end of file diff --git a/setup.py b/setup.py index dcf21df..af831a8 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ url = 'https://github.com/un33k/python-slugify' author = 'Val Neekman' author_email = 'info@neekware.com' license = 'MIT' -if "WITH_TEXTUNIDECODE" in os.environ: +if "SLUGIFY_USES_TEXT_UNIDECODE" in os.environ: install_requires = ['text-unidecode>=1.2'] else: install_requires = ['Unidecode>=0.04.16'] diff --git a/slugify/__init__.py b/slugify/__init__.py index 79e1d28..02393a1 100644 --- a/slugify/__init__.py +++ b/slugify/__init__.py @@ -3,4 +3,4 @@ from .slugify import * __author__ = 'Val Neekman @ Neekware Inc. [@vneekman]' __description__ = 'A Python slugify application that also handles Unicode' -__version__ = '1.2.4' +__version__ = '1.2.5' diff --git a/slugify/slugify.py b/slugify/slugify.py index 8619184..99afb7f 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -112,14 +112,14 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w if decimal: try: text = DECIMAL_PATTERN.sub(lambda m: unichr(int(m.group(1))), text) - except: + except Exception: pass # hexadecimal character reference if hexadecimal: try: text = HEX_PATTERN.sub(lambda m: unichr(int(m.group(1), 16)), text) - except: + except Exception: pass # translate diff --git a/test.py b/test.py index 6730756..3d37a0b 100644 --- a/test.py +++ b/test.py @@ -210,5 +210,6 @@ class TestUtils(unittest.TestCase): r = smart_truncate(txt, max_length=100, separator='_') self.assertEqual(r, txt) + if __name__ == '__main__': unittest.main() -- cgit v1.2.1 From ce8e4bf423b8ec995ca98b7aee5abce7a251bd7e Mon Sep 17 00:00:00 2001 From: Val Neekman Date: Sun, 25 Mar 2018 10:59:22 -0400 Subject: simplify publishing --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index af831a8..3e2a490 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ if sys.argv[-1] == 'build': os.system("python setup.py sdist bdist_wheel") if sys.argv[-1] == 'publish': - os.system("twine upload dist/*") + os.system("python setup.py sdist upload") args = {'version': get_version(package)} print("You probably want to also tag the version now:") print(" git tag -a %(version)s -m 'version %(version)s' && git push --tags" % args) -- cgit v1.2.1