Skip to content

Commit 8e360ae

Browse files
committed
support for text-unidecode
1 parent 874fe14 commit 8e360ae

9 files changed

+35
-31
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ python:
1111
- pypy
1212

1313
env:
14-
- WITH_TEXTUNIDECODE=yes
15-
- WITH_UNIDECODE=yes # this is redundant but otherwise travis will only trigger one build type
14+
- SLUGIFY_USES_TEXT_UNIDECODE=yes
15+
- SLUGIFY_USES_UNIDECODE=yes # dummy: tell travis to run more than one build types
1616

1717
install:
1818
- pip install pip -U
19-
- if [[ -z "${WITH_TEXTUNIDECODE}" ]]; then pip install -q -r requirements.txt; else pip install -q -r alt_requirements.txt; fi
19+
- if [[ -z "${SLUGIFY_USES_TEXT_UNIDECODE}" ]]; then pip install -q -r requirements.txt; else pip install -q -r requirements_alt.txt; fi
2020
- pip install -e .
21-
- pip install pep8
21+
- pip install pycodestyle
2222
- pip install coveralls
2323
- pip install https://github.com/un33k/pyflakes/tarball/master
2424

2525
before_script:
26-
- "bash pep8.sh"
26+
- "bash pycodestyle.sh"
2727
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pyflakes -x W slugify; fi
2828

2929
script: coverage run --source=slugify test.py

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
## 1.2.5
2+
- Add support for using text-unidecode (@bolkedebruin)
3+
- Switch to pycodestyle instead of pep8
4+
15
## 1.2.4
26
- Remove build artifacts during packaging
37
- Simplify the setup.py file (@reece)
48

9+
## 1.2.3
10+
- Remove build artifacts during packaging
11+
- Simplify the setup.py file (@reece)
12+
513
## 1.2.3
614
- Republish - possible corrupt 1.2.2 build
715

README.rst

+16-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ From sources via ``git``:
3030
3131
$ git clone http://github.com/un33k/python-slugify
3232
$ cd python-slugify
33-
$ python setup.py
33+
$ python setup.py install
3434
3535
From sources:
3636

@@ -39,7 +39,16 @@ From sources:
3939
$ wget https://github.com/un33k/python-slugify/zipball/master
4040
# unzip the downloaded file
4141
# cd into python-slugify-* directory
42-
$ python setup.py
42+
$ python setup.py install
43+
44+
Note:
45+
46+
By default *python-slugify* installs **unidecode** (GPL) for its decoding needs.
47+
48+
Alternatively *python-slugify* can install and use **text-unidecode** (GPL & Perl Artistic) instead. This is done by setting up
49+
an environment variable *SLUGIFY_USES_TEXT_UNIDECODE=yes* prior to installing and/or upgrading `python-slugify`.
50+
51+
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.
4352

4453

4554
How to use
@@ -117,10 +126,6 @@ How to use
117126
r = slugify(txt, max_length=20, word_boundary=True, separator=".")
118127
self.assertEqual(r, "jaja.lol.mememeoo.a")
119128
120-
txt = 'jaja---lol-méméméoo--a'
121-
r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ")
122-
self.assertEqual(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa")
123-
124129
txt = 'one two three four five'
125130
r = slugify(txt, max_length=13, word_boundary=True, save_order=True)
126131
self.assertEqual(r, "one-two-three")
@@ -186,6 +191,11 @@ License
186191

187192
Released under a (`MIT`_) license.
188193

194+
**Note:**
195+
196+
*python-slugify* relies on thirdparty **API** for decoding unicode strings. This dependency is kept at the public **API** ONLY in
197+
order to ensure that *python-slugify* never becomes a **derivative work** of any other packages. MIT license holds.
198+
189199

190200
Version
191201
-------
@@ -212,18 +222,3 @@ X.Y.Z Version
212222

213223
.. _MIT: https://github.com/un33k/python-slugify/blob/master/LICENSE
214224

215-
216-
GPL
217-
---
218-
219-
By default python-slugify depends on **unidecode** which is released under GPL. In case this is
220-
a concern to you it is possible to install slugify with **text-unidecode** which is dual licensed
221-
Perl Artistic and GPL. This can be done by:
222-
223-
.. code:: bash
224-
225-
$ export WITH_TEXTUNIDECODE=yes
226-
227-
And then proceed with the normal installation instructions. Please note that this needs to be specified
228-
for every upgrade. Also be aware that in case **unidecode* is present on the system python-slugify will
229-
still default to using it.

pep8.sh pycodestyle.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
# -- E225 missing whitespace around operator
99
# -- E501 line too long
1010

11-
pep8 --ignore=E128,E261,E225,E501 slugify test.py setup.py
11+
pycodestyle --ignore=E128,E261,E225,E501 slugify test.py setup.py
File renamed without changes.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
author = 'Val Neekman'
1616
author_email = 'info@neekware.com'
1717
license = 'MIT'
18-
if "WITH_TEXTUNIDECODE" in os.environ:
18+
if "SLUGIFY_USES_TEXT_UNIDECODE" in os.environ:
1919
install_requires = ['text-unidecode>=1.2']
2020
else:
2121
install_requires = ['Unidecode>=0.04.16']

slugify/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
__author__ = 'Val Neekman @ Neekware Inc. [@vneekman]'
55
__description__ = 'A Python slugify application that also handles Unicode'
6-
__version__ = '1.2.4'
6+
__version__ = '1.2.5'

slugify/slugify.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
112112
if decimal:
113113
try:
114114
text = DECIMAL_PATTERN.sub(lambda m: unichr(int(m.group(1))), text)
115-
except:
115+
except Exception:
116116
pass
117117

118118
# hexadecimal character reference
119119
if hexadecimal:
120120
try:
121121
text = HEX_PATTERN.sub(lambda m: unichr(int(m.group(1), 16)), text)
122-
except:
122+
except Exception:
123123
pass
124124

125125
# translate

test.py

+1
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,6 @@ def test_smart_truncate_no_seperator(self):
210210
r = smart_truncate(txt, max_length=100, separator='_')
211211
self.assertEqual(r, txt)
212212

213+
213214
if __name__ == '__main__':
214215
unittest.main()

0 commit comments

Comments
 (0)