jacobus 1.0.6__tar.gz → 2.0.0.dev0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jacobus
3
- Version: 1.0.6
3
+ Version: 2.0.0.dev0
4
4
  Summary: This project normalizes whitespace.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ license-files = [
28
28
  name = "jacobus"
29
29
  readme = "README.rst"
30
30
  requires-python = ">=3.11"
31
- version = "1.0.6"
31
+ version = "2.0.0.dev0"
32
32
 
33
33
  [project.urls]
34
34
  Download = "https://pypi.org/project/jacobus/#files"
@@ -0,0 +1,99 @@
1
+ import argparse
2
+ import glob
3
+ import io
4
+ import os
5
+ import typing
6
+ from collections.abc import Iterable
7
+ from importlib import metadata
8
+ from typing import Optional
9
+
10
+ from jacobus._const.Const import Const
11
+
12
+ __all__ = ["main", "run"]
13
+
14
+
15
+ def gcd(a: int, b: int) -> int:
16
+ while b:
17
+ a, b = b, a % b
18
+ return a
19
+
20
+
21
+ def go(lines: list[str], *, indent: Optional[int]) -> list[str]:
22
+ diff: int
23
+ divisor: int
24
+ index: int
25
+ line: str
26
+ for index in range(len(lines)):
27
+ lines[index] = lines[index].rstrip() + "\n"
28
+ while len(lines) and lines[0] == "\n":
29
+ lines.pop(0)
30
+ while len(lines) and lines[-1] == "\n":
31
+ lines.pop()
32
+ continue
33
+ divisor = 0
34
+ if indent is None:
35
+ return lines
36
+ for line in lines:
37
+ diff = len(line) - len(line.lstrip(" "))
38
+ divisor = gcd(divisor, diff)
39
+ for index in range(len(lines) * bool(divisor)):
40
+ diff = len(lines[index]) - len(lines[index].lstrip(" "))
41
+ diff //= divisor
42
+ diff *= indent
43
+ lines[index] = (" " * diff) + lines[index].lstrip(" ")
44
+ return lines
45
+
46
+
47
+ def main(args: typing.Optional[list[str]] = None, /) -> None:
48
+ parser: argparse.ArgumentParser
49
+ space: argparse.Namespace
50
+ parser = argparse.ArgumentParser(
51
+ description=Const.const.varia.get("description"),
52
+ fromfile_prefix_chars="@",
53
+ )
54
+ parser.add_argument(
55
+ "-V",
56
+ "--version",
57
+ action="version",
58
+ dest="version",
59
+ version=metadata.version("jacobus"),
60
+ )
61
+ parser.add_argument(
62
+ "--indent",
63
+ type=int,
64
+ )
65
+ parser.add_argument(
66
+ "filepatterns",
67
+ default=[],
68
+ nargs="*",
69
+ )
70
+ space = parser.parse_args(args)
71
+ run(**vars(space))
72
+
73
+
74
+ def run(
75
+ filepatterns: Iterable[str] = (),
76
+ *,
77
+ indent: Optional[int] = None,
78
+ ) -> None:
79
+ absfile: str
80
+ absfiles: list[str]
81
+ lines: list[str]
82
+ pattern: str
83
+ stream: io.TextIOWrapper
84
+ absfiles = list()
85
+ for pattern in filepatterns:
86
+ for absfile in map(os.path.abspath, glob.glob(pattern)):
87
+ if absfile in absfiles:
88
+ continue
89
+ absfiles.append(absfile)
90
+ for absfile in absfiles:
91
+ with open(file=absfile, mode="r") as stream:
92
+ lines = stream.readlines()
93
+ lines = go(lines, indent=indent)
94
+ with open(file=absfile, mode="w") as stream:
95
+ stream.writelines(lines)
96
+
97
+
98
+ if __name__ == "__main__":
99
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jacobus
3
- Version: 1.0.6
3
+ Version: 2.0.0.dev0
4
4
  Summary: This project normalizes whitespace.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -1,98 +0,0 @@
1
- import argparse
2
- import io
3
- import pathlib
4
- import typing
5
- from collections.abc import Iterable
6
- from importlib import metadata
7
- from typing import Optional
8
-
9
- from jacobus._const.Const import Const
10
-
11
- __all__ = ["main", "run"]
12
-
13
-
14
- def main(args: typing.Optional[list[str]] = None, /) -> None:
15
- parser: argparse.ArgumentParser
16
- space: argparse.Namespace
17
- parser = argparse.ArgumentParser(
18
- description=Const.const.varia.get("description"),
19
- formatter_class=argparse.RawTextHelpFormatter,
20
- fromfile_prefix_chars="@",
21
- )
22
- parser.add_argument(
23
- "-V",
24
- "--version",
25
- action="version",
26
- dest="version",
27
- version=metadata.version("jacobus"),
28
- )
29
- parser.add_argument(
30
- "--file",
31
- action="append",
32
- default=[],
33
- dest="files",
34
- )
35
- parser.add_argument(
36
- "--indent",
37
- type=int,
38
- )
39
- parser.add_argument(
40
- "root",
41
- )
42
- space = parser.parse_args(args)
43
- # kwargs = vars(space)
44
- run(
45
- space.root,
46
- files=space.files,
47
- indent=space.indent,
48
- )
49
-
50
-
51
- def run(
52
- root: str,
53
- /,
54
- *,
55
- files: Iterable[str] = (),
56
- indent: Optional[int] = None,
57
- ) -> None:
58
- diff: int
59
- divisor: int
60
- index: int
61
- line: str
62
- lines: list[str]
63
- path: pathlib.Path
64
- paths: list[pathlib.Path]
65
- stream: io.TextIOWrapper
66
- paths = list()
67
- for file in files:
68
- for path in pathlib.Path(root).glob(file):
69
- if path.is_file() and path not in paths:
70
- paths.append(path)
71
- for path in paths:
72
- with open(file=path, mode="r") as stream:
73
- lines = stream.readlines()
74
- for index in range(len(lines)):
75
- lines[index] = lines[index].rstrip() + "\n"
76
- while len(lines) and lines[0] == "\n":
77
- lines.pop(0)
78
- while len(lines) and lines[-1] == "\n":
79
- lines.pop()
80
- continue
81
- divisor = 0
82
- if indent is not None:
83
- for line in lines:
84
- diff = len(line) - len(line.lstrip(" "))
85
- divisor = gcd(divisor, diff)
86
- for index in range(len(lines) * bool(divisor)):
87
- diff = len(lines[index]) - len(lines[index].lstrip(" "))
88
- diff //= divisor
89
- diff *= indent
90
- lines[index] = (" " * diff) + lines[index].lstrip(" ")
91
- with open(file=path, mode="w") as stream:
92
- stream.writelines(lines)
93
-
94
-
95
- def gcd(a: int, b: int) -> int:
96
- while b:
97
- a, b = b, a % b
98
- return a
File without changes
File without changes
File without changes
File without changes