Skip to content

Commit 692ca4b

Browse files
committed
Merge branch 'release/0.0.6'
2 parents ff13aec + bc318a1 commit 692ca4b

8 files changed

Lines changed: 196 additions & 87 deletions

File tree

.github/workflows/publish-to-test-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on: push
99
jobs:
1010
build-n-publish:
1111
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
12-
runs-on: ubuntu-18.04
12+
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@master
1515
- name: Set up Python 3.8

devpack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
__project__ = "devpack"
1212
__author__ = "Christian Heider Nielsen"
13-
__version__ = "0.0.5"
13+
__version__ = "0.0.6"
1414
__doc__ = """
1515
Created on 15/04/2020
1616

devpack/batch_tools/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "heider"
5+
__doc__ = r"""
6+
7+
Created on 8/30/22
8+
"""
9+
10+
__all__ = []

devpack/batch_tools/inits.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "heider"
5+
__doc__ = r"""
6+
7+
Created on 8/30/22
8+
"""
9+
10+
__all__ = []
11+
12+
from pathlib import Path
13+
from typing import Callable, Iterable, Optional
14+
15+
from warg.os.filtering import negate, is_python_package
16+
17+
18+
def recursive_remove_inits(
19+
path: Path,
20+
exclusion_filter: Optional[Iterable[Callable]] = (negate(is_python_package),),
21+
*,
22+
init_name: str = "__init__.py",
23+
verbose: bool = True,
24+
):
25+
path = Path(path)
26+
27+
init_file = path / init_name
28+
if init_file.exists():
29+
init_file.unlink()
30+
31+
for child in path.iterdir():
32+
if child.is_dir():
33+
if exclusion_filter is None or not any(
34+
flt(child) for flt in exclusion_filter
35+
):
36+
recursive_remove_inits(
37+
child,
38+
exclusion_filter,
39+
init_name=init_name,
40+
verbose=verbose,
41+
)
42+
else:
43+
if verbose:
44+
print(
45+
f"{child} was excluded, filters:\n{[(flt.__name__, flt(child)) for flt in exclusion_filter]}"
46+
)
47+
elif child.is_file():
48+
pass
49+
50+
51+
if __name__ == "__main__":
52+
recursive_remove_inits("../exclude/samples")
Lines changed: 28 additions & 27 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+
from warg.os.filtering import negate, is_python_package
1718

1819

1920
class TouchModeEnum(Enum):
@@ -32,10 +33,13 @@ def auto_add_readme(
3233
readme_name: str = "README.md",
3334
root_path: Optional[Path] = Path.cwd(),
3435
prefix="# ",
36+
verbose: bool = True,
3537
) -> None:
3638
"""
3739
Add a readme to the root_path if it does not exist
3840
41+
:param verbose:
42+
:type verbose:
3943
:param path:
4044
:param touch_mode:
4145
:param readme_name:
@@ -48,6 +52,8 @@ def auto_add_readme(
4852
readme_file = path / readme_name
4953
if not readme_file.exists():
5054
readme_file.touch()
55+
if verbose:
56+
print(f"Created {readme_file}")
5157
if touch_mode == TouchModeEnum.breadcrumb:
5258
assert root_path is not None
5359
readme_file.write_text(prefix + str(path.relative_to(root_path)))
@@ -57,27 +63,9 @@ def auto_add_readme(
5763
readme_file.write_text(prefix + str(readme_file.parent.name))
5864
else:
5965
raise ValueError(f"Unknown touch mode {touch_mode}")
60-
61-
62-
def is_python_module(path: Path) -> bool:
63-
"""
64-
Check if path is a python module
65-
"""
66-
return path.is_file() and path.suffix == ".py"
67-
68-
69-
def is_python_package(path: Path) -> bool:
70-
"""
71-
Check if path is a python package
72-
"""
73-
return path.is_dir() and (path / "__init__.py").exists()
74-
75-
76-
def negate(f: Callable) -> Callable:
77-
"""
78-
Negate a function
79-
"""
80-
return lambda *args, **kwargs: not f(*args, **kwargs)
66+
else:
67+
if verbose:
68+
print(f"{readme_name} already exists at {path}")
8169

8270

8371
def recursive_add_readmes(
@@ -87,6 +75,7 @@ def recursive_add_readmes(
8775
touch_mode: TouchModeEnum = TouchModeEnum.breadcrumb,
8876
readme_name: str = "README.md",
8977
root_path: Optional[Path] = None,
78+
verbose: bool = True,
9079
) -> None:
9180
"""
9281
recursively add readmes to all children spanning from root_path
@@ -97,22 +86,34 @@ def recursive_add_readmes(
9786
root_path = path.parent
9887

9988
auto_add_readme(
100-
path, touch_mode=touch_mode, readme_name=readme_name, root_path=root_path
89+
path,
90+
touch_mode=touch_mode,
91+
readme_name=readme_name,
92+
root_path=root_path,
93+
verbose=verbose,
10194
)
10295

10396
for child in path.iterdir():
104-
if exclusion_filter is None or not any(flt(child) for flt in exclusion_filter):
105-
if child.is_dir():
97+
if child.is_dir():
98+
if exclusion_filter is None or not any(
99+
flt(child) for flt in exclusion_filter
100+
):
106101
recursive_add_readmes(
107102
child,
108103
exclusion_filter,
109104
touch_mode=touch_mode,
110105
readme_name=readme_name,
111106
root_path=root_path,
107+
verbose=verbose,
112108
)
113-
elif child.is_file():
114-
pass
109+
else:
110+
if verbose:
111+
print(
112+
f"{child} was excluded, filters:\n{[(flt.__name__, flt(child)) for flt in exclusion_filter]}"
113+
)
114+
elif child.is_file():
115+
pass
115116

116117

117118
if __name__ == "__main__":
118-
recursive_add_readmes("exclude")
119+
recursive_add_readmes("../exclude")

devpack/entry_points/batch.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import argparse
1313
from pathlib import Path
1414

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

1718

1819
def recursively_add_readmes_from_here():
@@ -33,12 +34,43 @@ def recursively_add_readmes_from_here():
3334
parser.add_argument(
3435
"--readme-name", "-r", type=str, default="README.md", help="Readme name"
3536
)
37+
parser.add_argument(
38+
"--verbose", action="store_true", help="Verbose output of touched files"
39+
)
3640
args = parser.parse_args()
3741

3842
recursive_add_readmes(
39-
args.path, touch_mode=args.touch_mode, readme_name=args.readme_name
43+
args.path,
44+
touch_mode=args.touch_mode,
45+
readme_name=args.readme_name,
46+
verbose=args.verbose,
47+
)
48+
49+
50+
def recursively_remove_inits_from_here():
51+
"""
52+
Add readmes to all python modules in the current directory
53+
"""
54+
parser = argparse.ArgumentParser(description="DevPack remove inits from here")
55+
parser.add_argument(
56+
"--path", "-p", type=Path, default=Path.cwd(), help="Path to remove inits from"
57+
)
58+
59+
parser.add_argument(
60+
"--init-name", "-r", type=str, default="__init__.py", help="init name"
61+
)
62+
parser.add_argument(
63+
"--verbose", action="store_true", help="Verbose output of removed files"
64+
)
65+
args = parser.parse_args()
66+
67+
recursive_remove_inits(
68+
args.path,
69+
init_name=args.init_name,
70+
verbose=args.verbose,
4071
)
4172

4273

4374
if __name__ == "__main__":
4475
recursively_add_readmes_from_here()
76+
recursively_remove_inits_from_here()

devpack/entry_points/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
import argparse
99

10-
from devpack.devpack.development import pip_uninstall_package
11-
12-
13-
from .development import pip_install_development_package
10+
from devpack.development import pip_uninstall_package
11+
from devpack.development import pip_install_development_package
1412

1513

1614
def install_develop():

0 commit comments

Comments
 (0)