binnev-python-template 1.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- __init__.py +0 -0
- api/__init__.py +1 -0
- api/app.py +7 -0
- api/calculator.py +75 -0
- binnev_python_template-1.2.2.dist-info/METADATA +54 -0
- binnev_python_template-1.2.2.dist-info/RECORD +13 -0
- binnev_python_template-1.2.2.dist-info/WHEEL +5 -0
- binnev_python_template-1.2.2.dist-info/top_level.txt +4 -0
- cli/__init__.py +1 -0
- cli/__main__.py +4 -0
- cli/calculator.py +94 -0
- core/__init__.py +2 -0
- core/calculator.py +95 -0
__init__.py
ADDED
|
File without changes
|
api/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .app import app as app
|
api/app.py
ADDED
api/calculator.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from fastapi import APIRouter, HTTPException
|
|
2
|
+
|
|
3
|
+
from src.core import calculator
|
|
4
|
+
|
|
5
|
+
calculator_router = APIRouter()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@calculator_router.get("/add")
|
|
9
|
+
def add(a: float, b: float):
|
|
10
|
+
"""
|
|
11
|
+
Endpoint to add two numbers.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
a (float): The first number to add.
|
|
15
|
+
b (float): The second number to add.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
dict: The result of the addition.
|
|
19
|
+
"""
|
|
20
|
+
result = calculator.add(a, b)
|
|
21
|
+
return {"result": result}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@calculator_router.get("/subtract")
|
|
25
|
+
def subtract(a: float, b: float):
|
|
26
|
+
"""
|
|
27
|
+
Endpoint to subtract two numbers.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
a (float): The number to subtract from.
|
|
31
|
+
b (float): The number to subtract.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
dict: The result of the subtraction.
|
|
35
|
+
"""
|
|
36
|
+
result = calculator.subtract(a, b)
|
|
37
|
+
return {"result": result}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@calculator_router.get("/multiply")
|
|
41
|
+
def multiply(a: float, b: float):
|
|
42
|
+
"""
|
|
43
|
+
Endpoint to multiply two numbers.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
a (float): The first number to multiply.
|
|
47
|
+
b (float): The second number to multiply.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
dict: The result of the multiplication.
|
|
51
|
+
"""
|
|
52
|
+
result = calculator.multiply(a, b)
|
|
53
|
+
return {"result": result}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@calculator_router.get("/divide")
|
|
57
|
+
def divide(a: float, b: float):
|
|
58
|
+
"""
|
|
59
|
+
Endpoint to divide two numbers.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
a (float): The numerator.
|
|
63
|
+
b (float): The denominator.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
dict: The result of the division.
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
HTTPException: If division by zero is attempted.
|
|
70
|
+
"""
|
|
71
|
+
try:
|
|
72
|
+
result = calculator.divide(a, b)
|
|
73
|
+
return {"result": result}
|
|
74
|
+
except ValueError as e:
|
|
75
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: binnev-python-template
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author-email: Robin Neville <robin.m.neville@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/binnev/python-template
|
|
8
|
+
Requires-Python: >=3.13
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: fastapi>=0.115.12
|
|
11
|
+
Requires-Dist: httpx>=0.28.1
|
|
12
|
+
Requires-Dist: typer>=0.15.4
|
|
13
|
+
Requires-Dist: uvicorn>=0.34.2
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-asyncio>=1.0.0; extra == "dev"
|
|
17
|
+
Requires-Dist: pytest-dotenv>=0.5.2; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest-watcher>=0.4.3; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-xdist>=3.6.1; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-sugar>=1.0.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-better-parametrize>=0.2.0; extra == "dev"
|
|
23
|
+
Requires-Dist: coverage>=7.8.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.11.10; extra == "dev"
|
|
25
|
+
Requires-Dist: mypy>=1.15.0; extra == "dev"
|
|
26
|
+
Requires-Dist: mkdocs>=1.6.1; extra == "dev"
|
|
27
|
+
Requires-Dist: mkdocs-material>=9.6.14; extra == "dev"
|
|
28
|
+
Requires-Dist: mkdocstrings[python]>=0.29.1; extra == "dev"
|
|
29
|
+
Requires-Dist: mkdocs-mermaid2-plugin>=1.2.1; extra == "dev"
|
|
30
|
+
Requires-Dist: mike>=2.1.3; extra == "dev"
|
|
31
|
+
Requires-Dist: commitizen>=4.7.2; extra == "dev"
|
|
32
|
+
Requires-Dist: pre-commit>=4.2.0; extra == "dev"
|
|
33
|
+
Requires-Dist: build>=1.2.2.post1; extra == "dev"
|
|
34
|
+
Requires-Dist: twine>=6.1.0; extra == "dev"
|
|
35
|
+
|
|
36
|
+
# Python project template
|
|
37
|
+
This project is a template for new python projects. It contains up-to-date tooling for tests, docs, versioning, and dependency management.
|
|
38
|
+
|
|
39
|
+
In a nutshell, the idea is that you clone/fork this project, and then modify it to suit your new project. The [`docs/how-to/getting-started.md`](tutorials/getting-started.md) page provides a step-by-step guide.
|
|
40
|
+
|
|
41
|
+
## Documentation
|
|
42
|
+
To view the documentation, run:
|
|
43
|
+
```sh
|
|
44
|
+
mkdocs serve
|
|
45
|
+
```
|
|
46
|
+
and go to [localhost:8000](http://localhost:8000) in your browser.
|
|
47
|
+
|
|
48
|
+
The documentation provides a detailed guide to the project. It is structured using the [Diátaxis framework](https://diataxis.fr/) to help you navigate and understand the project effectively. This framework consists of 4 categories:
|
|
49
|
+
|
|
50
|
+
1. **Tutorials**: Guides that teach a concept.
|
|
51
|
+
2. **How-To Guides**: Step-by-step instructions to achieve specific goals or tasks.
|
|
52
|
+
3. **Reference**: Technical descriptions of the project's components and APIs.
|
|
53
|
+
4. **Explanations**: In-depth discussions of concepts and motivations.
|
|
54
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
api/__init__.py,sha256=sMZ_Q3pHNHBOBkJ3_K3VIH4de_UvfBsUnxfNKLgPnnU,28
|
|
3
|
+
api/app.py,sha256=pwmavYIVvWcucQ13Wf4V-iH4qy-2cr06XI2zfMZj_Pg,149
|
|
4
|
+
api/calculator.py,sha256=a5sJRHbznv91ldM3LtjFJBqaJ0O6w0HqyQ1If5Y_r68,1664
|
|
5
|
+
cli/__init__.py,sha256=JuQR1P36bOLj9DU5rMC_4OPRsj48OkFaBSPFTMjlUSc,35
|
|
6
|
+
cli/__main__.py,sha256=yhh9JvWC840Ev_lWj3QovGBR2Tj6eUzgWYh0as1spLc,62
|
|
7
|
+
cli/calculator.py,sha256=cvsrwMbizv8l4sDXjbaXogRBRr4d3DZEyXXtCLAK614,2168
|
|
8
|
+
core/__init__.py,sha256=R3pyZpIhsGzw3M3SbELzxNis7FzslLTZwxjOrmowkdU,55
|
|
9
|
+
core/calculator.py,sha256=rYsUuuAbmRnkdDjmZBFlTgOmIAexF332ELzWVQPoQw0,1790
|
|
10
|
+
binnev_python_template-1.2.2.dist-info/METADATA,sha256=1RMu2CJLsWMBLSliLht8bfLhgAWugc00N0gxVizOyyI,2502
|
|
11
|
+
binnev_python_template-1.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
binnev_python_template-1.2.2.dist-info/top_level.txt,sha256=tnrNGeZWxGB7wuuBAehLylpPK3dJdsMjjMfpCEYgrxc,22
|
|
13
|
+
binnev_python_template-1.2.2.dist-info/RECORD,,
|
cli/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .calculator import app as app
|
cli/__main__.py
ADDED
cli/calculator.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides CLI commands for performing basic arithmetic operations.
|
|
3
|
+
|
|
4
|
+
It uses the `typer` library to define commands for addition, subtraction,
|
|
5
|
+
multiplication, and division. Each command takes two numbers as input and prints
|
|
6
|
+
the result to the console.
|
|
7
|
+
|
|
8
|
+
The module relies on the `core.calculator` module for the actual arithmetic
|
|
9
|
+
operations.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Optional
|
|
13
|
+
|
|
14
|
+
import typer
|
|
15
|
+
|
|
16
|
+
from src import core
|
|
17
|
+
from src.core import calculator
|
|
18
|
+
|
|
19
|
+
app = typer.Typer()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@app.command()
|
|
23
|
+
def add(a: float, b: float) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Add two numbers.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
a (float): The first number to add.
|
|
29
|
+
b (float): The second number to add.
|
|
30
|
+
"""
|
|
31
|
+
result = calculator.add(a, b)
|
|
32
|
+
typer.echo(f"The result of addition is: {result}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.command()
|
|
36
|
+
def subtract(a: float, b: float) -> None:
|
|
37
|
+
"""
|
|
38
|
+
Subtract two numbers.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
a (float): The number to subtract from.
|
|
42
|
+
b (float): The number to subtract.
|
|
43
|
+
"""
|
|
44
|
+
result = calculator.subtract(a, b)
|
|
45
|
+
typer.echo(f"The result of subtraction is: {result}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@app.command()
|
|
49
|
+
def multiply(a: float, b: float) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Multiply two numbers.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
a (float): The first number to multiply.
|
|
55
|
+
b (float): The second number to multiply.
|
|
56
|
+
"""
|
|
57
|
+
result = calculator.multiply(a, b)
|
|
58
|
+
typer.echo(f"The result of multiplication is: {result}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@app.command()
|
|
62
|
+
def divide(a: float, b: float) -> None:
|
|
63
|
+
"""
|
|
64
|
+
Divide two numbers.
|
|
65
|
+
Args:
|
|
66
|
+
a (float): The numerator.
|
|
67
|
+
b (float): The denominator.
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
result = calculator.divide(a, b)
|
|
71
|
+
typer.echo(f"The result of division is: {result}")
|
|
72
|
+
except ValueError as e:
|
|
73
|
+
typer.echo(f"Error: {e}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _version_callback(value: bool) -> None:
|
|
77
|
+
if value:
|
|
78
|
+
typer.echo(f"{core.__app_name__} v{core.__version__}")
|
|
79
|
+
raise typer.Exit()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.callback()
|
|
83
|
+
def main(
|
|
84
|
+
version: Optional[bool] = typer.Option(
|
|
85
|
+
None,
|
|
86
|
+
"--version",
|
|
87
|
+
"-v",
|
|
88
|
+
help="Show the application's version and exit.",
|
|
89
|
+
callback=_version_callback,
|
|
90
|
+
is_eager=True,
|
|
91
|
+
),
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Handles the --version flag"""
|
|
94
|
+
return
|
core/__init__.py
ADDED
core/calculator.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""The core calculator library with basic arithmetic operations."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def add(a: float, b: float) -> float:
|
|
5
|
+
"""
|
|
6
|
+
Return the sum of two numbers.
|
|
7
|
+
|
|
8
|
+
The `add` function is a simple utility designed to perform the addition of
|
|
9
|
+
two floating-point numbers. It takes two arguments, `a` and `b`, both of
|
|
10
|
+
which are expected to be of type `float`. The function returns their sum,
|
|
11
|
+
also as a `float`.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
a: The first number.
|
|
15
|
+
b: The second number.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
The sum of the two numbers.
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
>>> add(2, 3)
|
|
22
|
+
5
|
|
23
|
+
|
|
24
|
+
>>> add(-1, 1)
|
|
25
|
+
0
|
|
26
|
+
"""
|
|
27
|
+
return a + b
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def subtract(a: float, b: float) -> float:
|
|
31
|
+
"""
|
|
32
|
+
Return the difference of two numbers.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
a: The first number.
|
|
36
|
+
b: The second number.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
The difference of the two numbers.
|
|
40
|
+
|
|
41
|
+
Examples:
|
|
42
|
+
>>> subtract(5, 3)
|
|
43
|
+
2
|
|
44
|
+
|
|
45
|
+
>>> subtract(2, 5)
|
|
46
|
+
-3
|
|
47
|
+
"""
|
|
48
|
+
return a - b
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def multiply(a: float, b: float) -> float:
|
|
52
|
+
"""
|
|
53
|
+
Return the product of two numbers.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
a: The first number.
|
|
57
|
+
b: The second number.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
The product of the two numbers.
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
>>> multiply(2, 3)
|
|
64
|
+
6
|
|
65
|
+
|
|
66
|
+
>>> multiply(-1, 4)
|
|
67
|
+
-4
|
|
68
|
+
"""
|
|
69
|
+
return a * b
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def divide(a: float, b: float) -> float:
|
|
73
|
+
"""
|
|
74
|
+
Return the division of two numbers. Raise an error if dividing by zero.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
a: The numerator.
|
|
78
|
+
b: The denominator.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
The result of the division.
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
ValueError: If the denominator is zero.
|
|
85
|
+
|
|
86
|
+
Examples:
|
|
87
|
+
>>> divide(6, 3)
|
|
88
|
+
2.0
|
|
89
|
+
|
|
90
|
+
>>> divide(5, 2)
|
|
91
|
+
2.5
|
|
92
|
+
"""
|
|
93
|
+
if b == 0:
|
|
94
|
+
raise ValueError("Cannot divide by zero.")
|
|
95
|
+
return a / b
|