Skip to content

Commit

Permalink
Modified: improved package structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
futoase committed Oct 13, 2013
1 parent 2cbd4f3 commit 8cbae9d
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 35 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ Fizz
13
14
FizzBuzz

> bizzbuzz 15
1
2
Bizz
4
Buzz
Bizz
7
8
Bizz
Buzz
11
Bizz
13
14
BizzBuzz
```

# setup.py option

## build

```
> python setup.py build
```

## cleanup

```
> python setup.py clean --all
```

# License
Expand Down
15 changes: 15 additions & 0 deletions lib/bin/bizzbuzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from fizzbuzz import BizzBuzz
from argparse import ArgumentParser

def main():
bizzbuzz = BizzBuzz()
parser = ArgumentParser(description='fizzbuzz option')
parser.add_argument('n', help='target number')
args = parser.parse_args()
print('\n'.join(bizzbuzz(int(args.n))))

if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion lib/bin/fizzbuzz
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from fizzbuzz import fizzbuzz
from fizzbuzz import FizzBuzz
from argparse import ArgumentParser

def main():
fizzbuzz = FizzBuzz()
parser = ArgumentParser(description='fizzbuzz option')
parser.add_argument('n', help='target number')
args = parser.parse_args()
Expand Down
33 changes: 18 additions & 15 deletions lib/fizzbuzz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
__name__ = "PyFizzBuzz"
__version__ = "0.0.1"
__description__ = "FizzBuzz cli tool"
__author__ = "Keiji Matsuzaki"
__author_email__ = "[email protected]"
__license__ = "MIT License"
__url__ = "https://github.com/futoase/fizzbuzz"
__classifiers__ = [
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"License :: OSI Approved :: MIT License"
]
# -*- coding:utf-8 -*-

def fizzbuzz(n=100):
for i in range(1, n+1):
yield (('Fizz' * (i % 3 == 0) + 'Buzz' * (i % 5 == 0)) or str(i))
__info__ = dict(
name = "PyFizzBuzz",
version = "0.0.2",
description = "FizzBuzz cli tool",
author = "Keiji Matsuzaki",
author_email = "[email protected]",
license = "MIT License",
url = "https://github.com/futoase/fizzbuzz",
classifiers = [
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"License :: OSI Approved :: MIT License"
]
)

from .fizzbuzz import FizzBuzz
from .bizzbuzz import BizzBuzz
8 changes: 8 additions & 0 deletions lib/fizzbuzz/bizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding:utf-8 -*-

from .fizzbuzz_abs import FizzBuzzAbstract

class BizzBuzz(FizzBuzzAbstract):
def __call__(self, n):
for i in range(1, n+1):
yield (('Bizz' * (i % 3 == 0) + 'Buzz' * (i % 5 == 0)) or str(i))
8 changes: 8 additions & 0 deletions lib/fizzbuzz/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding:utf-8 -*-

from .fizzbuzz_abs import FizzBuzzAbstract

class FizzBuzz(FizzBuzzAbstract):
def __call__(self, n):
for i in range(1, n+1):
yield (('Fizz' * (i % 3 == 0) + 'Buzz' * (i % 5 == 0)) or str(i))
4 changes: 4 additions & 0 deletions lib/fizzbuzz/fizzbuzz_abs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding:utf-8 -*-

class FizzBuzzAbstract(object):
pass
36 changes: 36 additions & 0 deletions lib/test/case_bizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding:utf-8 -*-

import os
import sys

LIB_DIR = os.path.realpath('../')

if not LIB_DIR in sys.path:
sys.path.insert(0, LIB_DIR)

from fizzbuzz import BizzBuzz

describe "BizzBuzz target toone variable":

let bizzbuzz = BizzBuzz()

it "should be last valiable is 'BizzBuzz' when given 45":
assert list(self.bizzbuzz(45))[-1] == "BizzBuzz"

it "should be last valiable is 'Bizz' when given 3":
assert list(self.bizzbuzz(3))[-1] == "Bizz"

it "should be last valiable is 'Buzz' when given 5":
assert list(self.bizzbuzz(5))[-1] == "Buzz"

it "should be last valiable is 4 when given 4":
assert list(self.bizzbuzz(4))[-1] == "4"

describe "BizzBuzz check of result.":

let bizzbuzz = BizzBuzz()

let result = ['1', '2', 'Bizz', '4', 'Buzz', 'Bizz', '7', '8', 'Bizz', 'Buzz', '11', 'Bizz', '13', '14', 'BizzBuzz']
it "should be the same list is when given 15":

assert self.result == list(self.bizzbuzz(15))
16 changes: 10 additions & 6 deletions lib/test/case_fizzbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@
if not LIB_DIR in sys.path:
sys.path.insert(0, LIB_DIR)

from fizzbuzz import fizzbuzz
from fizzbuzz import FizzBuzz

describe "FizzBuzz target toone variable":

let fizzbuzz = FizzBuzz()

it "should be last valiable is 'FizzBuzz' when given 45":
assert list(fizzbuzz(45))[-1] == "FizzBuzz"
assert list(self.fizzbuzz(45))[-1] == "FizzBuzz"

it "should be last valiable is 'Fizz' when given 3":
assert list(fizzbuzz(3))[-1] == "Fizz"
assert list(self.fizzbuzz(3))[-1] == "Fizz"

it "should be last valiable is 'Buzz' when given 5":
assert list(fizzbuzz(5))[-1] == "Buzz"
assert list(self.fizzbuzz(5))[-1] == "Buzz"

it "should be last valiable is 4 when given 4":
assert list(fizzbuzz(4))[-1] == "4"
assert list(self.fizzbuzz(4))[-1] == "4"

describe "FizzBuzz check of result.":

let fizzbuzz = FizzBuzz()

let result = ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']
it "should be the same list is when given 15":

assert self.result == list(fizzbuzz(15))
assert self.result == list(self.fizzbuzz(15))
29 changes: 16 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
except ImportError:
print("Please install setuptools.")

def find_scripts(scripts_path):
base_path = os.path.abspath(scripts_path)
return list(map(lambda path: os.path.join(scripts_path, path),
filter(lambda file_name: os.path.isfile(
os.path.join(base_path, file_name)), os.listdir(base_path)
)))

import os
import sys

libdir = "lib"
bindir = os.path.join(libdir, "bin")

sys.path.insert(0, libdir)

import fizzbuzz as pkg

setup_options = {
"scripts": ["lib/bin/fizzbuzz"],
"name": pkg.__name__,
"version": pkg.__version__,
"description": pkg.__description__,
"author": pkg.__author__,
"author_email": pkg.__author_email__,
"license": pkg.__license__,
"url": pkg.__url__,
from fizzbuzz import __info__

setup_options = __info__
setup_options.update({
"scripts": find_scripts(bindir),
"packages": find_packages(libdir),
"package_dir": {"": libdir},
"classifiers": pkg.__classifiers__
}
})

setup(**setup_options)

0 comments on commit 8cbae9d

Please sign in to comment.