clizard 0.1.0__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.
clizard-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Erdogan Taskesen
4
+ clizard - Python package
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ #include REPONAME/data/*.zip
2
+ #include REPONAME/data/*.txt
clizard-0.1.0/PKG-INFO ADDED
@@ -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
+ [![Python](https://img.shields.io/pypi/pyversions/clizard)](https://img.shields.io/pypi/pyversions/clizard)
25
+ [![Pypi](https://img.shields.io/pypi/v/clizard)](https://pypi.org/project/clizard/)
26
+ [![Docs](https://img.shields.io/badge/Sphinx-Docs-Green)](https://erdogant.github.io/clizard/)
27
+ [![LOC](https://sloc.xyz/github/erdogant/clizard/?category=code)](https://github.com/erdogant/clizard/)
28
+ [![Downloads](https://static.pepy.tech/personalized-badge/clizard?period=month&units=international_system&left_color=grey&right_color=brightgreen&left_text=PyPI%20downloads/month)](https://pepy.tech/project/clizard)
29
+ [![Downloads](https://static.pepy.tech/personalized-badge/clizard?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/clizard)
30
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/erdogant/clizard/blob/master/LICENSE)
31
+ [![Forks](https://img.shields.io/github/forks/erdogant/clizard.svg)](https://github.com/erdogant/clizard/network)
32
+ [![Issues](https://img.shields.io/github/issues/erdogant/clizard.svg)](https://github.com/erdogant/clizard/issues)
33
+ [![Project Status](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
34
+ [![DOI](https://zenodo.org/badge/231843440.svg)](https://zenodo.org/badge/latestdoi/231843440)
35
+ [![Medium](https://img.shields.io/badge/Medium-Blog-black)](https://erdogant.github.io/clizard/pages/html/Documentation.html#medium-blog)
36
+ [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://erdogant.github.io/clizard/pages/html/Documentation.html#colab-notebook)
37
+ [![Donate](https://img.shields.io/badge/Support%20this%20project-grey.svg?logo=github%20sponsors)](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
+ [![Buy me a coffee](https://img.buymeacoffee.com/button-api/?text=Buy+me+a+coffee&emoji=&slug=erdogant&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https://www.buymeacoffee.com/erdogant)
@@ -0,0 +1,151 @@
1
+ [![Python](https://img.shields.io/pypi/pyversions/clizard)](https://img.shields.io/pypi/pyversions/clizard)
2
+ [![Pypi](https://img.shields.io/pypi/v/clizard)](https://pypi.org/project/clizard/)
3
+ [![Docs](https://img.shields.io/badge/Sphinx-Docs-Green)](https://erdogant.github.io/clizard/)
4
+ [![LOC](https://sloc.xyz/github/erdogant/clizard/?category=code)](https://github.com/erdogant/clizard/)
5
+ [![Downloads](https://static.pepy.tech/personalized-badge/clizard?period=month&units=international_system&left_color=grey&right_color=brightgreen&left_text=PyPI%20downloads/month)](https://pepy.tech/project/clizard)
6
+ [![Downloads](https://static.pepy.tech/personalized-badge/clizard?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/clizard)
7
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/erdogant/clizard/blob/master/LICENSE)
8
+ [![Forks](https://img.shields.io/github/forks/erdogant/clizard.svg)](https://github.com/erdogant/clizard/network)
9
+ [![Issues](https://img.shields.io/github/issues/erdogant/clizard.svg)](https://github.com/erdogant/clizard/issues)
10
+ [![Project Status](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
11
+ [![DOI](https://zenodo.org/badge/231843440.svg)](https://zenodo.org/badge/latestdoi/231843440)
12
+ [![Medium](https://img.shields.io/badge/Medium-Blog-black)](https://erdogant.github.io/clizard/pages/html/Documentation.html#medium-blog)
13
+ [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://erdogant.github.io/clizard/pages/html/Documentation.html#colab-notebook)
14
+ [![Donate](https://img.shields.io/badge/Support%20this%20project-grey.svg?logo=github%20sponsors)](https://erdogant.github.io/clizard/pages/html/Documentation.html#)
15
+
16
+ <div>
17
+ <a href="https://erdogant.github.io/clizard/">
18
+ <img src="https://raw.githubusercontent.com/erdogant/clizard/master/docs/figs/logo.png"
19
+ width="250"
20
+ align="left" />
21
+ </a>
22
+ clizard is a Python package for probability density fitting of univariate distributions for random variables.
23
+ 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.
24
+ It can be used for parametric, non-parametric, and discrete distributions. ⭐️Star it if you like it⭐️
25
+ </div>
26
+
27
+ ---
28
+
29
+ ### Key Features
30
+
31
+ | Feature | Description |
32
+ |--------|-------------|
33
+ | [**Parametric Fitting**](https://erdogant.github.io/clizard/pages/html/Parametric.html) | Fit distributions on empirical data X. |
34
+ | [**Non-Parametric Fitting**](https://erdogant.github.io/clizard/pages/html/Quantile.html) | Fit distributions on empirical data X using non-parametric approaches (quantile, percentiles). |
35
+ | [**Discrete Fitting**](https://erdogant.github.io/clizard/pages/html/Discrete.html) | Fit distributions on empirical data X using binomial distribution. |
36
+ | [**Predict**](https://erdogant.github.io/clizard/pages/html/Functions.html#module-clizard.clizard.clizard.predict) | Compute probabilities for response variables y. |
37
+ | [**Synthetic Data**](https://erdogant.github.io/clizard/pages/html/Generate.html) | Generate synthetic data. |
38
+ | [**Plots**](https://erdogant.github.io/clizard/pages/html/Plots.html) | Varoius plotting functionalities. |
39
+
40
+ ---
41
+
42
+ ### Resources and Links
43
+ - **Example Notebooks:** [Examples](https://erdogant.github.io/clizard/pages/html/Documentation.html)
44
+ - **Blog Posts:** [Medium](https://erdogant.github.io/clizard/pages/html/Documentation.html#medium-blog)
45
+ - **Documentation:** [Website](https://erdogant.github.io/clizard)
46
+ - **Bug Reports and Feature Requests:** [GitHub Issues](https://github.com/erdogant/clizard/issues)
47
+
48
+ ---
49
+
50
+ ### Background
51
+
52
+ * For the parametric approach, The clizard library can determine the best fit across 89 theoretical distributions.
53
+ To score the fit, one of the scoring statistics for the good-of-fitness test can be used used, such as RSS/SSE, Wasserstein,
54
+ Kolmogorov-Smirnov (KS), or Energy. After finding the best-fitted theoretical distribution, the loc, scale,
55
+ and arg parameters are returned, such as mean and standard deviation for normal distribution.
56
+
57
+ * For the non-parametric approach, the clizard library contains two methods, the quantile and percentile method.
58
+ Both methods assume that the data does not follow a specific probability distribution. In the case of the quantile method,
59
+ the quantiles of the data are modeled whereas for the percentile method, the percentiles are modeled.
60
+
61
+ ---
62
+
63
+ ### Installation
64
+
65
+ ##### Install clizard from PyPI
66
+ ```bash
67
+ pip install clizard
68
+ ```
69
+
70
+ ##### Install from Github source
71
+ ```bash
72
+ pip install git+https://github.com/erdogant/clizard
73
+ ```
74
+
75
+ ##### Imort Library
76
+ ```python
77
+ import clizard
78
+ print(clizard.__version__)
79
+
80
+ # Import library
81
+ from clizard import clizard
82
+ ```
83
+
84
+ <hr>
85
+
86
+ ### Examples
87
+
88
+ ##### [Example: Quick start to find best fit for your input data](https://erdogant.github.io/clizard/pages/html/Examples.html#)
89
+
90
+ ```python
91
+
92
+ # [clizard] >INFO> fit
93
+ # [clizard] >INFO> transform
94
+ # [clizard] >INFO> [norm ] [0.00 sec] [RSS: 0.00108326] [loc=-0.048 scale=1.997]
95
+ # [clizard] >INFO> [expon ] [0.00 sec] [RSS: 0.404237] [loc=-6.897 scale=6.849]
96
+ # [clizard] >INFO> [pareto ] [0.00 sec] [RSS: 0.404237] [loc=-536870918.897 scale=536870912.000]
97
+ # [clizard] >INFO> [dweibull ] [0.06 sec] [RSS: 0.0115552] [loc=-0.031 scale=1.722]
98
+ # [clizard] >INFO> [t ] [0.59 sec] [RSS: 0.00108349] [loc=-0.048 scale=1.997]
99
+ # [clizard] >INFO> [genextreme] [0.17 sec] [RSS: 0.00300806] [loc=-0.806 scale=1.979]
100
+ # [clizard] >INFO> [gamma ] [0.05 sec] [RSS: 0.00108459] [loc=-1862.903 scale=0.002]
101
+ # [clizard] >INFO> [lognorm ] [0.32 sec] [RSS: 0.00121597] [loc=-110.597 scale=110.530]
102
+ # [clizard] >INFO> [beta ] [0.10 sec] [RSS: 0.00105629] [loc=-16.364 scale=32.869]
103
+ # [clizard] >INFO> [uniform ] [0.00 sec] [RSS: 0.287339] [loc=-6.897 scale=14.437]
104
+ # [clizard] >INFO> [loggamma ] [0.12 sec] [RSS: 0.00109042] [loc=-370.746 scale=55.722]
105
+ # [clizard] >INFO> Compute confidence intervals [parametric]
106
+ # [clizard] >INFO> Compute significance for 9 samples.
107
+ # [clizard] >INFO> Multiple test correction method applied: [fdr_bh].
108
+ # [clizard] >INFO> Create PDF plot for the parametric method.
109
+ # [clizard] >INFO> Mark 5 significant regions
110
+ # [clizard] >INFO> Estimated distribution: beta [loc:-16.364265, scale:32.868811]
111
+ ```
112
+
113
+ <p align="left">
114
+ <a href="https://erdogant.github.io/clizard/pages/html/Examples.html#make-predictions">
115
+ <img src="https://github.com/erdogant/clizard/blob/master/docs/figs/example_figP4c.png" width="450" />
116
+ </a>
117
+ </p>
118
+
119
+
120
+ #
121
+
122
+ ##### [Example: Plot summary of the tested distributions](https://erdogant.github.io/clizard/pages/html/Examples.html#plot-rss)
123
+
124
+ After we have a fitted model, we can make some predictions using the theoretical distributions.
125
+ After making some predictions, we can plot again but now the predictions are automatically included.
126
+
127
+ <p align="left">
128
+ <a href="https://erdogant.github.io/clizard/pages/html/Examples.html#plot-rss">
129
+ <img src="https://github.com/erdogant/clizard/blob/master/docs/figs/fig1_summary.png" width="450" />
130
+ </a>
131
+ </p>
132
+
133
+ #
134
+
135
+ <hr>
136
+
137
+ ### Contributors
138
+ Setting up and maintaining bnlearn has been possible thanks to users and contributors. Thanks to:
139
+
140
+ <p align="left">
141
+ <a href="https://github.com/erdogant/clizard/graphs/contributors">
142
+ <img src="https://contrib.rocks/image?repo=erdogant/clizard" />
143
+ </a>
144
+ </p>
145
+
146
+ ### Maintainer
147
+ * Erdogan Taskesen, github: [erdogant](https://github.com/erdogant)
148
+ * Contributions are welcome.
149
+ * 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>.
150
+
151
+ [![Buy me a coffee](https://img.buymeacoffee.com/button-api/?text=Buy+me+a+coffee&emoji=&slug=erdogant&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https://www.buymeacoffee.com/erdogant)
@@ -0,0 +1,6 @@
1
+ from .core import GenericCLI
2
+ from .config import Config
3
+ from .cli_args import parse_args, build_parser, auto_cli
4
+
5
+ __all__ = ["GenericCLI", "Config", "parse_args", "build_parser", "auto_cli"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,146 @@
1
+ """Default console-script entry point: `clizard`.
2
+
3
+ Run with no args inside a repo to auto-discover everything:
4
+ - the repo's main() (via __main__.py / main.py signature)
5
+ - a Snakemake workflow (Snakefile + config.yaml), if present
6
+ - git remote info (.git/config)
7
+ - pyproject.toml metadata (name, docs url, requirements)
8
+ - .clizard overrides (ascii art, accent color, tips, app name, docs url)
9
+
10
+ Falls back to a bare GenericCLI if nothing is discoverable.
11
+ """
12
+ import subprocess
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ from .cli_args import parse_args
17
+ from .core import GenericCLI
18
+ from .git_info import get_git_info
19
+ from .project_info import get_project_info
20
+ from .clizard_file import ensure_clizard_file
21
+ from .discover import (
22
+ find_main, settings_from_main,
23
+ find_snakemake_config, settings_from_snakemake_config, write_snakemake_config,
24
+ )
25
+ from .scaffold import generate_clizard_main
26
+
27
+
28
+ def build_cli(repo_path="."):
29
+ repo_path = str(Path(repo_path).resolve())
30
+
31
+ git_info = get_git_info(repo_path)
32
+ proj_info = get_project_info(repo_path)
33
+ clz = ensure_clizard_file(repo_path)
34
+
35
+ app_name = clz.get("app_name") or proj_info.get("name") or git_info.get("github_repo") or "clizard"
36
+ docs_url = clz.get("docs_url") or proj_info.get("docs_url")
37
+
38
+ module, main_func, entry_file = find_main(repo_path)
39
+ main_settings, arg_meta, call_style = settings_from_main(main_func) if main_func else ({}, {}, "kwargs")
40
+
41
+ sm_config_path = find_snakemake_config(repo_path)
42
+ sm_settings = settings_from_snakemake_config(sm_config_path) if sm_config_path else {}
43
+
44
+ settings = {
45
+ "path": repo_path,
46
+ "docs_url": docs_url or "",
47
+ **main_settings,
48
+ **sm_settings,
49
+ }
50
+
51
+ has_run_target = main_func is not None or sm_config_path is not None
52
+ default_tips = ["/wizard", "/run", "/settings", "/help"] if has_run_target else ["/settings", "/help"]
53
+
54
+ cli = GenericCLI(
55
+ app_name=app_name,
56
+ ascii_art=clz.get("ascii_art"),
57
+ accent_color=clz.get("accent_color", "#d97757"),
58
+ settings=settings,
59
+ tips=clz.get("tips") if clz.get("tips") else default_tips,
60
+ updates=clz.get("updates"),
61
+ )
62
+ cli.arg_meta = arg_meta
63
+
64
+ # Config persists settings across runs (so a value the user explicitly
65
+ # set via /settings, e.g. username="test", survives between sessions).
66
+ # But that means a key first discovered with no default (None) stays
67
+ # None forever in the persisted store, even after main()'s source gains
68
+ # an explicit default later (e.g. clean=True, verbosity=3). Backfill: if
69
+ # the persisted value is still None, adopt the freshly discovered
70
+ # default instead of leaving it stuck.
71
+ for key, val in {**main_settings, **sm_settings}.items():
72
+ if cli.config.get(key) is None and val is not None:
73
+ cli.config.set(key, val)
74
+
75
+ # Only show /run if there's actually something to run.
76
+ if not has_run_target:
77
+ cli._commands.pop("/run", None)
78
+ if "/run" in cli.tips:
79
+ cli.tips = [t for t in cli.tips if t != "/run"]
80
+
81
+ if has_run_target:
82
+ @cli.command("/run", "Run the project's main()/Snakemake workflow with current settings")
83
+ def _cmd_run(prompt):
84
+ if main_func is not None:
85
+ cli.status("Running main()...")
86
+ if call_style == "argv":
87
+ argv = ["clizard"]
88
+ for name, meta in arg_meta.items():
89
+ flag = meta.get("flag")
90
+ if not flag:
91
+ continue
92
+ val = cli.config.get(name)
93
+ if val is None:
94
+ continue
95
+ if meta.get("is_flag"):
96
+ if val:
97
+ argv.append(flag)
98
+ else:
99
+ argv.extend([flag, str(val)])
100
+ old_argv = sys.argv
101
+ sys.argv = argv
102
+ try:
103
+ result = main_func()
104
+ finally:
105
+ sys.argv = old_argv
106
+ else:
107
+ call_kwargs = {k: cli.config.get(k) for k in main_settings}
108
+ result = main_func(**call_kwargs)
109
+ if result is not None:
110
+ cli.assistant_message(str(result))
111
+
112
+ if sm_config_path is not None:
113
+ current_sm = {k: cli.config.get(k) for k in sm_settings}
114
+ write_snakemake_config(sm_config_path, current_sm)
115
+ cmd = ["snakemake", "--configfile", str(sm_config_path), "--cores", "all"]
116
+ console_cmd = " ".join(cmd)
117
+ cli.status(f"Running: {console_cmd}")
118
+ try:
119
+ result = subprocess.run(cmd, cwd=repo_path, capture_output=True, text=True)
120
+ output = (result.stdout + result.stderr).strip()
121
+ cli.assistant_message(f"```\n$ {console_cmd}\n{output[-2000:]}\n```")
122
+ except FileNotFoundError:
123
+ cli.error("snakemake is not installed or not on PATH.")
124
+
125
+ if main_func is not None:
126
+ @cli.command("/scaffold", "Generate clizard_main.py wrapping this project's main()")
127
+ def _cmd_scaffold(prompt):
128
+ try:
129
+ out_path = generate_clizard_main(repo_path)
130
+ cli.assistant_message(f"Wrote `{out_path}`. Run it with:\n\n```\npython {out_path.name}\n```")
131
+ except RuntimeError as e:
132
+ cli.error(str(e))
133
+
134
+ return cli
135
+
136
+
137
+ def main():
138
+ args = parse_args(app_name="clizard")
139
+ cli = build_cli(repo_path=args.path or ".")
140
+ if args.model:
141
+ cli.config.set("model", args.model)
142
+ cli.run()
143
+
144
+
145
+ if __name__ == "__main__":
146
+ main()
@@ -0,0 +1,95 @@
1
+ """Argument parsing for GenericCLI-based tools."""
2
+ import argparse
3
+
4
+
5
+ def build_parser(app_name="Generic CLI", extra_args=None):
6
+ """Create an argparse.ArgumentParser with common options.
7
+
8
+ extra_args: list of dicts like {"flags": ["--foo"], "kwargs": {...}}
9
+ to let downstream scripts add their own arguments.
10
+ """
11
+ parser = argparse.ArgumentParser(prog=app_name, description=f"{app_name} - interactive CLI")
12
+ parser.add_argument("--model", default=None, help="Model name/identifier to use")
13
+ parser.add_argument("--path", default=None, help="Working/project path")
14
+ parser.add_argument("--config", default=None, help="Path to a JSON config file")
15
+ parser.add_argument("--name", default=None, help="Override the displayed app name")
16
+
17
+ if extra_args:
18
+ for arg in extra_args:
19
+ parser.add_argument(*arg["flags"], **arg.get("kwargs", {}))
20
+
21
+ return parser
22
+
23
+
24
+ def parse_args(app_name="Generic CLI", extra_args=None, argv=None):
25
+ parser = build_parser(app_name, extra_args)
26
+ return parser.parse_args(argv)
27
+
28
+
29
+ def auto_cli(parser, args=None, app_name=None, handler=None, run_callback=None, config_path=None):
30
+ """Build a GenericCLI automatically from an existing argparse.ArgumentParser.
31
+
32
+ Every `--flag` already defined on `parser` becomes an editable setting:
33
+ its current value (parsed from argv, or its default) seeds the CLI's
34
+ `/settings` table, and its `choices`/`type`/`help` are kept so `/settings`
35
+ can validate and cast edits correctly.
36
+
37
+ Parameters
38
+ ----------
39
+ parser : argparse.ArgumentParser
40
+ An already-configured parser (e.g. the one built in your existing
41
+ `main()`), or just `parser` before calling `parse_args()` on it.
42
+ args : argparse.Namespace, optional
43
+ Pre-parsed args. If omitted, `parser.parse_args()` is called.
44
+ app_name : str, optional
45
+ Defaults to `parser.prog`.
46
+ handler : callable(prompt, cli) -> str, optional
47
+ Called for free-text input. If omitted, free-text input does nothing
48
+ special; use `run_callback` + a `/run` command instead (see below).
49
+ run_callback : callable(cli) -> str, optional
50
+ If given, a `/run` command is registered that calls
51
+ `run_callback(cli)` using the current settings, mirroring how you'd
52
+ call your script's `run(...)` function with `args.*`.
53
+ config_path : str, optional
54
+ Where to persist settings between sessions.
55
+
56
+ Returns
57
+ -------
58
+ GenericCLI
59
+ """
60
+ from .core import GenericCLI # local import avoids a circular import
61
+
62
+ if args is None:
63
+ args = parser.parse_args()
64
+
65
+ settings = {}
66
+ arg_meta = {}
67
+ for action in parser._actions:
68
+ dest = action.dest
69
+ if dest in ("help",) or isinstance(action, argparse._HelpAction):
70
+ continue
71
+ settings[dest] = getattr(args, dest, action.default)
72
+ arg_meta[dest] = {
73
+ "choices": list(action.choices) if action.choices else None,
74
+ "type": action.type,
75
+ "help": action.help,
76
+ }
77
+
78
+ cli = GenericCLI(
79
+ app_name=app_name or parser.prog or "CLI",
80
+ settings=settings,
81
+ config_path=config_path,
82
+ handler=handler,
83
+ tips=["/run", "/settings", "/docs", "/help"] if run_callback else ["/settings", "/help"],
84
+ )
85
+ cli.arg_meta = arg_meta # exposed for validation / display in /settings
86
+
87
+ if run_callback is not None:
88
+ @cli.command("/run", "Run the script with current settings")
89
+ def _cmd_run(prompt):
90
+ cli.status("Running...")
91
+ result = run_callback(cli)
92
+ if result is not None:
93
+ cli.assistant_message(str(result))
94
+
95
+ return cli
@@ -0,0 +1,55 @@
1
+ """Read/write the project-local .clizard metadata file.
2
+
3
+ This stores anything that can't be auto-discovered from git/pyproject:
4
+ ascii_art, app_name override, docs_url override, accent_color, tips, etc.
5
+ """
6
+ import json
7
+ from pathlib import Path
8
+
9
+ DEFAULT_ASCII = r"""
10
+ .-.
11
+ |o o|
12
+ | = |
13
+ /|___|\
14
+ """
15
+
16
+ CLIZARD_FILENAME = ".clizard"
17
+
18
+
19
+ def load_clizard_file(repo_path="."):
20
+ """Return the parsed .clizard JSON dict, or {} if absent/invalid."""
21
+ path = Path(repo_path) / CLIZARD_FILENAME
22
+ if not path.exists():
23
+ return {}
24
+ try:
25
+ with open(path, "r") as f:
26
+ return json.load(f)
27
+ except (json.JSONDecodeError, OSError):
28
+ return {}
29
+
30
+
31
+ def save_clizard_file(data: dict, repo_path="."):
32
+
33
+ path = Path(repo_path) / CLIZARD_FILENAME
34
+ with open(path, "w") as f:
35
+ json.dump(data, f, indent=2)
36
+ return path
37
+
38
+
39
+ def ensure_clizard_file(repo_path=".", **overrides):
40
+ """Create a .clizard file with sane defaults if one doesn't exist yet."""
41
+ path = Path(repo_path) / CLIZARD_FILENAME
42
+ if path.exists():
43
+ return load_clizard_file(repo_path)
44
+
45
+ data = {
46
+ "app_name": None, # None -> auto from pyproject/git
47
+ "ascii_art": DEFAULT_ASCII,
48
+ "docs_url": None, # None -> auto from pyproject, else docs/index.html
49
+ "accent_color": "#d97757",
50
+ "tips": ["/wizard", "/run", "/settings", "/docs", "/help"],
51
+ "updates": [],
52
+ }
53
+ data.update(overrides)
54
+ save_clizard_file(data, repo_path)
55
+ return data