diff options
-rw-r--r-- | MANIFEST.in | 2 | ||||
-rw-r--r-- | README.rst | 6 | ||||
-rw-r--r-- | __init__.py | 3 | ||||
-rwxr-xr-x | bin/natsort (renamed from scripts/natsort) | 0 | ||||
-rw-r--r-- | natsort.py | 55 | ||||
-rw-r--r-- | setup.py | 27 |
6 files changed, 71 insertions, 22 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index 09d17d4..ce63398 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,4 @@ include README.rst include LICENSE include natsort.py include setup.py -include scripts/natsort +include bin/natsort @@ -158,6 +158,12 @@ Seth M. Morton History ------- +11-21-2012 v. 2.0.1 +''''''''''''''''''' + + - Reorganized directory structure + - Added tests into the natsort.py file iteself + 11-16-2012, v. 2.0.0 '''''''''''''''''''' diff --git a/__init__.py b/__init__.py deleted file mode 100644 index ae810db..0000000 --- a/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# For developement purposes only; will not be distributed with egg -from natsort import * -from natsort import __version__ diff --git a/scripts/natsort b/bin/natsort index 47f5db2..47f5db2 100755 --- a/scripts/natsort +++ b/bin/natsort @@ -1,4 +1,31 @@ -__version__ = '2.0.0' +''' +Here are a collection of examples of how this module can be used. +See the README or the natsort homepage for more details. + + >>> a = ['a2', 'a8', 'a7', 'a5', 'a9', 'a1', 'a4', 'a10', 'a3', 'a6'] + >>> sorted(a) + ['a1', 'a10', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9'] + >>> natsorted(a) + ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10'] + + >>> a = ['a50', 'a51.', 'a50.4', 'a5.034e1', 'a50.300'] + >>> sorted(a) + ['a5.034e1', 'a50', 'a50.300', 'a50.4', 'a51.'] + >>> natsorted(a) + ['a50', 'a50.300', 'a5.034e1', 'a50.4', 'a51.'] + + >>> a = ['1.9.9a', '1.11', '1.9.9b', '1.11.4', '1.10.1'] + >>> sorted(a) + ['1.10.1', '1.11', '1.11.4', '1.9.9a', '1.9.9b'] + >>> natsorted(a) + ['1.9.9a', '1.9.9b', '1.10.1', '1.11.4', '1.11'] + >>> a = ['1.9.9a', '1.11.0', '1.9.9b', '1.11.4', '1.10.1'] + >>> natsorted(a) + ['1.9.9a', '1.9.9b', '1.10.1', '1.11.0', '1.11.4'] + +''' + +__version__ = '2.0.1' import re # The regex that locates version numbers and floats @@ -29,6 +56,12 @@ def natsort_key(s): It also has basic support for version numbers. For use in passing to the :py:func:`sorted` builtin or :py:meth:`sort` attribute of lists. + + >>> a = ['num3', 'num5', 'num2'] + >>> a.sort(key=natsort_key) + >>> a + ['num2', 'num3', 'num5'] + ''' # If we are dealing with non-strings, return now @@ -80,6 +113,10 @@ def natsorted(seq): Sorts a sequence naturally (alphabetically and numerically), not by ASCII. + >>> a = ['num3', 'num5', 'num2'] + >>> natsorted(a) + ['num2', 'num3', 'num5'] + :argument seq: The sequence to be sorted. :type seq: sequence-like @@ -92,6 +129,17 @@ def index_natsorted(seq): Sorts a sequence naturally, but returns a list of sorted the indeces and not the sorted list. + >>> a = ['num3', 'num5', 'num2'] + >>> b = ['foo', 'bar', 'baz'] + >>> index = index_natsorted(a) + >>> # Sort both lists by the sort order of a + >>> a = [a[i] for i in index] + >>> b = [b[i] for i in index] + >>> a + ['num2', 'num3', 'num5'] + >>> b + ['baz', 'foo', 'bar'] + :argument seq: The sequence that you want the sorted index of. :type seq: sequence-like @@ -105,7 +153,4 @@ def index_natsorted(seq): # Test this module if __name__ == '__main__': import doctest - try: - doctest.testfile('README.rst') - except OSError: - doctest.testfile('README') + doctest.testmod() @@ -9,20 +9,19 @@ from os.path import join # Read the natsort.py file for the module version number import re VERSIONFILE = 'natsort.py' +versionsearch = re.compile(r"^__version__ = ['\"]([^'\"]*)['\"]") with open(VERSIONFILE, "rt") as fl: - versionstring = fl.readline().strip() -m = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", versionstring) -if m: - VERSION = m.group(1) -else: - s = "Unable to locate version string in {0}" - raise RuntimeError (s.format(VERSIONFILE)) - -# A description -DESCRIPTION = ('Provides routines and a command-line script to sort lists ' - 'naturally') + for line in fl: + m = versionsearch.search(line) + if m: + VERSION = m.group(1) + break + else: + s = "Unable to locate version string in {0}" + raise RuntimeError (s.format(VERSIONFILE)) # Read in the documentation for the long_description +DESCRIPTION = 'Sort lists naturally' try: with open('README.rst') as fl: LONG_DESCRIPTION = fl.read() @@ -37,15 +36,17 @@ setup(name='natsort', url='https://github.com/SethMMorton/natsort', license='MIT', py_modules=['natsort'], - scripts=[join('scripts', 'natsort')], + scripts=[join('bin', 'natsort')], description=DESCRIPTION, long_description=LONG_DESCRIPTION, classifiers=( - 'Development Status :: 4 - Beta', + #'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Intended Audience :: System Administrators', 'Intended Audience :: Information Technology', + 'Operating System :: OS Independent', 'License :: Freeware', 'Natural Language :: English', 'Programming Language :: Python :: 2.6', |