Skip to content

Commit 228063a

Browse files
committed
version bumping
1 parent ff501df commit 228063a

8 files changed

Lines changed: 201 additions & 29 deletions

File tree

devpack/batch_tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
# from .shebangs import *
1919
# from .entry_points import *
2020
# from .authors import *
21+
# from .typing_hints import *

devpack/batch_tools/privates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from typing import Optional, Callable, Iterable
1616

1717
from draugr.os_utilities.linux_utilities.user_utilities import get_username
18-
1918
from warg.os_utilities.filtering import is_python_module, negate
2019

2120

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "heider"
5+
__doc__ = r"""
6+
7+
Created on 9/6/22
8+
"""
9+
10+
__all__ = ["is_missing_typing_hints"]
11+
12+
import subprocess
13+
from pathlib import Path
14+
from typing import Optional, Iterable, Callable, Sequence
15+
16+
17+
def is_missing_typing_hints(
18+
path: Path,
19+
*,
20+
verbose: bool = True,
21+
flags: Optional[Sequence] = (
22+
"--disallow-untyped-calls ",
23+
"--disallow-untyped-defs ",
24+
"--disallow-incomplete-defs ",
25+
"--strict-optional",
26+
"--strict",
27+
),
28+
) -> bool:
29+
"""
30+
31+
:param verbose:
32+
:type verbose:
33+
:param path:
34+
:type path:
35+
:return:
36+
:rtype:
37+
"""
38+
a = subprocess.getoutput(f'mypy {" ".join(flags)} {str(path)}')
39+
if verbose:
40+
print(a)
41+
if "Success:" not in a:
42+
return True
43+
return False
44+
45+
46+
def is_missing_typing_hints_traverse(
47+
path: Path,
48+
exclusion_filter: Optional[Iterable[Callable]] = None,
49+
*,
50+
verbose: bool = True,
51+
):
52+
"""
53+
54+
:param path:
55+
:type path:
56+
:param exclusion_filter:
57+
:type exclusion_filter:
58+
:param init_name:
59+
:type init_name:
60+
:param verbose:
61+
:type verbose:
62+
"""
63+
path = Path(path)
64+
65+
for child in path.iterdir():
66+
if child.is_dir():
67+
if exclusion_filter is None or not any(
68+
flt(child) for flt in exclusion_filter
69+
):
70+
is_missing_typing_hints_traverse(
71+
child, exclusion_filter=exclusion_filter, verbose=verbose
72+
)
73+
else:
74+
if verbose:
75+
print(
76+
f"{child} was excluded, filters:\n{[(flt.__name__, flt(child)) for flt in exclusion_filter]}"
77+
)
78+
elif child.is_file():
79+
if is_missing_typing_hints(
80+
child,
81+
verbose=verbose,
82+
):
83+
break
84+
85+
86+
if __name__ == "__main__":
87+
print(is_missing_typing_hints(Path(__file__).parent))

devpack/entry_points/batch.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ def recursively_remove_inits_from_here():
7171
)
7272

7373

74+
def recursively_check_typing():
75+
"""
76+
Add readmes to all python modules in the current directory
77+
"""
78+
parser = argparse.ArgumentParser(description="DevPack remove inits from here")
79+
parser.add_argument(
80+
"--path", "-p", type=Path, default=Path.cwd(), help="Path to remove inits from"
81+
)
82+
parser.add_argument(
83+
"--verbose", action="store_true", help="Verbose output of removed files"
84+
)
85+
args = parser.parse_args()
86+
87+
recursive_remove_inits(
88+
args.path,
89+
init_name=args.init_name,
90+
verbose=args.verbose,
91+
)
92+
93+
7494
if __name__ == "__main__":
75-
recursively_add_readmes_from_here()
76-
recursively_remove_inits_from_here()
95+
# recursively_add_readmes_from_here()
96+
# recursively_remove_inits_from_here()
97+
recursively_check_typing()

