Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classg multi kind #2030

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions class_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

###### Install poetry environment

- Using [pipx](https://github.com/pypa/pipx) (recommended)

```bash
pipx install openshift-python-wrapper
```

- Using `pip`

```bash
python3 -m pip install openshift-python-wrapper
```

- Using [poetry](https://python-poetry.org/) (For development)

```bash
poetry install
```
Expand All @@ -22,7 +36,14 @@ if type class-generator > /dev/null; then eval "$(_CLASS_GENERATOR_COMPLETE=zsh_

###### Call the script

- All available options:

```bash
class-generator --help
```

- Running in normal mode with `--kind` flags:
- `--kind` can process multiple kinds at the same command, pass `--kind <kind1>,<kind2>,<kind3>`

```bash
class-generator --kind <kind>
Expand Down
52 changes: 40 additions & 12 deletions class_generator/class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import click
import re

from concurrent.futures import Future, ThreadPoolExecutor, as_completed
import cloup
from cloup.constraints import If, IsSet, accept_none, require_one
from pyhelper_utils.shell import run_command
Expand Down Expand Up @@ -697,7 +698,12 @@ def generate_class_generator_tests() -> None:
"-k",
"--kind",
type=click.STRING,
help="The Kind to generate the class for, Needs working cluster with admin privileges",
help="""
\b
The Kind to generate the class for, Needs working cluster with admin privileges.
multiple kinds can be sent separated by comma (without psaces)
Example: -k Deployment,Pod,ConfigMap
""",
)
@cloup.option(
"-o",
Expand Down Expand Up @@ -755,18 +761,40 @@ def main(
pdb: bool,
add_tests: bool,
):
_ = pdb
_ = pdb # Used by `function_runner_with_pdb`

_kwargs: Dict[str, Any] = {
"overwrite": overwrite,
"interactive": interactive,
"dry_run": dry_run,
"debug": debug,
"process_debug_file": debug_file,
"output_file": output_file,
"add_tests": add_tests,
}

class_generator(
kind=kind,
overwrite=overwrite,
interactive=interactive,
dry_run=dry_run,
debug=debug,
process_debug_file=debug_file,
output_file=output_file,
add_tests=add_tests,
)
if interactive or debug_file:
class_generator(**_kwargs)

else:
kinds: List[str] = kind.split(",")
futures: List[Future] = []

with ThreadPoolExecutor() as executor:
for _kind in kinds:
_kwargs["kind"] = _kind
if pdb or len(kinds) == 1:
class_generator(**_kwargs)

else:
executor.submit(
class_generator,
**_kwargs,
)

for _ in as_completed(futures):
# wait for all tasks to complete
pass

if add_tests:
generate_class_generator_tests()
Expand Down
10 changes: 5 additions & 5 deletions class_generator/tests/test_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
os.path.join(TESTS_MANIFESTS_DIR, "deployment", "deployment_debug.json"),
os.path.join(TESTS_MANIFESTS_DIR, "deployment", "deployment_res.py"),
),
(
"image_content_source_policy",
os.path.join(TESTS_MANIFESTS_DIR, "image_content_source_policy", "image_content_source_policy_debug.json"),
os.path.join(TESTS_MANIFESTS_DIR, "image_content_source_policy", "image_content_source_policy_res.py"),
),
(
"pod",
os.path.join(TESTS_MANIFESTS_DIR, "pod", "pod_debug.json"),
Expand All @@ -41,11 +46,6 @@
os.path.join(TESTS_MANIFESTS_DIR, "secret", "secret_debug.json"),
os.path.join(TESTS_MANIFESTS_DIR, "secret", "secret_res.py"),
),
(
"image_content_source_policy",
os.path.join(TESTS_MANIFESTS_DIR, "image_content_source_policy", "image_content_source_policy_debug.json"),
os.path.join(TESTS_MANIFESTS_DIR, "image_content_source_policy", "image_content_source_policy_res.py"),
),
),
)
def test_parse_explain(tmpdir_factory, kind, debug_file, result_file):
Expand Down
Loading