Skip to content

Commit d59cce6

Browse files
committed
Initial commit
0 parents  commit d59cce6

13 files changed

Lines changed: 307 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.6, 3.7, 3.8]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Lint with flake8
20+
run: |
21+
pip install flake8
22+
flake8 fibonacci --count --select=E9,F63,F7,F82 --show-source --statistics
23+
flake8 fibonacci --count --exit-zero --max-complexity=10 --statistics
24+
- name: Test with pytest
25+
run: |
26+
pip install .
27+
pip install pytest
28+
pytest

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Created by https://www.gitignore.io/api/python
2+
# Edit at https://www.gitignore.io/?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
pip-wheel-metadata/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
.hypothesis/
55+
.pytest_cache/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# pyenv
71+
.python-version
72+
73+
# pipenv
74+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
75+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
76+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
77+
# install all needed dependencies.
78+
#Pipfile.lock
79+
80+
# celery beat schedule file
81+
celerybeat-schedule
82+
83+
# SageMath parsed files
84+
*.sage.py
85+
86+
# Spyder project settings
87+
.spyderproject
88+
.spyproject
89+
90+
# Rope project settings
91+
.ropeproject
92+
93+
# Mr Developer
94+
.mr.developer.cfg
95+
.project
96+
.pydevproject
97+
98+
# mkdocs documentation
99+
/site
100+
101+
# mypy
102+
.mypy_cache/
103+
.dmypy.json
104+
dmypy.json
105+
106+
# Pyre type checker
107+
.pyre/
108+
109+
# End of https://www.gitignore.io/api/python
110+
111+
# Python virtual environment
112+
.venv/
113+
venv/

COMMANDS

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
INSTALL EDITABLE FROM SOURCE
2+
3+
pip install -e .
4+
5+
6+
RUN UNIT TEST
7+
8+
pytest
9+
10+
11+
RUN COVERAGE
12+
13+
coverage run -m pytest
14+
coverage report -m
15+
16+
17+
PACKAGING
18+
19+
SOURCE DISTRIBUTION
20+
21+
python setup.py sdist
22+
23+
BUILT DISTRIBUTION (MANIFEST.in DOES NOT AFFECT BUILT DISTRIBUTION)
24+
25+
pip install wheel
26+
python setup.py bdist_wheel

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Kevin Ma
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include COMMANDS
2+
include LICENSE
3+
include MANIFEST.in
4+
include README.rst
5+
graft fibonaci
6+
graft docs
7+
graft tests
8+
global-exclude __pycache__
9+
global-exclude *.py[co]

README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=========
2+
Fibonacci
3+
=========
4+
5+
This is a Python starter project. Use Fibonacci number as example.
6+
7+
Usage
8+
-----
9+
10+
From code:
11+
12+
.. code-block:: python
13+
14+
import fibonacci
15+
16+
f = fibonacci.compute(5)
17+
18+
From command line:
19+
20+
.. code-block::
21+
22+
$ fibonacci 5
23+
> [2020-03-03 12:34:56 +0800][fibonacci.bin][INFO] Fibonacci(5) = 5

docs/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
================
2+
Fibonacci number
3+
================
4+
5+
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>`_)

fibonacci/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging
2+
3+
logging.basicConfig(
4+
level=logging.INFO,
5+
format='[%(asctime)s][%(name)s][%(levelname)s] %(message)s',
6+
datefmt='%Y-%m-%d %H:%M:%S %z')
7+
8+
9+
def compute(num):
10+
assert num >= 0
11+
return num if num < 2 else compute(num - 1) + compute(num - 2)

fibonacci/bin/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
import logging
3+
import fibonacci
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
def compute():
9+
num = int(sys.argv[1])
10+
fib = fibonacci.compute(num)
11+
logger.info('Fibonacci(%d) = %d', num, fib)

setup.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[metadata]
2+
license_file = LICENSE
3+
4+
[bdist_wheel]
5+
universal = true
6+
7+
[tool:pytest]
8+
testpaths = tests
9+
10+
[coverage:run]
11+
branch = True
12+
source = fibonacci, tests
13+
omit = fibonacci/bin/*
14+
15+
[flake8]
16+
ignore = E203, E402, E501, E722

0 commit comments

Comments
 (0)