devpack/entry_points/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def install_develop():
15-
"""description"""
15+
"""For programmatically installing a package as a development install"""
1616
parser = argparse.ArgumentParser(description="DevPack Develop Installation")
1717
parser.add_argument(
1818
"PACKAGE_NAME", metavar="Name", type=str, help="Package name to install"
@@ -33,7 +33,7 @@ def install_develop():
3333

3434

3535
def uninstall():
36-
"""description"""
36+
"""For programmatically uninstalling a package"""
3737
parser = argparse.ArgumentParser(description="DevPack Uninstall")
3838
parser.add_argument(
3939
"PACKAGE_NAME", metavar="Name", type=str, help="Package name to uninstall"

devpack/entry_points/versioning.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import argparse
22
from pathlib import Path
3-
from devpack.batch_tools.readmes import recursive_add_readmes
3+
4+
from devpack.versioning_tools.bump import version_bump
45

56

67
def bump():
7-
def recursively_add_readmes_from_here():
8-
"""
9-
Add readmes to all python modules in the current directory
10-
"""
11-
parser = argparse.ArgumentParser(description="DevPack add readmes from here")
12-
parser.add_argument(
13-
"--path", "-p", type=Path, default=Path.cwd(), help="Path to add readmes to"
14-
)
15-
parser.add_argument(
16-
"--verbose", action="store_true", help="Verbose output of touched files"
17-
)
18-
args = parser.parse_args()
8+
"""
9+
bumps python module python version in the current directory
10+
"""
11+
parser = argparse.ArgumentParser(description="DevPack bump version of this module")
12+
parser.add_argument(
13+
"--path", "-p", type=Path, default=Path.cwd(), help="Path to python module"
14+
)
15+
parser.add_argument("--verbose", action="store_true", help="Verbose output of bump")
16+
args = parser.parse_args()
1917

20-
recursive_add_readmes(
21-
args.path,
22-
touch_mode=args.touch_mode,
23-
readme_name=args.readme_name,
24-
verbose=args.verbose,
25-
)
18+
# TODO: #version_bump( args.path, touch_mode=args.touch_mode, readme_name=args.readme_name, verbose=args.verbose, )

devpack/versioning_tools/bump.py

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,77 @@
11
from pathlib import Path
2+
from sorcery import assigned_names
3+
from enum import Enum
24

35

4-
def bump_version_import(module_name: str, package: str = None) -> str:
6+
class BumpOrderEnum(Enum):
7+
major, minor, patch = assigned_names()
8+
micro = patch
9+
epoch = major
10+
11+
12+
def bump_version_import(
13+
module_name: str, package: str = None, order: BumpOrderEnum = BumpOrderEnum.patch
14+
) -> str:
515
import importlib
616

717
module = importlib.import_module(module_name, package)
818

919
version = module.__version__
1020

11-
base, _, minor = version.rpartition(".")
12-
return base + "." + str(int(minor) + 1)
21+
return version_bump(version)
22+
23+
24+
def version_partition(version: str) -> str:
25+
dot_count = version.count(".")
26+
27+
if dot_count == 1:
28+
major, minor = version.split(".")
29+
return int(major), int(minor)
30+
31+
elif dot_count >= 2:
32+
major, minor, patch, *rest = version.split(".")
33+
34+
return int(major), int(minor), int(patch), *rest
35+
36+
return (version,)
37+
38+
39+
def version_bump(version: str, order: BumpOrderEnum = BumpOrderEnum.patch) -> str:
40+
partitioned = version_partition(version)
41+
42+
if len(partitioned) == 1:
43+
return str(int(partitioned[0]) + 1)
44+
45+
pre = post = ""
46+
47+
if order == BumpOrderEnum.major:
48+
ordered, *post = partitioned
49+
post = ".".join([str(p) for p in post])
50+
51+
elif order == BumpOrderEnum.minor:
52+
if len(partitioned) == 2:
53+
pre, ordered = partitioned
54+
else:
55+
pre, ordered, *post = partitioned
56+
post = ".".join([str(p) for p in post])
57+
pre = str(pre)
58+
59+
elif order == BumpOrderEnum.patch:
60+
if len(partitioned) == 2:
61+
pre, ordered = partitioned
62+
else:
63+
major, minor, ordered, *post = partitioned
64+
pre = ".".join((str(major), str(minor)))
65+
post = ".".join([str(p) for p in post])
66+
pre = str(pre)
67+
68+
if pre != "":
69+
pre = str(pre) + "."
70+
71+
if post != "":
72+
post = "." + str(post)
73+
74+
return pre + str(int(ordered) + 1) + post
1375

1476

1577
def bump_version_regex(file_path: Path, search_regex_str: str) -> str:
@@ -38,3 +100,13 @@ def bump_version_input() -> str:
38100

39101
if __name__ == "__main__":
40102
print(bump_version_import("warg"))
103+
104+
def ujhasduhau():
105+
for e in BumpOrderEnum:
106+
print("__")
107+
print(version_bump("1", order=e))
108+
print(version_bump("1.2", order=e))
109+
print(version_bump("1.2.3", order=e))
110+
print(version_bump("1.2.3.4", order=e))
111+
112+
ujhasduhau()

samples/imports.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import draugr
2-
31
import apppath
2+
import draugr
43
import warg
54

65
print(warg.__version__)

0 commit comments

Comments
 (0)