barz 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.
barz-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.3
2
+ Name: barz
3
+ Version: 0.1.0
4
+ Summary: Bar charts in the terminal
5
+ Author: Zeev Rotshtein
6
+ Author-email: Zeev Rotshtein <zeevro@gmail.com>
7
+ Requires-Python: >=3.10
8
+ Project-URL: Repository, https://github.com/zeevro/barz
9
+ Description-Content-Type: text/markdown
10
+
11
+ # barz
12
+
13
+ ## Installation
14
+ ```sh
15
+ uv tool install barz
16
+ ```
17
+ ```sh
18
+ pipx install barz
19
+ ```
20
+
21
+ ## Usage
22
+ ```console
23
+ $ barz --help
24
+ usage: barz [-h] [-s] [-r] [filename]
25
+
26
+ positional arguments:
27
+ filename
28
+
29
+ options:
30
+ -h, --help show this help message and exit
31
+ -s, --sort
32
+ -r, --reverse
33
+
34
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz
35
+ asdf 100 ██████████████████████████████
36
+ qwer 15 ████▌
37
+ zxcv 34 ██████████▎
38
+
39
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -r
40
+ zxcv 34 ██████████▎
41
+ qwer 15 ████▌
42
+ asdf 100 ██████████████████████████████
43
+
44
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -s
45
+ qwer 15 ████▌
46
+ zxcv 34 ██████████▎
47
+ asdf 100 ██████████████████████████████
48
+
49
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -sr
50
+ asdf 100 ██████████████████████████████
51
+ zxcv 34 ██████████▎
52
+ qwer 15 ████▌
53
+ ```
barz-0.1.0/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # barz
2
+
3
+ ## Installation
4
+ ```sh
5
+ uv tool install barz
6
+ ```
7
+ ```sh
8
+ pipx install barz
9
+ ```
10
+
11
+ ## Usage
12
+ ```console
13
+ $ barz --help
14
+ usage: barz [-h] [-s] [-r] [filename]
15
+
16
+ positional arguments:
17
+ filename
18
+
19
+ options:
20
+ -h, --help show this help message and exit
21
+ -s, --sort
22
+ -r, --reverse
23
+
24
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz
25
+ asdf 100 ██████████████████████████████
26
+ qwer 15 ████▌
27
+ zxcv 34 ██████████▎
28
+
29
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -r
30
+ zxcv 34 ██████████▎
31
+ qwer 15 ████▌
32
+ asdf 100 ██████████████████████████████
33
+
34
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -s
35
+ qwer 15 ████▌
36
+ zxcv 34 ██████████▎
37
+ asdf 100 ██████████████████████████████
38
+
39
+ $ python3 -c "print(*['asdf']*100, *['qwer']*15, *['zxcv']*34, sep='\n')" | uniq -c | barz -sr
40
+ asdf 100 ██████████████████████████████
41
+ zxcv 34 ██████████▎
42
+ qwer 15 ████▌
43
+ ```
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.7.10,<0.8"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "barz"
7
+ version = "0.1.0"
8
+ description = "Bar charts in the terminal"
9
+ readme = "README.md"
10
+ authors = [{ name = "Zeev Rotshtein", email = "zeevro@gmail.com" }]
11
+ requires-python = ">=3.10"
12
+
13
+ [project.scripts]
14
+ barz = "barz:main"
15
+
16
+ [project.urls]
17
+ Repository = "https://github.com/zeevro/barz"
18
+
19
+ [tool.ruff]
20
+ line-length = 150
21
+ output-format = "concise"
22
+
23
+ [tool.ruff.lint]
24
+ select = ["ALL"]
25
+ ignore = [
26
+ "W191", # tab-indentation - conflicts with formatter
27
+ "E111", # indentation-with-invalid-multiple - conflicts with formatter
28
+ "E114", # indentation-with-invalid-multiple-comment - conflicts with formatter
29
+ "E117", # over-indented - conflicts with formatter
30
+ "D206", # indent-with-spaces - conflicts with formatter
31
+ "D300", # triple-single-quotes - conflicts with formatter
32
+ "Q000", # bad-quotes-inline-string - conflicts with formatter
33
+ "Q001", # bad-quotes-multiline-string - conflicts with formatter
34
+ "Q002", # bad-quotes-docstring - conflicts with formatter
35
+ "Q003", # avoidable-escaped-quote - conflicts with formatter
36
+ "COM812", # missing-trailing-comma - conflicts with formatter
37
+ "COM819", # prohibited-trailing-comma - conflicts with formatter
38
+ "E501", # line-too-long - see formatter documentation
39
+
40
+ "C90", # linter: mccabe
41
+ "D", # linter: pydocstyle
42
+
43
+ "BLE001", # blind-except
44
+ "T201", # print
45
+ "SIM115", # open-file-with-context-handler
46
+ "PLR0904", # too-many-public-methods
47
+ "PLR0911", # too-many-return-statements
48
+ "PLR0912", # too-many-branches
49
+ "PLR0913", # too-many-arguments
50
+ "PLR0914", # too-many-locals
51
+ "PLR0915", # too-many-statements
52
+ "PLR0916", # too-many-boolean-expressions
53
+ "PLR0917", # too-many-positional-arguments
54
+ ]
55
+
56
+ [tool.ruff.lint.isort]
57
+ force-sort-within-sections = true
58
+ lines-after-imports = 2
59
+
60
+ [tool.ruff.format]
61
+ quote-style = "single"
62
+
63
+ [tool.mypy]
64
+ strict = true
65
+ files = ["src/"]
@@ -0,0 +1,47 @@
1
+ import argparse
2
+
3
+
4
+ W = 30
5
+ B = ['', *'▏▎▍▌▋▊▉█']
6
+ C = B[-1]
7
+
8
+
9
+ def main() -> None:
10
+ p = argparse.ArgumentParser()
11
+ p.add_argument('-s', '--sort', action='store_true')
12
+ p.add_argument('-r', '--reverse', action='store_true')
13
+ p.add_argument('file', metavar='filename', nargs='?', type=argparse.FileType(), default='-')
14
+ args = p.parse_args()
15
+
16
+ try:
17
+ data: list[tuple[int, str]] = []
18
+ d_len = 0
19
+ n_max = 0
20
+ n_len = 0
21
+ for line in args.file:
22
+ try:
23
+ ns, rest = line.split(None, 1)
24
+ data.append((n := int(ns, 0), rest.rstrip('\n')))
25
+ except ValueError:
26
+ continue
27
+ d_len = max(d_len, len(rest))
28
+ n_max = max(n_max, n)
29
+ n_len = max(n_len, len(ns))
30
+
31
+ k = n_max / W
32
+
33
+ if args.sort:
34
+ data = sorted(data)
35
+ if args.reverse:
36
+ data = data[::-1]
37
+
38
+ for n, line in data:
39
+ c = n / k
40
+ bar = f'{C * int(c)}{B[round((c % 1) * 8)]}'
41
+ print(f'{line:{d_len}} {n:{n_len}} {bar}')
42
+ except (BrokenPipeError, KeyboardInterrupt):
43
+ pass
44
+
45
+
46
+ if __name__ == '__main__':
47
+ main()
@@ -0,0 +1,5 @@
1
+ from . import main
2
+
3
+
4
+ if __name__ == '__main__':
5
+ main()
File without changes