nithilan 0.1.0__tar.gz
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.
- nithilan-0.1.0/PKG-INFO +34 -0
- nithilan-0.1.0/README.md +22 -0
- nithilan-0.1.0/pyproject.toml +24 -0
- nithilan-0.1.0/setup.cfg +4 -0
- nithilan-0.1.0/src/nithilan/__init__.py +4 -0
- nithilan-0.1.0/src/nithilan/core.py +51 -0
- nithilan-0.1.0/src/nithilan.egg-info/PKG-INFO +34 -0
- nithilan-0.1.0/src/nithilan.egg-info/SOURCES.txt +9 -0
- nithilan-0.1.0/src/nithilan.egg-info/dependency_links.txt +1 -0
- nithilan-0.1.0/src/nithilan.egg-info/top_level.txt +1 -0
- nithilan-0.1.0/tests/test_core.py +42 -0
nithilan-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nithilan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Small Python utilities for everyday programs
|
|
5
|
+
Author: Nithilan Vivek
|
|
6
|
+
Project-URL: Homepage, https://nithi.land
|
|
7
|
+
Keywords: utilities,factorial,terminal
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# nithilan
|
|
14
|
+
|
|
15
|
+
`nithilan` is a small collection of Python utilities for everyday programs.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -m pip install nithilan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from nithilan import ask, factorial
|
|
27
|
+
|
|
28
|
+
print(factorial(5))
|
|
29
|
+
|
|
30
|
+
if ask("Continue?"):
|
|
31
|
+
print("Continuing")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`factorial` supports non-negative integers and real values supported by the gamma function. `ask` reads a single `y` or `n` response from an interactive Windows, macOS, or Linux terminal.
|
nithilan-0.1.0/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# nithilan
|
|
2
|
+
|
|
3
|
+
`nithilan` is a small collection of Python utilities for everyday programs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install nithilan
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from nithilan import ask, factorial
|
|
15
|
+
|
|
16
|
+
print(factorial(5))
|
|
17
|
+
|
|
18
|
+
if ask("Continue?"):
|
|
19
|
+
print("Continuing")
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`factorial` supports non-negative integers and real values supported by the gamma function. `ask` reads a single `y` or `n` response from an interactive Windows, macOS, or Linux terminal.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nithilan"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Small Python utilities for everyday programs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Nithilan Vivek" }
|
|
13
|
+
]
|
|
14
|
+
keywords = ["utilities", "factorial", "terminal"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://nithi.land"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
nithilan-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import math
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def factorial(x: float) -> int | float:
|
|
7
|
+
if x < 0:
|
|
8
|
+
raise ValueError("factorial is not defined for negative numbers")
|
|
9
|
+
if x % 1 == 0:
|
|
10
|
+
count = int(x)
|
|
11
|
+
result = 1
|
|
12
|
+
while count > 0:
|
|
13
|
+
result *= count
|
|
14
|
+
count -= 1
|
|
15
|
+
return result
|
|
16
|
+
return math.gamma(x + 1)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def ask(prompt: str) -> bool | None:
|
|
20
|
+
print(prompt + " (y/n): ", end="", flush=True)
|
|
21
|
+
|
|
22
|
+
if sys.platform == "win32":
|
|
23
|
+
import msvcrt
|
|
24
|
+
|
|
25
|
+
char = msvcrt.getch().decode("utf-8", errors="ignore")
|
|
26
|
+
else:
|
|
27
|
+
import termios
|
|
28
|
+
import tty
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
file_descriptor = sys.stdin.fileno()
|
|
32
|
+
previous_settings = termios.tcgetattr(file_descriptor)
|
|
33
|
+
try:
|
|
34
|
+
tty.setraw(file_descriptor)
|
|
35
|
+
char = sys.stdin.read(1)
|
|
36
|
+
finally:
|
|
37
|
+
termios.tcsetattr(
|
|
38
|
+
file_descriptor,
|
|
39
|
+
termios.TCSADRAIN,
|
|
40
|
+
previous_settings,
|
|
41
|
+
)
|
|
42
|
+
except (io.UnsupportedOperation, OSError):
|
|
43
|
+
char = input()
|
|
44
|
+
|
|
45
|
+
char = char.lower()
|
|
46
|
+
if char == "y":
|
|
47
|
+
return True
|
|
48
|
+
if char == "n":
|
|
49
|
+
return False
|
|
50
|
+
print("Incorrect argument")
|
|
51
|
+
return None
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nithilan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Small Python utilities for everyday programs
|
|
5
|
+
Author: Nithilan Vivek
|
|
6
|
+
Project-URL: Homepage, https://nithi.land
|
|
7
|
+
Keywords: utilities,factorial,terminal
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# nithilan
|
|
14
|
+
|
|
15
|
+
`nithilan` is a small collection of Python utilities for everyday programs.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -m pip install nithilan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from nithilan import ask, factorial
|
|
27
|
+
|
|
28
|
+
print(factorial(5))
|
|
29
|
+
|
|
30
|
+
if ask("Continue?"):
|
|
31
|
+
print("Continuing")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`factorial` supports non-negative integers and real values supported by the gamma function. `ask` reads a single `y` or `n` response from an interactive Windows, macOS, or Linux terminal.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nithilan
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import math
|
|
3
|
+
import unittest
|
|
4
|
+
from unittest.mock import patch
|
|
5
|
+
|
|
6
|
+
from nithilan import ask, factorial
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FactorialTests(unittest.TestCase):
|
|
10
|
+
def test_integer(self):
|
|
11
|
+
self.assertEqual(factorial(5), 120)
|
|
12
|
+
|
|
13
|
+
def test_zero(self):
|
|
14
|
+
self.assertEqual(factorial(0), 1)
|
|
15
|
+
|
|
16
|
+
def test_fraction(self):
|
|
17
|
+
self.assertAlmostEqual(factorial(0.5), math.gamma(1.5))
|
|
18
|
+
|
|
19
|
+
def test_negative_number(self):
|
|
20
|
+
with self.assertRaisesRegex(ValueError, "negative numbers"):
|
|
21
|
+
factorial(-1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AskTests(unittest.TestCase):
|
|
25
|
+
def check_answer(self, answer, expected):
|
|
26
|
+
fake_input = io.StringIO(answer + "\n")
|
|
27
|
+
fake_output = io.StringIO()
|
|
28
|
+
with patch("sys.stdin", fake_input), patch("sys.stdout", fake_output):
|
|
29
|
+
self.assertIs(ask("Continue?"), expected)
|
|
30
|
+
|
|
31
|
+
def test_yes(self):
|
|
32
|
+
self.check_answer("y", True)
|
|
33
|
+
|
|
34
|
+
def test_no(self):
|
|
35
|
+
self.check_answer("n", False)
|
|
36
|
+
|
|
37
|
+
def test_invalid_answer(self):
|
|
38
|
+
self.check_answer("maybe", None)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
unittest.main()
|