jacobus 1.0.6__tar.gz → 2.0.0.dev1__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.
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/PKG-INFO +1 -1
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/pyproject.toml +1 -1
- jacobus-2.0.0.dev1/src/jacobus/core/__init__.py +99 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus.egg-info/PKG-INFO +1 -1
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus.egg-info/SOURCES.txt +0 -3
- jacobus-1.0.6/src/jacobus/_const/Const.py +0 -26
- jacobus-1.0.6/src/jacobus/_const/__init__.py +0 -0
- jacobus-1.0.6/src/jacobus/_const/const.toml +0 -5
- jacobus-1.0.6/src/jacobus/core/__init__.py +0 -98
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/LICENSE.txt +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/MANIFEST.in +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/README.rst +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/setup.cfg +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus/__init__.py +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus/__main__.py +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus/py.typed +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus/tests/__init__.py +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus/tests/test_jacobus_unittest.py +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus.egg-info/dependency_links.txt +0 -0
- {jacobus-1.0.6 → jacobus-2.0.0.dev1}/src/jacobus.egg-info/top_level.txt +0 -0
|
@@ -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
|
+
__all__ = ["main", "run"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def gcd(a: int, b: int) -> int:
|
|
14
|
+
while b:
|
|
15
|
+
a, b = b, a % b
|
|
16
|
+
return a
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def go(lines: list[str], *, indent: Optional[int]) -> list[str]:
|
|
20
|
+
diff: int
|
|
21
|
+
divisor: int
|
|
22
|
+
index: int
|
|
23
|
+
line: str
|
|
24
|
+
for index in range(len(lines)):
|
|
25
|
+
lines[index] = lines[index].rstrip() + "\n"
|
|
26
|
+
while len(lines) and lines[0] == "\n":
|
|
27
|
+
lines.pop(0)
|
|
28
|
+
while len(lines) and lines[-1] == "\n":
|
|
29
|
+
lines.pop()
|
|
30
|
+
continue
|
|
31
|
+
divisor = 0
|
|
32
|
+
if indent is None:
|
|
33
|
+
return lines
|
|
34
|
+
for line in lines:
|
|
35
|
+
diff = len(line) - len(line.lstrip(" "))
|
|
36
|
+
divisor = gcd(divisor, diff)
|
|
37
|
+
for index in range(len(lines) * bool(divisor)):
|
|
38
|
+
diff = len(lines[index]) - len(lines[index].lstrip(" "))
|
|
39
|
+
diff //= divisor
|
|
40
|
+
diff *= indent
|
|
41
|
+
lines[index] = (" " * diff) + lines[index].lstrip(" ")
|
|
42
|
+
return lines
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main(args: typing.Optional[list[str]] = None, /) -> None:
|
|
46
|
+
parser: argparse.ArgumentParser
|
|
47
|
+
space: argparse.Namespace
|
|
48
|
+
parser = argparse.ArgumentParser(
|
|
49
|
+
description="This project normalizes whitespace.",
|
|
50
|
+
fromfile_prefix_chars="@",
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"-V",
|
|
54
|
+
"--version",
|
|
55
|
+
action="version",
|
|
56
|
+
dest="version",
|
|
57
|
+
version=metadata.version("jacobus"),
|
|
58
|
+
)
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
"--indent",
|
|
61
|
+
help="This option alters the indentation.",
|
|
62
|
+
type=int,
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"filepatterns",
|
|
66
|
+
default=[],
|
|
67
|
+
help="These arguments give the patterns of the file.",
|
|
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()
|
|
@@ -10,9 +10,6 @@ src/jacobus.egg-info/PKG-INFO
|
|
|
10
10
|
src/jacobus.egg-info/SOURCES.txt
|
|
11
11
|
src/jacobus.egg-info/dependency_links.txt
|
|
12
12
|
src/jacobus.egg-info/top_level.txt
|
|
13
|
-
src/jacobus/_const/Const.py
|
|
14
|
-
src/jacobus/_const/__init__.py
|
|
15
|
-
src/jacobus/_const/const.toml
|
|
16
13
|
src/jacobus/core/__init__.py
|
|
17
14
|
src/jacobus/tests/__init__.py
|
|
18
15
|
src/jacobus/tests/test_jacobus_unittest.py
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import enum
|
|
2
|
-
import functools
|
|
3
|
-
import tomllib
|
|
4
|
-
from importlib import resources
|
|
5
|
-
from typing import Any, Self
|
|
6
|
-
|
|
7
|
-
__all__ = ["Const"]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Const(enum.StrEnum):
|
|
11
|
-
const = "jacobus.const/const.toml"
|
|
12
|
-
|
|
13
|
-
@functools.cached_property
|
|
14
|
-
def data(self: Self) -> dict[str, Any]:
|
|
15
|
-
text: str
|
|
16
|
-
text = resources.read_text(*self.value.split("/"))
|
|
17
|
-
return tomllib.loads(text)
|
|
18
|
-
|
|
19
|
-
@functools.cached_property
|
|
20
|
-
def varia(self: Self) -> dict[str, Any]:
|
|
21
|
-
ans: Any
|
|
22
|
-
ans = self.data.get("varia")
|
|
23
|
-
if isinstance(ans, dict):
|
|
24
|
-
return ans
|
|
25
|
-
else:
|
|
26
|
-
return dict()
|
|
File without changes
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|