np4 1.0.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.
- np4-1.0.0/.gitignore +1 -0
- np4-1.0.0/PKG-INFO +5 -0
- np4-1.0.0/README.md +0 -0
- np4-1.0.0/pyproject.toml +19 -0
- np4-1.0.0/src/NP4.py +1 -0
- np4-1.0.0/src/np4/__init__.py +74 -0
- np4-1.0.0/src/np4/data/u1.txt +794 -0
- np4-1.0.0/src/np4/data/u2.txt +1541 -0
- np4-1.0.0/src/np4/data/u3.txt +1200 -0
- np4-1.0.0/src/np4/data/u4.txt +1137 -0
- np4-1.0.0/src/np4/data/u5.txt +1270 -0
np4-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
np4-1.0.0/PKG-INFO
ADDED
np4-1.0.0/README.md
ADDED
|
File without changes
|
np4-1.0.0/pyproject.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "np4"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
requires-python = ">=3.9"
|
|
9
|
+
authors = [{name = "Kanishk Thakar"}]
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[project.scripts]
|
|
13
|
+
np4 = "np4:main"
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build.targets.wheel]
|
|
16
|
+
packages = ["src/np4"]
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
19
|
+
"src/NP4.py" = "NP4.py"
|
np4-1.0.0/src/NP4.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from np4 import * # noqa
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""np4: IMAP Practice Questions, every question with an in-depth solution.
|
|
2
|
+
|
|
3
|
+
show(), show(unit), q(unit, n), list(), find(text).
|
|
4
|
+
"""
|
|
5
|
+
import re
|
|
6
|
+
import sys
|
|
7
|
+
import pydoc
|
|
8
|
+
from importlib.resources import files
|
|
9
|
+
|
|
10
|
+
__version__ = "1.0.0"
|
|
11
|
+
__all__ = ["show", "q", "list", "find", "show1"]
|
|
12
|
+
_SEP = "=" * 78 + "\n>>> UNIT "
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _unit_text(u):
|
|
16
|
+
return files("np4").joinpath(f"data/u{int(u)}.txt").read_text(encoding="utf-8")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _blocks(u):
|
|
20
|
+
t = _unit_text(u)
|
|
21
|
+
parts = t.split("\n" + _SEP)
|
|
22
|
+
return [_SEP + p for p in parts[1:]]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _out(text, pager=False, return_text=False):
|
|
26
|
+
if return_text:
|
|
27
|
+
return text
|
|
28
|
+
if pager and sys.stdout.isatty():
|
|
29
|
+
pydoc.pager(text)
|
|
30
|
+
return None
|
|
31
|
+
try:
|
|
32
|
+
print(text)
|
|
33
|
+
except UnicodeEncodeError:
|
|
34
|
+
print(text.encode("ascii", "replace").decode())
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def show(unit=None, *, pager=False, return_text=False):
|
|
38
|
+
"""Every practice question with its in-depth solution. show(2) = Unit 2 only."""
|
|
39
|
+
units = [int(unit)] if unit is not None else [1, 2, 3, 4, 5]
|
|
40
|
+
return _out("\n\n".join(_unit_text(u) for u in units), pager, return_text)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
show1 = show
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def q(unit, number, *, return_text=False):
|
|
47
|
+
"""One question: q(3, 20) = Unit 3, Practice Q20."""
|
|
48
|
+
pat = re.compile(rf">>> UNIT {int(unit)} - PRACTICE Q{int(number)}\b")
|
|
49
|
+
hit = [b for b in _blocks(unit) if pat.search(b)]
|
|
50
|
+
return _out("\n\n".join(hit) or f"Unit {unit} Q{number} not found. Try np4.list({unit}).",
|
|
51
|
+
return_text=return_text)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def list(unit=None, *, return_text=False): # noqa: A001
|
|
55
|
+
"""Headings of every question."""
|
|
56
|
+
units = [int(unit)] if unit is not None else [1, 2, 3, 4, 5]
|
|
57
|
+
heads = [line for u in units for line in _unit_text(u).splitlines() if line.startswith(">>> UNIT")]
|
|
58
|
+
return _out("\n".join(heads), return_text=return_text)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def find(text, *, return_text=False):
|
|
62
|
+
"""Every question whose question or answer contains text (case-insensitive)."""
|
|
63
|
+
hits = [b for u in range(1, 6) for b in _blocks(u) if text.casefold() in b.casefold()]
|
|
64
|
+
return _out("\n\n".join(hits) or "No match.", return_text=return_text)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def main():
|
|
68
|
+
a = sys.argv[1:]
|
|
69
|
+
if len(a) >= 2:
|
|
70
|
+
q(a[0], a[1])
|
|
71
|
+
elif a:
|
|
72
|
+
show(a[0], pager=True)
|
|
73
|
+
else:
|
|
74
|
+
show(pager=True)
|