Skip to content

Commit 802252b

Browse files
committed
add docs and batch add readmes tool
1 parent 1490aa6 commit 802252b

136 files changed

Lines changed: 20688 additions & 372 deletions

File tree

Some content is hidden

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

.github/images/devpack.png

Lines changed: 3 additions & 0 deletions
Loading

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ ENV/
102102

103103
# Spyder project settings
104104
.spyderproject
105+
*.out
105106
.spyproject
106107

107108
# mkdocs documentation
@@ -125,5 +126,4 @@ logs/*.csv
125126

126127

127128
pip-wheel-metadata
128-
.pytest_cache
129129
build/

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fail_fast: true
22
repos:
33
- repo: https://github.com/ambv/black
4-
rev: 22.1.0
4+
rev: 22.6.0
55
hooks:
66
- id: black
77
language_version: python3.8

.readthedocs.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-20.04
11+
tools:
12+
python: "3.9"
13+
# You can also specify other tool versions:
14+
# nodejs: "16"
15+
# rust: "1.55"
16+
# golang: "1.17"
17+
18+
# Build documentation in the docs/ directory with Sphinx
19+
sphinx:
20+
configuration: docs/source/conf.py
21+
22+
# If using Sphinx, optionally build your docs in additional formats such as PDF
23+
# formats:
24+
# - pdf
25+
26+
# Optionally declare the Python requirements required to build your docs
27+
python:
28+
install:
29+
- requirements: requirements/requirements_dev.txt

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
# ProjectName
1+
# DevPack
22

33
```bash
4-
pip install projectname
5-
```
4+
pip install devpack -U
5+
```
6+
7+
Get a decent development
8+
9+
Contains some useful batching tools for python package development
10+
11+
- Auto add readmes to packages, with breadcrumbs

benchmarks/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

devpack/__init__.py

Lines changed: 4 additions & 2 deletions
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.4"
13+
__version__ = "0.0.5"
1414
__doc__ = """
1515
Created on 15/04/2020
1616
@@ -22,7 +22,7 @@
2222

2323
def dist_is_editable(dist: Any) -> bool:
2424
"""
25-
Return True if given Distribution is an editable install."""
25+
Return True if given Distribution is an editable installation."""
2626
import sys
2727
from pathlib import Path
2828

@@ -34,6 +34,8 @@ def dist_is_editable(dist: Any) -> bool:
3434

3535

3636
PROJECT_NAME = __project__.lower().strip().replace(" ", "_")
37+
PROJECT_VERSION = __version__
38+
PROJECT_YEAR = 2018
3739
PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_")
3840
PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR)
3941

devpack/batch_tools.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "heider"
5+
__doc__ = r"""
6+
7+
Created on 8/18/22
8+
"""
9+
10+
__all__ = ["auto_add_readme", "recursive_add_readmes", "TouchModeEnum"]
11+
12+
from enum import Enum
13+
from pathlib import Path
14+
from typing import Callable, Iterable, Optional
15+
16+
from sorcery import assigned_names
17+
18+
19+
class TouchModeEnum(Enum):
20+
"""
21+
The touch mode enum
22+
23+
"""
24+
25+
breadcrumb, empty, parent_name = assigned_names()
26+
27+
28+
def auto_add_readme(
29+
path: Path,
30+
*,
31+
touch_mode: TouchModeEnum = TouchModeEnum.breadcrumb,
32+
readme_name: str = "README.md",
33+
root_path: Optional[Path] = Path.cwd(),
34+
prefix="# ",
35+
) -> None:
36+
"""
37+
Add a readme to the root_path if it does not exist
38+
39+
:param path:
40+
:param touch_mode:
41+
:param readme_name:
42+
:param root_path:
43+
:param prefix:
44+
:return:
45+
46+
"""
47+
path = Path(path)
48+
readme_file = path / readme_name
49+
if not readme_file.exists():
50+
readme_file.touch()
51+
if touch_mode == TouchModeEnum.breadcrumb:
52+
assert root_path is not None
53+
readme_file.write_text(prefix + str(path.relative_to(root_path)))
54+
elif touch_mode == TouchModeEnum.empty:
55+
readme_file.write_text("")
56+
elif touch_mode == TouchModeEnum.parent_name:
57+
readme_file.write_text(prefix + str(readme_file.parent.name))
58+
else:
59+
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)
81+
82+
83+
def recursive_add_readmes(
84+
path: Path,
85+
exclusion_filter: Optional[Iterable[Callable]] = (negate(is_python_package),),
86+
*,
87+
touch_mode: TouchModeEnum = TouchModeEnum.breadcrumb,
88+
readme_name: str = "README.md",
89+
root_path: Optional[Path] = None,
90+
) -> None:
91+
"""
92+
recursively add readmes to all children spanning from root_path
93+
94+
"""
95+
path = Path(path)
96+
if root_path is None:
97+
root_path = path.parent
98+
99+
auto_add_readme(
100+
path, touch_mode=touch_mode, readme_name=readme_name, root_path=root_path
101+
)
102+
103+
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():
106+
recursive_add_readmes(
107+
child,
108+
exclusion_filter,
109+
touch_mode=touch_mode,
110+
readme_name=readme_name,
111+
root_path=root_path,
112+
)
113+
elif child.is_file():
114+
pass
115+
116+
117+
if __name__ == "__main__":
118+
recursive_add_readmes("exclude")

devpack/cli.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

devpack/development.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from typing import Optional
1313

14-
__all__ = ["pip_install_development_package"]
14+
__all__ = ["pip_install_development_package", "pip_uninstall_package"]
1515

1616

1717
def pip_install_development_package(
@@ -20,7 +20,8 @@ def pip_install_development_package(
2020
extra_index: Optional[str] = "https://pypi.org/simple/",
2121
upgrade: bool = True,
2222
) -> None:
23-
""" """
23+
"""
24+
Install package in development mode."""
2425
arguments = [
2526
"install",
2627
"--index-url",
@@ -42,6 +43,14 @@ def pip_install_development_package(
4243
subprocess.check_call([sys.executable, "-m", "pip", *arguments])
4344

4445

46+
def pip_uninstall_package(package: str) -> None:
47+
"""
48+
Same as pip uninstall package, but may be expanded to include other options, like apppath clean up.
49+
#TODO: APPPATH CLEANUP
50+
"""
51+
subprocess.check_call([sys.executable, "-m", "pip", "uninstall", package])
52+
53+
4554
if __name__ == "__main__":
4655
pass
4756
# pip_install_development_package("devpack")

0 commit comments

Comments
 (0)