summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Neekman <val@neekware.com>2018-03-25 09:16:14 -0400
committerVal Neekman <val@neekware.com>2018-03-25 09:16:14 -0400
commitd12d1fc3851628dba7b071d13d1e61ccbf636fa2 (patch)
treee151395fb1f1b038215fd8abcfcf28c93a9405c1
parent52e5c3652a2fb1297dd5997c71c38fa4d7f78f73 (diff)
parent874fe140aa68ee1065e2170385f8c4ace5ac644a (diff)
downloadpython-slugify-d12d1fc3851628dba7b071d13d1e61ccbf636fa2.tar.gz
support of text-unidecode
-rw-r--r--.travis.yml10
-rw-r--r--CHANGELOG.md7
-rw-r--r--MANIFEST.in3
-rw-r--r--README.rst23
-rw-r--r--alt_requirements.txt1
-rwxr-xr-xpycodestyle.sh (renamed from pep8.sh)2
-rwxr-xr-xsetup.py5
-rw-r--r--slugify/__init__.py2
-rw-r--r--slugify/slugify.py10
-rw-r--r--test.py1
10 files changed, 48 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml
index d852b0a..a338f6f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,16 +10,20 @@ python:
- "3.6"
- pypy
+env:
+ - SLUGIFY_USE_TEXT_UNIDECODE=yes
+ - SLUGIFY_USE_UNIDECODE=yes # this is redundant but otherwise travis will only trigger one build type
+
install:
- pip install pip -U
- - pip install -q -r requirements.txt
+ - if [[ -z "${SLUGIFY_USE_TEXT_UNIDECODE}" ]]; then pip install -q -r requirements.txt; else pip install -q -r alt_requirements.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 aa33321..f02ecd2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 1.2.5
+ - Add support for using text-unidecode (@bolkedebruin)
+
+## 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)
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..a755e2e
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,3 @@
+include CHANGELOG.md
+include LICENSE
+include README.rst
diff --git a/README.rst b/README.rst
index a5a62ac..04b0fc9 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 `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.
+
Version
-------
@@ -211,3 +221,4 @@ X.Y.Z Version
:target: https://pypi.python.org/pypi/python-slugify
.. _MIT: https://github.com/un33k/python-slugify/blob/master/LICENSE
+
diff --git a/alt_requirements.txt b/alt_requirements.txt
new file mode 100644
index 0000000..980e50a
--- /dev/null
+++ b/alt_requirements.txt
@@ -0,0 +1 @@
+text-unidecode>=1.2 \ No newline at end of file
diff --git a/pep8.sh b/pycodestyle.sh
index a8e960a..ab6766e 100755
--- a/pep8.sh
+++ b/pycodestyle.sh
@@ -8,4 +8,4 @@
# -- E225 missing whitespace around operator
# -- E501 line too long
-pep8 --ignore=E128,E261,E225,E501 slugify test.py setup.py
+pycodestyle --ignore=E128,E261,E225,E501 slugify test.py setup.py
diff --git a/setup.py b/setup.py
index abfaa3f..230c93a 100755
--- a/setup.py
+++ b/setup.py
@@ -15,7 +15,10 @@ url = 'https://github.com/un33k/python-slugify'
author = 'Val Neekman'
author_email = 'info@neekware.com'
license = 'MIT'
-install_requires = ['Unidecode>=0.04.16']
+if "SLUGIFY_USE_TEXT_UNIDECODE" in os.environ:
+ install_requires = ['text-unidecode>=1.2']
+else:
+ install_requires = ['Unidecode>=0.04.16']
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
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 af0c609..99afb7f 100644
--- a/slugify/slugify.py
+++ b/slugify/slugify.py
@@ -13,8 +13,10 @@ except ImportError:
_unicode_type = str
unichr = chr
-import unidecode
-
+try:
+ import unidecode
+except ImportError:
+ import text_unidecode as unidecode
__all__ = ['slugify', 'smart_truncate']
@@ -110,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()