Skip to content

Commit caaa9df

Browse files
author
Brett
committed
update to 0.2.0 version.
restructure project to be more organized and allow development and testing without needing to install. tests moved into own folder for clarity. sorter-runner.py can be ran standalone for testing purposes. new readme heading for development.
1 parent 723411e commit caaa9df

File tree

9 files changed

+77
-35
lines changed

9 files changed

+77
-35
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![GitHub version](https://badge.fury.io/gh/becurrie%2Fpy-custom-sorters.svg)](https://github.com/becurrie/sorters-py/releases)
22

3-
# sorters-py
3+
# py-sorts (0.2.0)
44

55
Sort Integers using different sorting algorithms!
66

@@ -33,7 +33,7 @@ Check the [releases](https://github.com/becurrie/sorters-py/releases) section to
3333
## Examples
3434

3535
```bash
36-
python -m sorter -i 1 9 8 3 4 5 -s bogo -l
36+
python -m py_sorter -i 1 9 8 3 4 5 -s bogo -l
3737
```
3838

3939
Output:
@@ -50,7 +50,7 @@ Time(seconds): 0.0038447857274609663
5050

5151

5252
```bash
53-
python -m sorter -g 10000 -s quick
53+
python -m py_sorter -g 10000 -s quick
5454
```
5555

5656
Output:
@@ -70,7 +70,24 @@ an array and checks it's been sorted, shuffling infinitely until list is sorted.
7070

7171
- Clone repository locally.
7272
- ```python setup.py install```.
73-
- Access module from console with ```python -m sorter```.
73+
- Access module from console with ```python -m py_sorter```.
74+
75+
## Development
76+
77+
### Launching
78+
79+
- While developing, inside root (/py_sorter) you can use two options to invoke:
80+
- ```python sorter-runner.py [args]```
81+
- ```python -m py_sorter [args]```
82+
83+
### Testing
84+
85+
- New tests can be added to the `run_all.py` file located at (/tests).
86+
87+
- To run automated tests:
88+
- ```python -m unittest run_all```
89+
90+
7491

7592
## Authors
7693

py_sorter/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""py_sorter.__main__: executed when py_sorter directory is called as a script."""
2+
3+
4+
from .sorter import main
5+
6+
main()

sorter/sorter.py renamed to py_sorter/sorter.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
"""py_sorter.sorter: provides argument parsing and entry point main()."""
2+
3+
__version__ = "0.2.0"
4+
5+
16
import argparse
27
import os
38
import sys
49
import timeit
510

6-
from sorter.sorts import *
11+
from random import randint
12+
from .sorts import *
713

814

915
def parse_args(args):
@@ -72,7 +78,7 @@ def generate_integer_list(size):
7278
"""Generate a list of Integers between specified size value."""
7379
integer_list = list()
7480
for i in range(0, size):
75-
integer_list.append(random.randint(0, 1000))
81+
integer_list.append(randint(0, 1000))
7682

7783
return integer_list
7884

@@ -139,9 +145,9 @@ def all_sorts(args):
139145
sort(args)
140146

141147

142-
def main(args):
148+
def main():
143149
"""Main method. build arguments, clear console and parse arguments"""
144-
args = parse_args(args[1:])
150+
args = parse_args(sys.argv[1:])
145151

146152
# Clear system terminal based on operating system name.
147153
if os.name == 'posix':
@@ -158,8 +164,3 @@ def main(args):
158164
all_sorts(args)
159165
else:
160166
sort(args)
161-
162-
163-
if __name__ == "__main__":
164-
# Allow import run through __name__ = __main__ idiom.
165-
main(sys.argv)

sorter/sorts.py renamed to py_sorter/sorts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""py_sorter.sorts: sorts module containing all sort algorithm logic."""
2+
3+
14
import random
25

36

setup.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
from setuptools import setup, find_packages
1+
"""setup.py: setuptools control."""
2+
3+
import re
4+
from setuptools import setup
5+
6+
7+
version = re.search('^__version__\s*=\s*"(.*)"',
8+
open('py_sorter/sorter.py').read(),
9+
re.M
10+
).group(1)
11+
12+
with open("README.md", "rb") as f:
13+
long_description = f.read().decode("utf-8")
14+
215

316
setup(
4-
name='sorter',
17+
name='py-sorts',
18+
packages=['py_sorter'],
19+
entry_points={'console_scripts': ['py_sorter = py_sorter.sorter.main']},
20+
version=version,
21+
description="Sort integer lists using python in the command line.",
22+
long_description=long_description,
23+
author='Brett Currie',
524
author_email='brettecurrie@gmail.com',
6-
author='becurrie',
7-
version='0.1.7',
8-
description='sort integers with different sorting algorithms.',
9-
packages=find_packages(),
10-
py_modules=['sorter.sorter'],
11-
entry_points={'console_scripts': ['sorter = sorter.sorter:main']},
12-
license='MIT',
13-
url='https://github.com/becurrie/sorters-py',
14-
keywords=['sorting', 'algorithm', 'console', 'application'],
25+
url='http://www.github.com/becurrie/py-sorts'
1526
)

sorter-runner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Convenience wrapper for running py_sorter directly from source tree."""
2+
3+
from py_sorter.sorter import main
4+
5+
if __name__ == '__main__':
6+
main()

sorter/__main__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

test.py renamed to tests/run_all.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
"""tests.run_all: Runs all tests for py_sorter console application."""
2+
import os
3+
import sys
14
import unittest
25

3-
from sorter.sorts import *
4-
from sorter.sorter import parse_args
6+
sys.path.insert(0, os.path.abspath('..'))
7+
8+
from py_sorter.sorts import *
9+
from py_sorter.sorter import parse_args
510

611

712
class TestParsing(unittest.TestCase):
@@ -76,12 +81,12 @@ def test_quick(self):
7681
"""Test the quick_sort function."""
7782
integers = quick_sort(self.actual)
7883
self.assertEqual(self.expected, integers)
79-
84+
8085
def test_radix(self):
8186
"""Test the radix_sort function."""
8287
integers = radix_sort(self.actual)
8388
self.assertEqual(self.expected, integers)
84-
89+
8590
def test_insertion(self):
8691
"""Test the recursive insertion sort function."""
8792
integers = insertion_sort(self.actual)

0 commit comments

Comments
 (0)