Initial commit

This commit is contained in:
Julien Palard 2024-03-14 09:15:38 +01:00
commit 4adf7f4f08
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
9 changed files with 83 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__/
.venv/
.envrc

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2024 Julien Palard
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.

View File

@ -0,0 +1,6 @@
"""Just a demo module to play with math series."""
__version__ = "0.1"
from math_doodling.public_api import fib
from math_doodling.exceptions import MyException

18
math_doodling/__main__.py Normal file
View File

@ -0,0 +1,18 @@
from argparse import ArgumentParser
from un_paquet import fib
def parse_args():
parser = ArgumentParser()
parser.add_argument("-v", help="Be verbose", action="store_true")
parser.add_argument("n", type=int)
return parser.parse_args()
def main():
args = parse_args()
print(fib(args.n))
print(__name__)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,2 @@
class MyException(Exception):
...

View File

View File

@ -0,0 +1,8 @@
from math_doodling.utils import cache
@cache(4096)
def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)

12
math_doodling/utils.py Normal file
View File

@ -0,0 +1,12 @@
def cache(limit):
def _cache(old_slow_function):
memory = {}
def new_faster_function(n):
if n in memory:
return memory[n]
result = old_slow_function(n)
if len(memory) < limit:
memory[n] = result
return result
return new_faster_function
return _cache

13
pyproject.toml Normal file
View File

@ -0,0 +1,13 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "math_doodling"
authors = [{name = "Julien Palard", email = "julien@palard.fr"}]
license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: MIT License"]
dynamic = ["version", "description"]
[project.urls]
Home = "https://git.afpy.org/mdk/math_doodling"