Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kuima committed Mar 3, 2020
0 parents commit d59cce6
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Lint with flake8
run: |
pip install flake8
flake8 fibonacci --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 fibonacci --count --exit-zero --max-complexity=10 --statistics
- name: Test with pytest
run: |
pip install .
pip install pytest
pytest
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/python

# Python virtual environment
.venv/
venv/
26 changes: 26 additions & 0 deletions COMMANDS
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
INSTALL EDITABLE FROM SOURCE

pip install -e .


RUN UNIT TEST

pytest


RUN COVERAGE

coverage run -m pytest
coverage report -m


PACKAGING

SOURCE DISTRIBUTION

python setup.py sdist

BUILT DISTRIBUTION (MANIFEST.in DOES NOT AFFECT BUILT DISTRIBUTION)

pip install wheel
python setup.py bdist_wheel
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Kevin Ma

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include COMMANDS
include LICENSE
include MANIFEST.in
include README.rst
graft fibonaci
graft docs
graft tests
global-exclude __pycache__
global-exclude *.py[co]
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=========
Fibonacci
=========

This is a Python starter project. Use Fibonacci number as example.

Usage
-----

From code:

.. code-block:: python
import fibonacci
f = fibonacci.compute(5)
From command line:

.. code-block::
$ fibonacci 5
> [2020-03-03 12:34:56 +0800][fibonacci.bin][INFO] Fibonacci(5) = 5
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
================
Fibonacci number
================

In mathematics, the Fibonacci numbers, commonly denoted F(n), form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2), for n > 1. (`Wikipedia <https://en.wikipedia.org/wiki/Fibonacci_number>`_)
11 changes: 11 additions & 0 deletions fibonacci/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s][%(name)s][%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S %z')


def compute(num):
assert num >= 0
return num if num < 2 else compute(num - 1) + compute(num - 2)
11 changes: 11 additions & 0 deletions fibonacci/bin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
import logging
import fibonacci

logger = logging.getLogger(__name__)


def compute():
num = int(sys.argv[1])
fib = fibonacci.compute(num)
logger.info('Fibonacci(%d) = %d', num, fib)
16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[metadata]
license_file = LICENSE

[bdist_wheel]
universal = true

[tool:pytest]
testpaths = tests

[coverage:run]
branch = True
source = fibonacci, tests
omit = fibonacci/bin/*

[flake8]
ignore = E203, E402, E501, E722
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import find_packages, setup

setup(
name='fibonacci',
version='1.0.0',
packages=find_packages(),
entry_points={
'console_scripts': [
'fibonacci = fibonacci.bin:compute'
]
}
)
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import unittest
import fibonacci


class CLITestCase(unittest.TestCase):

def test_cli_success(self):
assert os.system('fibonacci 5') == 0

def test_cli_failure(self):
assert os.system('fibonacci -1') != 0
20 changes: 20 additions & 0 deletions tests/test_fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest
import fibonacci


class FibonacciTestCase(unittest.TestCase):

def test_compute_0(self):
assert fibonacci.compute(0) == 0

def test_compute_1(self):
assert fibonacci.compute(1) == 1

def test_compute_2(self):
assert fibonacci.compute(2) == 1

def test_compute_5(self):
assert fibonacci.compute(5) == 5

def test_compute_6(self):
assert fibonacci.compute(6) == 8

0 comments on commit d59cce6

Please sign in to comment.