binnev-python-template 7.0.2__py3-none-any.whl → 7.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: binnev-python-template
3
- Version: 7.0.2
3
+ Version: 7.0.4
4
4
  Summary: Add your description here
5
5
  Author-email: Robin Neville <robin.m.neville@gmail.com>
6
6
  License-Expression: MIT
@@ -0,0 +1,16 @@
1
+ src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ src/api/__init__.py,sha256=sMZ_Q3pHNHBOBkJ3_K3VIH4de_UvfBsUnxfNKLgPnnU,28
3
+ src/api/app.py,sha256=SQ3YPyBedIBhm801HRi6-dJQDN185DCt9j_h3_afc_o,188
4
+ src/api/calculator.py,sha256=a5sJRHbznv91ldM3LtjFJBqaJ0O6w0HqyQ1If5Y_r68,1664
5
+ src/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ src/cli/calculator.py,sha256=Zc2o1ACWA6qhneGWnh6Y8Jyn6W0ifZEruJrU5drteOw,2284
7
+ src/cli/greeter.py,sha256=mh9Bzwa6B_vRBi6xZcXvAONAAYWMcSXhOYVnhEOO5T4,1157
8
+ src/core/__init__.py,sha256=2UXwBQihnc3rEoHkoTMCmv1euxqvweZ9PkTu61MFtvQ,128
9
+ src/core/calculator.py,sha256=rYsUuuAbmRnkdDjmZBFlTgOmIAexF332ELzWVQPoQw0,1790
10
+ src/core/greeter.py,sha256=lsfF9KhkYCcBW42MabmZMotiwD8cnj15ApBMr7tZWqI,226
11
+ src/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ binnev_python_template-7.0.4.dist-info/METADATA,sha256=LN-tWHG-TP0gyfCcwzbGuWX3VDxPQGiqdxq86AycR_k,1522
13
+ binnev_python_template-7.0.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
14
+ binnev_python_template-7.0.4.dist-info/entry_points.txt,sha256=HKdmBrnYHfEJEmcrurGU7a3VXJ0_X9hp76jc4GhznXY,103
15
+ binnev_python_template-7.0.4.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
16
+ binnev_python_template-7.0.4.dist-info/RECORD,,
src/api/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .app import app as app
src/api/app.py ADDED
@@ -0,0 +1,11 @@
1
+ from fastapi import FastAPI
2
+
3
+ from .calculator import calculator_router
4
+
5
+ app = FastAPI()
6
+
7
+ app.include_router(calculator_router, prefix="/calculator")
8
+
9
+
10
+ if __name__ == "__main__":
11
+ app()
src/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))
src/cli/__init__.py ADDED
File without changes
src/cli/calculator.py ADDED
@@ -0,0 +1,98 @@
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
+ calculator_app = typer.Typer()
20
+
21
+
22
+ @calculator_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
+ @calculator_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
+ @calculator_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
+ @calculator_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
+ @calculator_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
95
+
96
+
97
+ if __name__ == "__main__":
98
+ calculator_app()
src/cli/greeter.py ADDED
@@ -0,0 +1,57 @@
1
+ """
2
+ This module provides CLI commands for greeting people.
3
+
4
+ The module relies on the `core.greeter` module for the actual greeting logic.
5
+ """
6
+
7
+ from typing import Annotated, Optional
8
+
9
+ import typer
10
+
11
+ from src import core
12
+ from src.core import greeter
13
+
14
+ greeter_app = typer.Typer()
15
+
16
+
17
+ @greeter_app.command()
18
+ def greet(
19
+ name: Annotated[
20
+ str,
21
+ typer.Argument(help="The name of the person to greet."),
22
+ ] = "",
23
+ ) -> None:
24
+ """
25
+ Greet someone.
26
+
27
+ Args:
28
+ name: The name of the person to greet. If name is omitted, the world
29
+ will be greeted.
30
+ """
31
+ greeting = greeter.greeting(name)
32
+ typer.echo(greeting)
33
+
34
+
35
+ def _version_callback(value: bool) -> None:
36
+ if value:
37
+ typer.echo(f"{core.__app_name__} v{core.__version__}")
38
+ raise typer.Exit()
39
+
40
+
41
+ @greeter_app.callback()
42
+ def main(
43
+ version: Optional[bool] = typer.Option(
44
+ None,
45
+ "--version",
46
+ "-v",
47
+ help="Show the application's version and exit.",
48
+ callback=_version_callback,
49
+ is_eager=True,
50
+ ),
51
+ ) -> None:
52
+ """Handles the --version flag"""
53
+ return
54
+
55
+
56
+ if __name__ == "__main__":
57
+ greeter_app()
src/core/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ __app_name__ = "python-template"
2
+ __version__ = "7.0.4"
3
+
4
+ from . import calculator as calculator
5
+ from . import greeter as greeter
src/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
src/core/greeter.py ADDED
@@ -0,0 +1,12 @@
1
+ def greeting(name: str = "") -> str:
2
+ """
3
+ Greet a person.
4
+
5
+ Args:
6
+ name: the name of the person to greet
7
+
8
+ Returns:
9
+ A greeting string
10
+ """
11
+ name = name or "world"
12
+ return f"Hello, {name}!"
src/core/py.typed ADDED
File without changes
@@ -1,6 +0,0 @@
1
- python_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- binnev_python_template-7.0.2.dist-info/METADATA,sha256=nJVZjv677UqvrJ_0x6S0POXWFCUilWmZpHQbAvgPDgQ,1522
3
- binnev_python_template-7.0.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
- binnev_python_template-7.0.2.dist-info/entry_points.txt,sha256=HKdmBrnYHfEJEmcrurGU7a3VXJ0_X9hp76jc4GhznXY,103
5
- binnev_python_template-7.0.2.dist-info/top_level.txt,sha256=bQLLBdRq2654KL-rN6TKe04B9u9abV0tTHt4ub1SVYY,16
6
- binnev_python_template-7.0.2.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- python_template
File without changes