-
Notifications
You must be signed in to change notification settings - Fork 57
Organize CLI directory + new CLI for generating item.yaml files #906
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| ## Available Commands | ||
| (Explore more advanced options in the code, this is basic usage demonstration) | ||
|
|
||
| ### generate-item-yaml | ||
| Generate an `item.yaml` file (basic draft) in the appropriate directory from a Jinja2 template | ||
|
|
||
| Usage: | ||
| `python -m cli.cli generate-item-yaml TYPE NAME` | ||
|
|
||
| Example: | ||
| `python -m cli.cli generate-item-yaml function aggregate` | ||
|
|
||
| --- | ||
|
|
||
| ### item-to-function | ||
| Creates a `function.yaml` file based on a provided `item.yaml` file. | ||
|
|
||
| Usage: | ||
| `python -m cli.cli item-to-function --item-path PATH` | ||
|
|
||
| Example: | ||
| `python -m cli.cli item-to-function --item-path functions/src/aggregate` | ||
|
|
||
| --- | ||
|
|
||
| ### function-to-item | ||
| Creates a `item.yaml` file based on a provided `function.yaml` file. | ||
|
|
||
| Usage: | ||
| `python -m cli.cli function-to-item PATH` | ||
|
|
||
| Example: | ||
| `python -m cli.cli function-to-item --path functions/src/aggregate` | ||
|
|
||
| --- | ||
|
|
||
| ### run-tests | ||
| Run assets test suite. | ||
|
|
||
| Usage: | ||
| `python -m cli.cli run-tests -r PATH -s TYPE -fn NAME` | ||
|
|
||
| Example: | ||
| `python -m cli.cli run-tests -r functions/src/aggregate -s py -fn aggregate` | ||
|
|
||
| --- | ||
|
|
||
| ### build-marketplace | ||
| Build and push (create a PR) the updated marketplace/<TYPE> directory (e.g: marketplace/functions) | ||
|
|
||
| Usage: | ||
| `python -m cli.cli build-marketplace -s SOURCE-DIR -sn TYPE -m MARKETPLACE-DIR -c CHANNEL -v -f` | ||
|
|
||
| Example: | ||
| `python -m cli.cli build-marketplace -s ./functions/src -sn functions -m marketplace -c master -v -f` | ||
|
|
||
| --- | ||
|
|
||
| ### update-readme | ||
| Regenerate the `README.md` files in each of the asset directories (functions/modules). | ||
|
|
||
| Usage: | ||
| `python -m cli.cli update-readme --asset TYPE` | ||
|
|
||
| Example: | ||
| `python -m cli.cli update-readme --asset functions --asset modules` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import sys | ||
| from pathlib import Path | ||
| from datetime import datetime | ||
| import click | ||
| from jinja2 import Environment, FileSystemLoader | ||
|
|
||
| TEMPLATES = { | ||
| "function": "cli/utils/function_item_template.yaml.j2", | ||
| "module": "cli/utils/module_item_template.yaml.j2", | ||
| } | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.argument("type", type=click.Choice(list(TEMPLATES.keys()))) | ||
| @click.argument("name") | ||
| @click.option("--overwrite", is_flag=True, help="Replace existing file instead of raising an error.") | ||
| def generate_item_yaml(type: str, name: str, overwrite: bool = False): | ||
| """ | ||
| Generate an item.yaml file from a template. | ||
|
|
||
| type: one of the supported types (currently only `function` or `module`) | ||
| name: the function/module name (also used as the directory name) | ||
| overwrite: whether to overwrite existing item.yaml file | ||
| """ | ||
| # Construct the target path | ||
| path = Path(f"{type}s/src/{name}").resolve() | ||
| output_file = path / "item.yaml" | ||
|
|
||
| if not overwrite and output_file.exists(): | ||
| click.echo(f"Error: {output_file} already exists.", err=True) | ||
| sys.exit(1) | ||
|
|
||
| if not path.exists(): | ||
| click.echo(f"Error: {path} does not exist.", err=True) | ||
| sys.exit(1) | ||
|
|
||
| # Render parameters | ||
| params = { | ||
| "example": f"{name}.ipynb", | ||
| "generationDate": datetime.utcnow().strftime("%Y-%m-%d"), | ||
| "name": name, | ||
| "filename": f"{name}.py", | ||
| } | ||
|
|
||
| # Load and render template | ||
| env = Environment(loader=FileSystemLoader(".")) | ||
| template = env.get_template(TEMPLATES[type]) | ||
| rendered = template.render(params) | ||
|
|
||
| output_file.write_text(rendered) | ||
| click.echo(f"Created {output_file}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| generate_item_yaml() | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| apiVersion: v1 | ||
| categories: [] {# List of category names #} | ||
| description: '' {# Short description #} | ||
| doc: '' {# Path to README.md if exists #} | ||
| example: {{ example|default('') }} {# Path to example notebook #} | ||
| generationDate: {{ generationDate|default('') }} {# Automatically generated ISO8086 datetime #} | ||
| hidden: false {# Hide function from the UI #} | ||
| icon: '' {# Path to icon file #} | ||
| labels: {# Key values label pairs #} | ||
| author: Iguazio | ||
| maintainers: [] {# List of maintainers #} | ||
| mlrunVersion: '' {# Function’s MLRun version requirement, should follow python’s versioning schema #} | ||
| name: {{ name|default('') }} {# Function name #} | ||
| platformVersion: '' {# Function’s Iguazio version requirement, should follow python’s versioning schema #} | ||
| spec: | ||
| filename: {{ filename|default('') }} {# Implementation file #} | ||
| handler: '' {# Handler function name #} | ||
| image: mlrun/mlrun {# Base image name #} | ||
| kind: '' {# Function kind #} | ||
| requirements: [] {# List of Pythonic library requirements #} | ||
| url: '' | ||
| version: 1.0.0 {# Function version, should follow standard semantic versioning schema #} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: v1 | ||
| categories: [] {# List of category names #} | ||
| description: '' {# Short description #} | ||
| example: {{ example|default('') }} {# Path to example notebook #} | ||
| generationDate: {{ generationDate|default('') }} {# Automatically generated ISO8086 datetime #} | ||
| hidden: false {# Hide Module from the UI #} | ||
| labels: | ||
| author: Iguazio | ||
| mlrunVersion: '' {# Module’s MLRun version requirement, should follow python’s versioning schema #} | ||
| name: {{ name|default('') }} {# Module name #} | ||
| spec: | ||
| filename: {{ filename|default('') }} {# Implementation file #} | ||
| image: mlrun/mlrun {# Base image name #} | ||
| kind: '' {# Module kind #} | ||
| requirements: [] {# List of Pythonic library requirements #} | ||
| version: 1.0.0 {# Module version, should follow standard semantic versioning schema #} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ wheel | |
| bs4 | ||
| mlrun>=1.0.0 | ||
| jinja2~=3.1.2 | ||
| click>=8.0 | ||
| pipenv | ||
| myst_nb | ||
| black>=24.3.0 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.