Skip to content

Commit

Permalink
update to 0.2.0 version.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brett committed Apr 17, 2018
1 parent 723411e commit caaa9df
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 35 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![GitHub version](https://badge.fury.io/gh/becurrie%2Fpy-custom-sorters.svg)](https://github.com/becurrie/sorters-py/releases)

# sorters-py
# py-sorts (0.2.0)

Sort Integers using different sorting algorithms!

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

```bash
python -m sorter -i 1 9 8 3 4 5 -s bogo -l
python -m py_sorter -i 1 9 8 3 4 5 -s bogo -l
```

Output:
Expand All @@ -50,7 +50,7 @@ Time(seconds): 0.0038447857274609663


```bash
python -m sorter -g 10000 -s quick
python -m py_sorter -g 10000 -s quick
```

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

- Clone repository locally.
- ```python setup.py install```.
- Access module from console with ```python -m sorter```.
- Access module from console with ```python -m py_sorter```.

## Development

### Launching

- While developing, inside root (/py_sorter) you can use two options to invoke:
- ```python sorter-runner.py [args]```
- ```python -m py_sorter [args]```

### Testing

- New tests can be added to the `run_all.py` file located at (/tests).

- To run automated tests:
- ```python -m unittest run_all```



## Authors

Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions py_sorter/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""py_sorter.__main__: executed when py_sorter directory is called as a script."""


from .sorter import main

main()
19 changes: 10 additions & 9 deletions sorter/sorter.py → py_sorter/sorter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""py_sorter.sorter: provides argument parsing and entry point main()."""

__version__ = "0.2.0"


import argparse
import os
import sys
import timeit

from sorter.sorts import *
from random import randint
from .sorts import *


def parse_args(args):
Expand Down Expand Up @@ -72,7 +78,7 @@ def generate_integer_list(size):
"""Generate a list of Integers between specified size value."""
integer_list = list()
for i in range(0, size):
integer_list.append(random.randint(0, 1000))
integer_list.append(randint(0, 1000))

return integer_list

Expand Down Expand Up @@ -139,9 +145,9 @@ def all_sorts(args):
sort(args)


def main(args):
def main():
"""Main method. build arguments, clear console and parse arguments"""
args = parse_args(args[1:])
args = parse_args(sys.argv[1:])

# Clear system terminal based on operating system name.
if os.name == 'posix':
Expand All @@ -158,8 +164,3 @@ def main(args):
all_sorts(args)
else:
sort(args)


if __name__ == "__main__":
# Allow import run through __name__ = __main__ idiom.
main(sys.argv)
3 changes: 3 additions & 0 deletions sorter/sorts.py → py_sorter/sorts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""py_sorter.sorts: sorts module containing all sort algorithm logic."""


import random


Expand Down
33 changes: 22 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from setuptools import setup, find_packages
"""setup.py: setuptools control."""

import re
from setuptools import setup


version = re.search('^__version__\s*=\s*"(.*)"',
open('py_sorter/sorter.py').read(),
re.M
).group(1)

with open("README.md", "rb") as f:
long_description = f.read().decode("utf-8")


setup(
name='sorter',
name='py-sorts',
packages=['py_sorter'],
entry_points={'console_scripts': ['py_sorter = py_sorter.sorter.main']},
version=version,
description="Sort integer lists using python in the command line.",
long_description=long_description,
author='Brett Currie',
author_email='[email protected]',
author='becurrie',
version='0.1.7',
description='sort integers with different sorting algorithms.',
packages=find_packages(),
py_modules=['sorter.sorter'],
entry_points={'console_scripts': ['sorter = sorter.sorter:main']},
license='MIT',
url='https://github.com/becurrie/sorters-py',
keywords=['sorting', 'algorithm', 'console', 'application'],
url='http://www.github.com/becurrie/py-sorts'
)
6 changes: 6 additions & 0 deletions sorter-runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Convenience wrapper for running py_sorter directly from source tree."""

from py_sorter.sorter import main

if __name__ == '__main__':
main()
7 changes: 0 additions & 7 deletions sorter/__main__.py

This file was deleted.

13 changes: 9 additions & 4 deletions test.py → tests/run_all.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""tests.run_all: Runs all tests for py_sorter console application."""
import os
import sys
import unittest

from sorter.sorts import *
from sorter.sorter import parse_args
sys.path.insert(0, os.path.abspath('..'))

from py_sorter.sorts import *
from py_sorter.sorter import parse_args


class TestParsing(unittest.TestCase):
Expand Down Expand Up @@ -76,12 +81,12 @@ def test_quick(self):
"""Test the quick_sort function."""
integers = quick_sort(self.actual)
self.assertEqual(self.expected, integers)

def test_radix(self):
"""Test the radix_sort function."""
integers = radix_sort(self.actual)
self.assertEqual(self.expected, integers)

def test_insertion(self):
"""Test the recursive insertion sort function."""
integers = insertion_sort(self.actual)
Expand Down

0 comments on commit caaa9df

Please sign in to comment.