mydefaults 0.0.1__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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 J. Günthner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mydefaults
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Boilerplate I use in my projects
|
|
5
|
+
Author-email: Guenthner <guenthner.jonathan@gmail.com>
|
|
6
|
+
License-File: LICENSE.txt
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Requires-Dist: colorama
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
Boilerplate I use in my projects
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Boilerplate I use in my projects
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from colorama import Fore
|
|
4
|
+
|
|
5
|
+
from mydefaults.argparse import command
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def create_logger(name: str):
|
|
9
|
+
log = logging.getLogger(name)
|
|
10
|
+
console = logging.StreamHandler()
|
|
11
|
+
log.addHandler(console)
|
|
12
|
+
log.setLevel(logging.DEBUG)
|
|
13
|
+
console.setFormatter(
|
|
14
|
+
logging.Formatter(
|
|
15
|
+
f"{{asctime}} [{Fore.YELLOW}{{levelname:>5}}{Fore.RESET}] {Fore.BLUE}{{name}}{Fore.RESET}: {{message}}",
|
|
16
|
+
style="{", datefmt="W%W %a %I:%M"))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from argparse import ArgumentParser
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from typing import Callable, Generator
|
|
6
|
+
|
|
7
|
+
from colorama import Fore
|
|
8
|
+
|
|
9
|
+
type MAGIC = Generator[None, Namespace, None]
|
|
10
|
+
|
|
11
|
+
all_sub_commands = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def intercept_interrupts(func):
|
|
15
|
+
@wraps(func)
|
|
16
|
+
def impl(*args, **kwargs):
|
|
17
|
+
try:
|
|
18
|
+
func(*args, **kwargs)
|
|
19
|
+
except KeyboardInterrupt:
|
|
20
|
+
print(f"{Fore.RED}Program was interrupted by user{Fore.RESET}", file=sys.stderr)
|
|
21
|
+
|
|
22
|
+
return impl
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def flatten_decorator(deco):
|
|
26
|
+
def impl0(*args, **kwargs):
|
|
27
|
+
def impl1(func):
|
|
28
|
+
return deco(func, *args, **kwargs)
|
|
29
|
+
|
|
30
|
+
return impl1
|
|
31
|
+
|
|
32
|
+
return impl0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@flatten_decorator
|
|
36
|
+
def command(func: Callable[[ArgumentParser], None], version: str):
|
|
37
|
+
@wraps(func)
|
|
38
|
+
@intercept_interrupts
|
|
39
|
+
def impl():
|
|
40
|
+
parser = ArgumentParser(prog=func.__name__.replace("_", "-"), description=func.__doc__, add_help=True)
|
|
41
|
+
parser.add_argument('-v', '--verbose', action='store_true', help="Show more output")
|
|
42
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {version}")
|
|
43
|
+
|
|
44
|
+
func(parser)
|
|
45
|
+
|
|
46
|
+
return impl
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def sub_command(func: Callable[[ArgumentParser], MAGIC]):
|
|
50
|
+
def send_to_generator(args: Namespace, generator: MAGIC):
|
|
51
|
+
try:
|
|
52
|
+
generator.send(args)
|
|
53
|
+
except StopIteration:
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
@wraps(func)
|
|
57
|
+
def impl(subparsers):
|
|
58
|
+
parser = subparsers.add_parser(func.__name__, description=func.__doc__, help=func.__doc__)
|
|
59
|
+
generator: MAGIC = func(parser)
|
|
60
|
+
next(generator)
|
|
61
|
+
parser.set_defaults(sub_command=lambda args: send_to_generator(args, generator))
|
|
62
|
+
|
|
63
|
+
all_sub_commands.append(impl)
|
|
64
|
+
|
|
65
|
+
return impl
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def add_sub_commands(subparsers):
|
|
69
|
+
for cmd in all_sub_commands:
|
|
70
|
+
cmd(subparsers)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def run_sub_command(args: argparse.Namespace):
|
|
74
|
+
args.sub_command(args)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.hatch.build.targets.sdist]
|
|
6
|
+
only-include = [
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE.txt",
|
|
9
|
+
"pyproject.toml",
|
|
10
|
+
"mydefaults"
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project]
|
|
14
|
+
name = "mydefaults"
|
|
15
|
+
version = "0.0.1" # version
|
|
16
|
+
authors = [
|
|
17
|
+
{ name = "Guenthner", email = "guenthner.jonathan@gmail.com" },
|
|
18
|
+
]
|
|
19
|
+
description = "Boilerplate I use in my projects"
|
|
20
|
+
readme = "README.md"
|
|
21
|
+
requires-python = ">=3.8"
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent"
|
|
26
|
+
]
|
|
27
|
+
dependencies = ["colorama"]
|
|
28
|
+
keywords = []
|