clizard 0.1.0__py3-none-any.whl
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.
- clizard/__init__.py +6 -0
- clizard/__main__.py +146 -0
- clizard/cli_args.py +95 -0
- clizard/clizard_file.py +55 -0
- clizard/config.py +50 -0
- clizard/core.py +359 -0
- clizard/discover.py +349 -0
- clizard/examples/examples_auto_cli_release_tool.py +31 -0
- clizard/examples/examples_llmlight_app.py +42 -0
- clizard/examples/examples_summarizer.py +16 -0
- clizard/examples/examples_wrap_summarizer.py +63 -0
- clizard/git_info.py +64 -0
- clizard/project_info.py +41 -0
- clizard/scaffold.py +187 -0
- clizard-0.1.0.dist-info/METADATA +174 -0
- clizard-0.1.0.dist-info/RECORD +20 -0
- clizard-0.1.0.dist-info/WHEEL +5 -0
- clizard-0.1.0.dist-info/entry_points.txt +3 -0
- clizard-0.1.0.dist-info/licenses/LICENSE +22 -0
- clizard-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""How to turn your existing argparse main() into a clizard interface."""
|
|
2
|
+
import argparse
|
|
3
|
+
from clizard import auto_cli
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def run(username, package, clean=None, install=None, twine=None, verbose=None):
|
|
7
|
+
"""Your existing function, unchanged."""
|
|
8
|
+
print(f"Releasing {package} as {username} (clean={clean}, twine={twine}, verbose={verbose})")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
parser = argparse.ArgumentParser()
|
|
13
|
+
parser.add_argument("-u", "--username", type=str, help="Username on Github/Gitlab..")
|
|
14
|
+
parser.add_argument("-p", "--package", type=str, help="Package name to be released.")
|
|
15
|
+
parser.add_argument("-c", "--clean", type=int, choices=[0, 1], help="Remove local builds: [dist], [build] and [x.egg-info].")
|
|
16
|
+
parser.add_argument("-i", "--install", type=int, choices=[0, 1], help="Install this versions on local machine.")
|
|
17
|
+
parser.add_argument("-t", "--twine", type=str, help="Path to twine in case you have a custom build.")
|
|
18
|
+
parser.add_argument("-v", "--verbosity", type=int, choices=[0, 1, 2, 3, 4, 5], help="Verbosity, higher number tends to more information.")
|
|
19
|
+
args = parser.parse_args()
|
|
20
|
+
|
|
21
|
+
# Instead of calling run(...) directly, build a CLI around it:
|
|
22
|
+
def run_callback(cli):
|
|
23
|
+
s = cli.config.settings
|
|
24
|
+
run(s["username"], s["package"], clean=s["clean"], install=s["install"], twine=s["twine"], verbose=s["verbosity"])
|
|
25
|
+
|
|
26
|
+
cli = auto_cli(parser, args=args, app_name="ReleaseTool", run_callback=run_callback)
|
|
27
|
+
cli.run()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Example: how another script/project reuses clizard for its own tool."""
|
|
2
|
+
from clizard import GenericCLI, parse_args
|
|
3
|
+
|
|
4
|
+
EXTRA_ARGS = [
|
|
5
|
+
{"flags": ["--temperature"], "kwargs": {"type": float, "default": None, "help": "Sampling temperature"}},
|
|
6
|
+
]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def my_handler(prompt, cli):
|
|
10
|
+
# plug in real LLM call here
|
|
11
|
+
model = cli.config.get("model")
|
|
12
|
+
return f"[{model}] you said: **{prompt}**"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
args = parse_args(app_name="LLMlight", extra_args=EXTRA_ARGS)
|
|
17
|
+
|
|
18
|
+
cli = GenericCLI(
|
|
19
|
+
app_name=args.name or "LLMlight",
|
|
20
|
+
ascii_art=r"""
|
|
21
|
+
/\_/\
|
|
22
|
+
( o.o )
|
|
23
|
+
> ^ <
|
|
24
|
+
""",
|
|
25
|
+
settings={"model": "google/gemma-26B-a4B", "path": "C:/LLMlight", "temperature": 0.7},
|
|
26
|
+
config_path=args.config,
|
|
27
|
+
handler=my_handler,
|
|
28
|
+
tips=["/init", "/help", "generate documentation"],
|
|
29
|
+
updates=["Agent system improvements", "Documentation generation", "Local model support"],
|
|
30
|
+
)
|
|
31
|
+
cli.config.update_from_args({"model": args.model, "path": args.path, "temperature": args.temperature})
|
|
32
|
+
|
|
33
|
+
# custom command specific to this project
|
|
34
|
+
@cli.command("/init", "Initialize a new project")
|
|
35
|
+
def cmd_init(prompt):
|
|
36
|
+
cli.assistant_message(f"Initialized project at `{cli.config.get('path')}`")
|
|
37
|
+
|
|
38
|
+
cli.run()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Example existing script: summarizes a text file."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def main(input_path: str, max_words: int = 50, uppercase: bool = False) -> str:
|
|
5
|
+
"""Pretend this does real work (e.g. summarization)."""
|
|
6
|
+
try:
|
|
7
|
+
with open(input_path, "r") as f:
|
|
8
|
+
text = f.read()
|
|
9
|
+
except FileNotFoundError:
|
|
10
|
+
return f"File not found: {input_path}"
|
|
11
|
+
|
|
12
|
+
words = text.split()[:max_words]
|
|
13
|
+
result = " ".join(words)
|
|
14
|
+
if uppercase:
|
|
15
|
+
result = result.upper()
|
|
16
|
+
return result
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Example: expose summarizer.main(...) through a clizard interface.
|
|
2
|
+
|
|
3
|
+
Run:
|
|
4
|
+
python wrap_summarizer.py --input-path notes.txt --max-words 20
|
|
5
|
+
"""
|
|
6
|
+
from clizard import GenericCLI, parse_args
|
|
7
|
+
from summarizer import main as summarize
|
|
8
|
+
|
|
9
|
+
# 1. Declare the script's own arguments as extra CLI flags.
|
|
10
|
+
EXTRA_ARGS = [
|
|
11
|
+
{"flags": ["--input-path"], "kwargs": {"default": None, "help": "Path to input text file"}},
|
|
12
|
+
{"flags": ["--max-words"], "kwargs": {"type": int, "default": 50, "help": "Max words to keep"}},
|
|
13
|
+
{"flags": ["--uppercase"], "kwargs": {"action": "store_true", "help": "Uppercase the output"}},
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def build_cli(args):
|
|
18
|
+
cli = GenericCLI(
|
|
19
|
+
app_name="Summarizer CLI",
|
|
20
|
+
settings={
|
|
21
|
+
"input_path": args.input_path,
|
|
22
|
+
"max_words": args.max_words,
|
|
23
|
+
"uppercase": args.uppercase,
|
|
24
|
+
},
|
|
25
|
+
tips=["/run", "/settings", "/docs", "/help"],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# 2. A command that calls main() using whatever is currently in settings.
|
|
29
|
+
@cli.command("/run", "Run the summarizer with current settings")
|
|
30
|
+
def cmd_run(prompt):
|
|
31
|
+
path = cli.config.get("input_path")
|
|
32
|
+
if not path:
|
|
33
|
+
cli.error("No input_path set. Use: /settings set input_path <file>")
|
|
34
|
+
return
|
|
35
|
+
cli.status(f"Summarizing {path}...")
|
|
36
|
+
result = summarize(
|
|
37
|
+
input_path=path,
|
|
38
|
+
max_words=cli.config.get("max_words"),
|
|
39
|
+
uppercase=cli.config.get("uppercase"),
|
|
40
|
+
)
|
|
41
|
+
cli.assistant_message(result)
|
|
42
|
+
|
|
43
|
+
# 3. Optional: also let free-text input trigger main() directly,
|
|
44
|
+
# treating the typed text as the input_path.
|
|
45
|
+
def handler(prompt, cli):
|
|
46
|
+
return summarize(
|
|
47
|
+
input_path=prompt,
|
|
48
|
+
max_words=cli.config.get("max_words"),
|
|
49
|
+
uppercase=cli.config.get("uppercase"),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
cli.handler = handler
|
|
53
|
+
return cli
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main():
|
|
57
|
+
args = parse_args(app_name="Summarizer CLI", extra_args=EXTRA_ARGS)
|
|
58
|
+
cli = build_cli(args)
|
|
59
|
+
cli.run()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
main()
|
clizard/git_info.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Read repo identity straight out of .git/config."""
|
|
2
|
+
import configparser
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _parse_remote_url(url: str):
|
|
8
|
+
"""Return (host, user, repo) from a git remote URL (ssh or https)."""
|
|
9
|
+
url = url.strip().rstrip("/")
|
|
10
|
+
if url.endswith(".git"):
|
|
11
|
+
url = url[:-4]
|
|
12
|
+
|
|
13
|
+
m = re.match(r"git@([^:]+):([^/]+)/(.+)$", url) # git@github.com:user/repo
|
|
14
|
+
if not m:
|
|
15
|
+
m = re.match(r"https?://([^/]+)/([^/]+)/(.+)$", url) # https://github.com/user/repo
|
|
16
|
+
if not m:
|
|
17
|
+
return None, None, None
|
|
18
|
+
|
|
19
|
+
host, user, repo = m.group(1), m.group(2), m.group(3)
|
|
20
|
+
return host, user, repo
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_git_info(repo_path="."):
|
|
24
|
+
"""Inspect <repo_path>/.git/config and return repo metadata.
|
|
25
|
+
|
|
26
|
+
Returns dict with: host, github_user, github_repo, remote_url,
|
|
27
|
+
default_branch. Any field defaults to None/"" if not found.
|
|
28
|
+
"""
|
|
29
|
+
info = {
|
|
30
|
+
"host": None,
|
|
31
|
+
"github_user": None,
|
|
32
|
+
"github_repo": None,
|
|
33
|
+
"remote_url": None,
|
|
34
|
+
"default_branch": "main",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
git_config = Path(repo_path) / ".git" / "config"
|
|
38
|
+
if not git_config.exists():
|
|
39
|
+
return info
|
|
40
|
+
|
|
41
|
+
parser = configparser.ConfigParser(strict=False)
|
|
42
|
+
try:
|
|
43
|
+
parser.read(git_config)
|
|
44
|
+
except configparser.Error:
|
|
45
|
+
return info
|
|
46
|
+
|
|
47
|
+
for section in parser.sections():
|
|
48
|
+
if section.startswith('remote "'):
|
|
49
|
+
url = parser.get(section, "url", fallback=None)
|
|
50
|
+
if url:
|
|
51
|
+
info["remote_url"] = url
|
|
52
|
+
host, user, repo = _parse_remote_url(url)
|
|
53
|
+
info["host"] = host
|
|
54
|
+
info["github_user"] = user
|
|
55
|
+
info["github_repo"] = repo
|
|
56
|
+
break # first remote (usually 'origin') wins
|
|
57
|
+
|
|
58
|
+
head_file = Path(repo_path) / ".git" / "HEAD"
|
|
59
|
+
if head_file.exists():
|
|
60
|
+
head = head_file.read_text().strip()
|
|
61
|
+
if head.startswith("ref: refs/heads/"):
|
|
62
|
+
info["default_branch"] = head.split("refs/heads/")[-1]
|
|
63
|
+
|
|
64
|
+
return info
|
clizard/project_info.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Read project metadata out of pyproject.toml."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import tomllib # py3.11+
|
|
6
|
+
except ImportError:
|
|
7
|
+
import tomli as tomllib # fallback
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_project_info(repo_path="."):
|
|
11
|
+
"""Return dict with: name, version, docs_url, requirements (list)."""
|
|
12
|
+
info = {"name": None, "version": None, "docs_url": None, "requirements": []}
|
|
13
|
+
|
|
14
|
+
pyproject = Path(repo_path) / "pyproject.toml"
|
|
15
|
+
if pyproject.exists():
|
|
16
|
+
try:
|
|
17
|
+
with open(pyproject, "rb") as f:
|
|
18
|
+
data = tomllib.load(f)
|
|
19
|
+
except Exception:
|
|
20
|
+
data = {}
|
|
21
|
+
|
|
22
|
+
project = data.get("project", {})
|
|
23
|
+
info["name"] = project.get("name")
|
|
24
|
+
info["version"] = project.get("version")
|
|
25
|
+
info["requirements"] = project.get("dependencies", [])
|
|
26
|
+
info["description"] = project.get("description", "")
|
|
27
|
+
|
|
28
|
+
urls = project.get("urls", {})
|
|
29
|
+
for key in ("Documentation", "documentation", "Docs", "docs"):
|
|
30
|
+
if key in urls:
|
|
31
|
+
info["docs_url"] = urls[key]
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
req_file = Path(repo_path) / "requirements.txt"
|
|
35
|
+
if not info["requirements"] and req_file.exists():
|
|
36
|
+
info["requirements"] = [
|
|
37
|
+
line.strip() for line in req_file.read_text().splitlines()
|
|
38
|
+
if line.strip() and not line.strip().startswith("#")
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
return info
|
clizard/scaffold.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Generate a standalone `clizard_main.py` that wraps a repo's existing
|
|
2
|
+
main() with tclizard_main clizard interface, using .clizard for display settings.
|
|
3
|
+
"""
|
|
4
|
+
import inspect
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .discover import find_main, settings_from_main
|
|
8
|
+
from .clizard_file import ensure_clizard_file, save_clizard_file
|
|
9
|
+
from .git_info import get_git_info
|
|
10
|
+
|
|
11
|
+
TEMPLATE = '''"""Auto-generated by clizard. Wraps {entry_module}.main() with the
|
|
12
|
+
clizard interactive interface. Re-run `clizard --scaffold` to regenerate.
|
|
13
|
+
"""
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
sys.path.insert(0, str(Path(__file__).parent / "{entry_dir}"))
|
|
18
|
+
|
|
19
|
+
from {entry_module} import main as _original_main
|
|
20
|
+
# Prefer the local `clizard` package if present; fall back to `genericli` for
|
|
21
|
+
# standalone generated scripts that expect that external package.
|
|
22
|
+
|
|
23
|
+
from clizard import GenericCLI
|
|
24
|
+
from clizard.clizard_file import load_clizard_file
|
|
25
|
+
|
|
26
|
+
REPO_PATH = str(Path(__file__).parent.resolve())
|
|
27
|
+
|
|
28
|
+
# Fallback values baked in at generation time, used only if .clizard is
|
|
29
|
+
# missing these keys (e.g. it predates this feature, or was hand-edited).
|
|
30
|
+
_DEFAULT_SETTINGS = {settings!r}
|
|
31
|
+
_DEFAULT_ARG_META = {arg_meta!r}
|
|
32
|
+
_DEFAULT_CALL_STYLE = {call_style!r}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def build_cli():
|
|
36
|
+
clz = load_clizard_file(REPO_PATH)
|
|
37
|
+
|
|
38
|
+
# Settings/arg_meta/call_style live in .clizard so that edits made via
|
|
39
|
+
# `/settings` while running `clizard` interactively (or by hand-editing
|
|
40
|
+
# .clizard) are picked up here too, without needing to re-scaffold.
|
|
41
|
+
settings = clz.get("settings") or _DEFAULT_SETTINGS
|
|
42
|
+
arg_meta = clz.get("arg_meta") or _DEFAULT_ARG_META
|
|
43
|
+
call_style = clz.get("call_style") or _DEFAULT_CALL_STYLE
|
|
44
|
+
|
|
45
|
+
cli = GenericCLI(
|
|
46
|
+
app_name=clz.get("app_name") or {app_name!r},
|
|
47
|
+
ascii_art=clz.get("ascii_art"),
|
|
48
|
+
accent_color=clz.get("accent_color", "#d97757"),
|
|
49
|
+
settings=settings,
|
|
50
|
+
tips=clz.get("tips"),
|
|
51
|
+
updates=clz.get("updates"),
|
|
52
|
+
)
|
|
53
|
+
cli.arg_meta = arg_meta
|
|
54
|
+
|
|
55
|
+
@cli.command("/run", "Run {entry_module}.main() with current settings")
|
|
56
|
+
def _cmd_run(prompt):
|
|
57
|
+
cli.status("Running...")
|
|
58
|
+
if call_style == "argv":
|
|
59
|
+
# main() takes no arguments and parses its own argparse
|
|
60
|
+
# parser internally -- rebuild sys.argv from settings instead.
|
|
61
|
+
argv = [sys.argv[0]]
|
|
62
|
+
for name, meta in cli.arg_meta.items():
|
|
63
|
+
flag = meta.get("flag")
|
|
64
|
+
if not flag:
|
|
65
|
+
continue
|
|
66
|
+
val = cli.config.get(name)
|
|
67
|
+
if val is None:
|
|
68
|
+
continue
|
|
69
|
+
if meta.get("is_flag"):
|
|
70
|
+
if val:
|
|
71
|
+
argv.append(flag)
|
|
72
|
+
else:
|
|
73
|
+
argv.extend([flag, str(val)])
|
|
74
|
+
old_argv = sys.argv
|
|
75
|
+
sys.argv = argv
|
|
76
|
+
try:
|
|
77
|
+
result = _original_main()
|
|
78
|
+
finally:
|
|
79
|
+
sys.argv = old_argv
|
|
80
|
+
else:
|
|
81
|
+
call_kwargs = {{k: cli.config.get(k) for k in settings}}
|
|
82
|
+
result = _original_main(**call_kwargs)
|
|
83
|
+
if result is not None:
|
|
84
|
+
cli.assistant_message(str(result))
|
|
85
|
+
|
|
86
|
+
return cli
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def main():
|
|
90
|
+
build_cli().run()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
main()
|
|
95
|
+
'''
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def generate_clizard_main(repo_path=".", output_name="clizard_main.py"):
|
|
99
|
+
"""Write a clizard_main.py at the repo root. Returns the output Path,
|
|
100
|
+
or raises RuntimeError if no main() could be found.
|
|
101
|
+
|
|
102
|
+
The previous default filename `clizard.py` shadows the `clizard` package when
|
|
103
|
+
executed from the repo root (Python will import the local `clizard.py` file as
|
|
104
|
+
the `clizard` module, making `from clizard import ...` fail). Use
|
|
105
|
+
`clizard_main.py` to avoid that naming collision.
|
|
106
|
+
"""
|
|
107
|
+
repo_path = Path(repo_path).resolve()
|
|
108
|
+
module, main_func, entry_file = find_main(str(repo_path))
|
|
109
|
+
|
|
110
|
+
if main_func is None:
|
|
111
|
+
raise RuntimeError(f"No main() found under {repo_path}; nothing to wrap.")
|
|
112
|
+
|
|
113
|
+
settings, arg_meta, call_style = settings_from_main(main_func)
|
|
114
|
+
safe_arg_meta = {
|
|
115
|
+
name: {
|
|
116
|
+
"choices": info["choices"],
|
|
117
|
+
# Only a plain string type name (e.g. "int") is safe to embed
|
|
118
|
+
# in the generated source; a real class's repr (e.g. "<class
|
|
119
|
+
# 'int'>") is not valid Python syntax inside a dict literal.
|
|
120
|
+
"type": info["type"] if isinstance(info.get("type"), str) else None,
|
|
121
|
+
"help": info["help"],
|
|
122
|
+
"flag": info.get("flag"),
|
|
123
|
+
"is_flag": info.get("is_flag", False),
|
|
124
|
+
}
|
|
125
|
+
for name, info in arg_meta.items()
|
|
126
|
+
}
|
|
127
|
+
run_body_call_style = call_style
|
|
128
|
+
|
|
129
|
+
entry_file = Path(entry_file)
|
|
130
|
+
entry_module = entry_file.stem # "__main__" or "main"
|
|
131
|
+
entry_dir = entry_file.parent.relative_to(repo_path) if entry_file.parent != repo_path else "."
|
|
132
|
+
|
|
133
|
+
# Both clizard_main.py and .clizard always live at repo_path (the repo
|
|
134
|
+
# root), never inside the subdirectory/package containing main(). This
|
|
135
|
+
# matches the sys.path math below (Path(__file__).parent / entry_dir,
|
|
136
|
+
# with entry_dir relative to repo_path) and keeps a single, predictable
|
|
137
|
+
# location -- the same one `clizard` itself uses for .clizard.
|
|
138
|
+
out_path = repo_path / output_name
|
|
139
|
+
|
|
140
|
+
# Persist the discovered settings/arg_meta/call_style into .clizard so
|
|
141
|
+
# they're loaded at runtime by build_cli() above -- this also means
|
|
142
|
+
# edits made via `/settings` (or by hand-editing .clizard) carry over
|
|
143
|
+
# without needing to re-scaffold, and clizard_main.py can be regenerated
|
|
144
|
+
# later without losing customizations made elsewhere in .clizard.
|
|
145
|
+
clz = ensure_clizard_file(str(repo_path))
|
|
146
|
+
clz["settings"] = settings
|
|
147
|
+
clz["arg_meta"] = safe_arg_meta
|
|
148
|
+
clz["call_style"] = call_style
|
|
149
|
+
save_clizard_file(clz, str(repo_path))
|
|
150
|
+
|
|
151
|
+
# __main__.py can't be imported by stem name; use the package instead.
|
|
152
|
+
if entry_module == "__main__":
|
|
153
|
+
entry_module = entry_file.parent.name
|
|
154
|
+
entry_dir = entry_file.parent.parent.relative_to(repo_path) if entry_file.parent.parent != repo_path else "."
|
|
155
|
+
|
|
156
|
+
code = TEMPLATE.format(
|
|
157
|
+
entry_module=entry_module,
|
|
158
|
+
entry_dir=str(entry_dir),
|
|
159
|
+
app_name=clz.get("app_name") or repo_path.name,
|
|
160
|
+
settings=settings,
|
|
161
|
+
arg_meta=safe_arg_meta,
|
|
162
|
+
call_style=run_body_call_style,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Write file
|
|
166
|
+
out_path.write_text(code)
|
|
167
|
+
return out_path
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def clizardmake_cli(path=None):
|
|
171
|
+
"""Console entrypoint wrapper that uses the current working directory by default.
|
|
172
|
+
|
|
173
|
+
This function is intended for the `clizardmake` console_scripts entry point so
|
|
174
|
+
that running `clizardmake` will operate on the directory where it is executed.
|
|
175
|
+
"""
|
|
176
|
+
import os
|
|
177
|
+
import sys
|
|
178
|
+
|
|
179
|
+
repo_path = Path(path or os.getcwd())
|
|
180
|
+
|
|
181
|
+
try:
|
|
182
|
+
out = generate_clizard_main(repo_path=str(repo_path))
|
|
183
|
+
# Print the output path so the user sees where the file was written
|
|
184
|
+
print(f'clizard main file written to: {out}')
|
|
185
|
+
except RuntimeError as e:
|
|
186
|
+
print(str(e), file=sys.stderr)
|
|
187
|
+
sys.exit(1)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clizard
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: clizard is a Python library for Reusable rich-based interactive CLI framework
|
|
5
|
+
Author-email: Erdogan Taskesen <erdogant@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://erdogant.github.io/clizard
|
|
8
|
+
Project-URL: Download, https://github.com/erdogant/clizard/archive/{version}.tar.gz
|
|
9
|
+
Keywords: Python,clizard
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: Unix
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: rich>=13.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
[](https://img.shields.io/pypi/pyversions/clizard)
|
|
25
|
+
[](https://pypi.org/project/clizard/)
|
|
26
|
+
[](https://erdogant.github.io/clizard/)
|
|
27
|
+
[](https://github.com/erdogant/clizard/)
|
|
28
|
+
[](https://pepy.tech/project/clizard)
|
|
29
|
+
[](https://pepy.tech/project/clizard)
|
|
30
|
+
[](https://github.com/erdogant/clizard/blob/master/LICENSE)
|
|
31
|
+
[](https://github.com/erdogant/clizard/network)
|
|
32
|
+
[](https://github.com/erdogant/clizard/issues)
|
|
33
|
+
[](http://www.repostatus.org/#active)
|
|
34
|
+
[](https://zenodo.org/badge/latestdoi/231843440)
|
|
35
|
+
[](https://erdogant.github.io/clizard/pages/html/Documentation.html#medium-blog)
|
|
36
|
+
[](https://erdogant.github.io/clizard/pages/html/Documentation.html#colab-notebook)
|
|
37
|
+
[](https://erdogant.github.io/clizard/pages/html/Documentation.html#)
|
|
38
|
+
|
|
39
|
+
<div>
|
|
40
|
+
<a href="https://erdogant.github.io/clizard/">
|
|
41
|
+
<img src="https://raw.githubusercontent.com/erdogant/clizard/master/docs/figs/logo.png"
|
|
42
|
+
width="250"
|
|
43
|
+
align="left" />
|
|
44
|
+
</a>
|
|
45
|
+
clizard is a Python package for probability density fitting of univariate distributions for random variables.
|
|
46
|
+
The clizard library can determine the best fit for over 90 theoretical distributions. The goodness-of-fit test is used to score for the best fit and after finding the best-fitted theoretical distribution, the loc, scale, and arg parameters are returned.
|
|
47
|
+
It can be used for parametric, non-parametric, and discrete distributions. ⭐️Star it if you like it⭐️
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### Key Features
|
|
53
|
+
|
|
54
|
+
| Feature | Description |
|
|
55
|
+
|--------|-------------|
|
|
56
|
+
| [**Parametric Fitting**](https://erdogant.github.io/clizard/pages/html/Parametric.html) | Fit distributions on empirical data X. |
|
|
57
|
+
| [**Non-Parametric Fitting**](https://erdogant.github.io/clizard/pages/html/Quantile.html) | Fit distributions on empirical data X using non-parametric approaches (quantile, percentiles). |
|
|
58
|
+
| [**Discrete Fitting**](https://erdogant.github.io/clizard/pages/html/Discrete.html) | Fit distributions on empirical data X using binomial distribution. |
|
|
59
|
+
| [**Predict**](https://erdogant.github.io/clizard/pages/html/Functions.html#module-clizard.clizard.clizard.predict) | Compute probabilities for response variables y. |
|
|
60
|
+
| [**Synthetic Data**](https://erdogant.github.io/clizard/pages/html/Generate.html) | Generate synthetic data. |
|
|
61
|
+
| [**Plots**](https://erdogant.github.io/clizard/pages/html/Plots.html) | Varoius plotting functionalities. |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### Resources and Links
|
|
66
|
+
- **Example Notebooks:** [Examples](https://erdogant.github.io/clizard/pages/html/Documentation.html)
|
|
67
|
+
- **Blog Posts:** [Medium](https://erdogant.github.io/clizard/pages/html/Documentation.html#medium-blog)
|
|
68
|
+
- **Documentation:** [Website](https://erdogant.github.io/clizard)
|
|
69
|
+
- **Bug Reports and Feature Requests:** [GitHub Issues](https://github.com/erdogant/clizard/issues)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Background
|
|
74
|
+
|
|
75
|
+
* For the parametric approach, The clizard library can determine the best fit across 89 theoretical distributions.
|
|
76
|
+
To score the fit, one of the scoring statistics for the good-of-fitness test can be used used, such as RSS/SSE, Wasserstein,
|
|
77
|
+
Kolmogorov-Smirnov (KS), or Energy. After finding the best-fitted theoretical distribution, the loc, scale,
|
|
78
|
+
and arg parameters are returned, such as mean and standard deviation for normal distribution.
|
|
79
|
+
|
|
80
|
+
* For the non-parametric approach, the clizard library contains two methods, the quantile and percentile method.
|
|
81
|
+
Both methods assume that the data does not follow a specific probability distribution. In the case of the quantile method,
|
|
82
|
+
the quantiles of the data are modeled whereas for the percentile method, the percentiles are modeled.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### Installation
|
|
87
|
+
|
|
88
|
+
##### Install clizard from PyPI
|
|
89
|
+
```bash
|
|
90
|
+
pip install clizard
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
##### Install from Github source
|
|
94
|
+
```bash
|
|
95
|
+
pip install git+https://github.com/erdogant/clizard
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
##### Imort Library
|
|
99
|
+
```python
|
|
100
|
+
import clizard
|
|
101
|
+
print(clizard.__version__)
|
|
102
|
+
|
|
103
|
+
# Import library
|
|
104
|
+
from clizard import clizard
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<hr>
|
|
108
|
+
|
|
109
|
+
### Examples
|
|
110
|
+
|
|
111
|
+
##### [Example: Quick start to find best fit for your input data](https://erdogant.github.io/clizard/pages/html/Examples.html#)
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
|
|
115
|
+
# [clizard] >INFO> fit
|
|
116
|
+
# [clizard] >INFO> transform
|
|
117
|
+
# [clizard] >INFO> [norm ] [0.00 sec] [RSS: 0.00108326] [loc=-0.048 scale=1.997]
|
|
118
|
+
# [clizard] >INFO> [expon ] [0.00 sec] [RSS: 0.404237] [loc=-6.897 scale=6.849]
|
|
119
|
+
# [clizard] >INFO> [pareto ] [0.00 sec] [RSS: 0.404237] [loc=-536870918.897 scale=536870912.000]
|
|
120
|
+
# [clizard] >INFO> [dweibull ] [0.06 sec] [RSS: 0.0115552] [loc=-0.031 scale=1.722]
|
|
121
|
+
# [clizard] >INFO> [t ] [0.59 sec] [RSS: 0.00108349] [loc=-0.048 scale=1.997]
|
|
122
|
+
# [clizard] >INFO> [genextreme] [0.17 sec] [RSS: 0.00300806] [loc=-0.806 scale=1.979]
|
|
123
|
+
# [clizard] >INFO> [gamma ] [0.05 sec] [RSS: 0.00108459] [loc=-1862.903 scale=0.002]
|
|
124
|
+
# [clizard] >INFO> [lognorm ] [0.32 sec] [RSS: 0.00121597] [loc=-110.597 scale=110.530]
|
|
125
|
+
# [clizard] >INFO> [beta ] [0.10 sec] [RSS: 0.00105629] [loc=-16.364 scale=32.869]
|
|
126
|
+
# [clizard] >INFO> [uniform ] [0.00 sec] [RSS: 0.287339] [loc=-6.897 scale=14.437]
|
|
127
|
+
# [clizard] >INFO> [loggamma ] [0.12 sec] [RSS: 0.00109042] [loc=-370.746 scale=55.722]
|
|
128
|
+
# [clizard] >INFO> Compute confidence intervals [parametric]
|
|
129
|
+
# [clizard] >INFO> Compute significance for 9 samples.
|
|
130
|
+
# [clizard] >INFO> Multiple test correction method applied: [fdr_bh].
|
|
131
|
+
# [clizard] >INFO> Create PDF plot for the parametric method.
|
|
132
|
+
# [clizard] >INFO> Mark 5 significant regions
|
|
133
|
+
# [clizard] >INFO> Estimated distribution: beta [loc:-16.364265, scale:32.868811]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
<p align="left">
|
|
137
|
+
<a href="https://erdogant.github.io/clizard/pages/html/Examples.html#make-predictions">
|
|
138
|
+
<img src="https://github.com/erdogant/clizard/blob/master/docs/figs/example_figP4c.png" width="450" />
|
|
139
|
+
</a>
|
|
140
|
+
</p>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
#
|
|
144
|
+
|
|
145
|
+
##### [Example: Plot summary of the tested distributions](https://erdogant.github.io/clizard/pages/html/Examples.html#plot-rss)
|
|
146
|
+
|
|
147
|
+
After we have a fitted model, we can make some predictions using the theoretical distributions.
|
|
148
|
+
After making some predictions, we can plot again but now the predictions are automatically included.
|
|
149
|
+
|
|
150
|
+
<p align="left">
|
|
151
|
+
<a href="https://erdogant.github.io/clizard/pages/html/Examples.html#plot-rss">
|
|
152
|
+
<img src="https://github.com/erdogant/clizard/blob/master/docs/figs/fig1_summary.png" width="450" />
|
|
153
|
+
</a>
|
|
154
|
+
</p>
|
|
155
|
+
|
|
156
|
+
#
|
|
157
|
+
|
|
158
|
+
<hr>
|
|
159
|
+
|
|
160
|
+
### Contributors
|
|
161
|
+
Setting up and maintaining bnlearn has been possible thanks to users and contributors. Thanks to:
|
|
162
|
+
|
|
163
|
+
<p align="left">
|
|
164
|
+
<a href="https://github.com/erdogant/clizard/graphs/contributors">
|
|
165
|
+
<img src="https://contrib.rocks/image?repo=erdogant/clizard" />
|
|
166
|
+
</a>
|
|
167
|
+
</p>
|
|
168
|
+
|
|
169
|
+
### Maintainer
|
|
170
|
+
* Erdogan Taskesen, github: [erdogant](https://github.com/erdogant)
|
|
171
|
+
* Contributions are welcome.
|
|
172
|
+
* Yes! This library is entirely **free** but it runs on coffee! :) Feel free to support with a <a href="https://erdogant.github.io/donate/?currency=USD&amount=5">Coffee</a>.
|
|
173
|
+
|
|
174
|
+
[](https://www.buymeacoffee.com/erdogant)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
clizard/__init__.py,sha256=NZ5zGhfVra-ScQaOomjsY2HEzQlFzXfRutY92ndfgi0,213
|
|
2
|
+
clizard/__main__.py,sha256=QzRKix5w2tsHKk7pqmJw57Yd1_YHG-tcxhsN9hSzhSY,5960
|
|
3
|
+
clizard/cli_args.py,sha256=SVxp_wDz4Q9xa5LYFBcX5rrtgEYfY5GQxSfYPAmhrCI,3698
|
|
4
|
+
clizard/clizard_file.py,sha256=MI5lQ_uaOV7Gn8PFUqgXj76iiihY6CeibCxujiWGQXk,1511
|
|
5
|
+
clizard/config.py,sha256=8epmfws8YL7T2ayiLYJ7OuUTlAu5Osv4UdDIfYSfisg,1524
|
|
6
|
+
clizard/core.py,sha256=TMWxg9Rz0axnO-nf8HRgd4lDiZ_kt9aVZMqLW8HbJBU,13241
|
|
7
|
+
clizard/discover.py,sha256=7BSiiEZhEKWhwW19E8EsxhEAoM4-7EVhYRJj922C3gg,11444
|
|
8
|
+
clizard/git_info.py,sha256=v2j8RCFSrKBF9NSVXU_n5AV7ihpmoMghQ170LJDt_P0,1978
|
|
9
|
+
clizard/project_info.py,sha256=eQdDpl9pz2vH7_K7gBhhpnPKil4u8AN6GTJAVhJXAlg,1359
|
|
10
|
+
clizard/scaffold.py,sha256=awR81fPdn8XXsydmwHs4zWOUuTgDxqSHFbMjzytAhnU,7015
|
|
11
|
+
clizard/examples/examples_auto_cli_release_tool.py,sha256=By5hCfbCh3YjueJPbpLz8uYZRBItJe7cIQGeff3nnko,1498
|
|
12
|
+
clizard/examples/examples_llmlight_app.py,sha256=dfzb_Hl4jjmHbdaR6tTLlnI2zaFmkjcLKYlv3MnghbM,1286
|
|
13
|
+
clizard/examples/examples_summarizer.py,sha256=i3HY0Sb3WGZN8tiOzkm78OaKHVsnqufKQfdLMUvmoqw,487
|
|
14
|
+
clizard/examples/examples_wrap_summarizer.py,sha256=Uf7p3pi5uaQPKuNy3gIRxCBwPiB4zTkvQ0hk5Ee7aBY,2021
|
|
15
|
+
clizard-0.1.0.dist-info/licenses/LICENSE,sha256=v324pRx1CBd6jiK-y7mRwY4IK-eN7UGIkAcT_6zmYXg,1120
|
|
16
|
+
clizard-0.1.0.dist-info/METADATA,sha256=jI2189I97qpTMMeHRp9RlZg6nQNIr3Wu1WMPbE9Yy5k,9144
|
|
17
|
+
clizard-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
18
|
+
clizard-0.1.0.dist-info/entry_points.txt,sha256=UZS1--te8y-T5lLxWOp3c3EMjvJsHiyWY6rLW_mVoIU,97
|
|
19
|
+
clizard-0.1.0.dist-info/top_level.txt,sha256=zSS6AZ85ZQqAsMrOTjwEgwuC7RfNudorD82hVVF7xuE,8
|
|
20
|
+
clizard-0.1.0.dist-info/RECORD,,
|