Skip to content

Commit c9d784d

Browse files
committed
Merge branch 'release/0.0.8'
2 parents 991cc5d + 3e3382e commit c9d784d

53 files changed

Lines changed: 17588 additions & 16245 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/images/octocat.svg

Lines changed: 42 additions & 42 deletions
Loading

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
fail_fast: true
22
repos:
33
- repo: https://github.com/ambv/black
4-
rev: 22.6.0
4+
rev: 23.3.0
55
hooks:
66
- id: black
7-
language_version: python3.8
7+
language_version: python3.10
88
- repo: local
99
hooks:
1010
- id: pytest-check

devpack/__init__.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import datetime
44
import os
55
from warnings import warn
6-
7-
import pkg_resources
8-
6+
from importlib.metadata import PackageNotFoundError
7+
from importlib import resources
98
from apppath import AppPath
109

1110
__project__ = "devpack"
1211
__author__ = "Christian Heider Nielsen"
13-
__version__ = "0.0.7"
12+
__version__ = "0.0.8"
1413
__doc__ = """
1514
Created on 15/04/2020
1615
@@ -31,32 +30,20 @@
3130
# "PACKAGE_DATA_PATH"
3231
]
3332

34-
35-
def dist_is_editable(dist: Any) -> bool:
36-
"""
37-
Return True if given Distribution is an editable installation."""
38-
import sys
39-
from pathlib import Path
40-
41-
for path_item in sys.path:
42-
egg_link = Path(path_item) / f"{dist.project_name}.egg-link"
43-
if egg_link.is_file():
44-
return True
45-
return False
46-
47-
4833
PROJECT_NAME = __project__.lower().strip().replace(" ", "_")
4934
PROJECT_VERSION = __version__
5035
PROJECT_YEAR = 2018
5136
PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_")
5237
PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR)
5338
PROJECT_ORGANISATION = "pything"
5439

55-
distributions = {v.key: v for v in pkg_resources.working_set}
56-
if PROJECT_NAME in distributions:
57-
distribution = distributions[PROJECT_NAME]
58-
DEVELOP = dist_is_editable(distribution)
59-
else:
40+
from warg import package_is_editable
41+
42+
PACKAGE_DATA_PATH = resources.files(PROJECT_NAME) / "data"
43+
44+
try:
45+
DEVELOP = package_is_editable(PROJECT_NAME)
46+
except PackageNotFoundError as e:
6047
DEVELOP = True
6148

6249

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/aliases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515
from typing import Iterable, Callable, Optional, Sequence, Mapping, List
1616

17-
from warg.os_utilities.filtering import negate, is_python_module, is_python_package
17+
from warg.os_utilities.filtering import negate, is_python_package
1818

1919

2020
def has_import_aliases(path: Path, *, verbose: bool = False) -> bool:

devpack/batch_tools/alls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ def check_alls(path: Path, *, verbose: bool = True) -> None:
245245
print("WARNING library file with empty __all__ declaration")
246246

247247

248+
def has_multiple_alls() -> bool:
249+
...
250+
251+
248252
def recursive_check_alls(
249253
path: Path,
250254
exclusion_filter: Optional[Iterable[Callable]] = (negate(is_python_package),),
@@ -270,7 +274,6 @@ def recursive_check_alls(
270274
if exclusion_filter is None or not any(
271275
flt(child) for flt in exclusion_filter
272276
):
273-
274277
recursive_check_alls(
275278
child,
276279
exclusion_filter,

devpack/batch_tools/privates.py

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

1717
from draugr.os_utilities.linux_utilities.user_utilities import get_username
18+
1819
from warg.os_utilities.filtering import is_python_module, negate
1920

2021

devpack/batch_tools/readmes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Callable, Iterable, Optional
1515

1616
from sorcery import assigned_names
17+
1718
from warg.os_utilities.filtering import negate, is_python_package
1819

1920

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: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import argparse
1313
from pathlib import Path
1414

15-
from devpack.batch_tools.readmes import TouchModeEnum, recursive_add_readmes
1615
from devpack.batch_tools.inits import recursive_remove_inits
16+
from devpack.batch_tools.readmes import TouchModeEnum, recursive_add_readmes
1717

1818

1919
def recursively_add_readmes_from_here():
@@ -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()

0 commit comments

Comments
 (0)