From ad33581c491fd16cd64930fe02c862c04595550b Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 16 Feb 2022 16:11:08 -0500 Subject: version file, github action --- .github/workflows/dev.yml | 4 ++-- .vscode/settings.json | 3 ++- dev.requirements.txt | 3 ++- setup.py | 2 +- slugify/__init__.py | 5 ----- slugify/__main__.py | 4 ++-- slugify/__version__.py | 3 +++ slugify/slugify.py | 28 +++++++++------------------- slugify/special.py | 2 +- test.py | 1 - 10 files changed, 22 insertions(+), 33 deletions(-) create mode 100644 slugify/__version__.py diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 91929f7..fc6d0a5 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -30,11 +30,11 @@ jobs: - name: Run flake8 run: | pip install flake8 --upgrade - flake8 --exclude=migrations,tests --ignore=E501,E241,E225,E128 . + flake8 --exclude=build --ignore=E501,F403,F401,E241,E225,E128 . - name: Run pycodestyle run: | pip install pycodestyle --upgrade - pycodestyle --exclude=migrations,tests --ignore=E501,E241,E225,E128 . + pycodestyle --ignore=E128,E261,E225,E501,W605 slugify test.py setup.py - name: Run test run: | coverage run --source=python test.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ab09c1..ecfbb80 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "python.linting.pylintEnabled": false, "python.pythonPath": "/usr/bin/python3", -} \ No newline at end of file + "cSpell.words": ["Neekman", "shch", "xlate"] +} diff --git a/dev.requirements.txt b/dev.requirements.txt index 337aa36..2b4e781 100644 --- a/dev.requirements.txt +++ b/dev.requirements.txt @@ -1,2 +1,3 @@ pycodestyle==2.7.0 -twine==3.4.1 \ No newline at end of file +twine==3.4.1 +flake8==4.0.1 \ No newline at end of file diff --git a/setup.py b/setup.py index 769f5a1..8adc159 100755 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ def get_version(package): """ Return package version as listed in `__version__` in `init.py`. """ - init_py = codecs.open(os.path.join(package, '__init__.py'), encoding='utf-8').read() + init_py = codecs.open(os.path.join(package, '__version__.py'), encoding='utf-8').read() return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) diff --git a/slugify/__init__.py b/slugify/__init__.py index 6c59f4e..ac21492 100644 --- a/slugify/__init__.py +++ b/slugify/__init__.py @@ -1,7 +1,2 @@ from .special import * from .slugify import * - - -__author__ = 'Val Neekman @ Neekware Inc. [@vneekman]' -__description__ = 'A Python slugify application that also handles Unicode' -__version__ = '5.0.2' diff --git a/slugify/__main__.py b/slugify/__main__.py index f815206..ffdfd5f 100644 --- a/slugify/__main__.py +++ b/slugify/__main__.py @@ -77,7 +77,7 @@ def slugify_params(args): ) -def main(argv=None): # pragma: no cover +def main(argv=None): # pragma: no cover """ Run this program """ if argv is None: argv = sys.argv @@ -89,5 +89,5 @@ def main(argv=None): # pragma: no cover sys.exit(-1) -if __name__ == '__main__': # pragma: no cover +if __name__ == '__main__': # pragma: no cover main() diff --git a/slugify/__version__.py b/slugify/__version__.py new file mode 100644 index 0000000..72729f9 --- /dev/null +++ b/slugify/__version__.py @@ -0,0 +1,3 @@ +__author__ = 'Val Neekman @ Neekware Inc. [@vneekman]' +__description__ = 'A Python slugify application that also handles Unicode' +__version__ = '6.0.0' diff --git a/slugify/slugify.py b/slugify/slugify.py index bb3aa95..f38df10 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -1,17 +1,7 @@ import re import unicodedata -import types import sys - -try: - from htmlentitydefs import name2codepoint - _unicode = unicode - _unicode_type = types.UnicodeType -except ImportError: - from html.entities import name2codepoint - _unicode = str - _unicode_type = str - unichr = chr +from html.entities import name2codepoint try: import text_unidecode as unidecode @@ -69,7 +59,7 @@ def smart_truncate(string, max_length=0, word_boundary=False, separator=' ', sav else: if save_order: break - if not truncated: # pragma: no cover + if not truncated: # pragma: no cover truncated = string[:max_length] return truncated.strip(separator) @@ -100,8 +90,8 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w text = text.replace(old, new) # ensure text is unicode - if not isinstance(text, _unicode_type): - text = _unicode(text, 'utf-8', 'ignore') + if not isinstance(text, str): + text = str(text, 'utf-8', 'ignore') # replace quotes with dashes - pre-process text = QUOTE_PATTERN.sub(DEFAULT_SEPARATOR, text) @@ -110,24 +100,24 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w text = unidecode.unidecode(text) # ensure text is still in unicode - if not isinstance(text, _unicode_type): - text = _unicode(text, 'utf-8', 'ignore') + if not isinstance(text, str): + text = str(text, 'utf-8', 'ignore') # character entity reference if entities: - text = CHAR_ENTITY_PATTERN.sub(lambda m: unichr(name2codepoint[m.group(1)]), text) + text = CHAR_ENTITY_PATTERN.sub(lambda m: chr(name2codepoint[m.group(1)]), text) # decimal character reference if decimal: try: - text = DECIMAL_PATTERN.sub(lambda m: unichr(int(m.group(1))), text) + text = DECIMAL_PATTERN.sub(lambda m: chr(int(m.group(1))), text) except Exception: pass # hexadecimal character reference if hexadecimal: try: - text = HEX_PATTERN.sub(lambda m: unichr(int(m.group(1), 16)), text) + text = HEX_PATTERN.sub(lambda m: chr(int(m.group(1), 16)), text) except Exception: pass diff --git a/slugify/special.py b/slugify/special.py index d3478d5..54eb85c 100644 --- a/slugify/special.py +++ b/slugify/special.py @@ -20,7 +20,7 @@ _CYRILLIC = [ # package defaults: (u'я', u'ya'), # ia (u'х', u'h'), # kh (u'у', u'y'), # u - (u'щ', u'sch'), # shch + (u'щ', u'sch'), # sch (u'ю', u'u'), # iu / yu ] CYRILLIC = add_uppercase_char(_CYRILLIC) diff --git a/test.py b/test.py index ddf1bf4..1cd56dc 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import io -import os import sys import unittest from contextlib import contextmanager -- cgit v1.2.1