-
Notifications
You must be signed in to change notification settings - Fork 903
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
Improve kedro run as a package #1423
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dce0a1d
Update template main
antonymilne 4f54f67
Return session.run in run command
antonymilne 1ead446
Add comments
antonymilne 4eee9dc
Try out on databricks
antonymilne 71e08de
Add type hint
antonymilne b89e446
Databricks debug
antonymilne dd1273f
Tidy
antonymilne 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 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 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 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
47 changes: 14 additions & 33 deletions
47
...es/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py
This file contains 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 |
---|---|---|
@@ -1,47 +1,28 @@ | ||
"""{{ cookiecutter.project_name }} file for ensuring the package is executable | ||
as `{{ cookiecutter.repo_name }}` and `python -m {{ cookiecutter.python_package }}` | ||
""" | ||
import importlib | ||
import sys | ||
from pathlib import Path | ||
|
||
from kedro.framework.cli.utils import KedroCliError, load_entry_points | ||
from kedro.framework.project import configure_project | ||
from kedro.framework.project import configure_project, run | ||
|
||
|
||
def _find_run_command(package_name): | ||
try: | ||
project_cli = importlib.import_module(f"{package_name}.cli") | ||
# fail gracefully if cli.py does not exist | ||
except ModuleNotFoundError as exc: | ||
if f"{package_name}.cli" not in str(exc): | ||
raise | ||
plugins = load_entry_points("project") | ||
run = _find_run_command_in_plugins(plugins) if plugins else None | ||
if run: | ||
# use run command from installed plugin if it exists | ||
return run | ||
# use run command from `kedro.framework.cli.project` | ||
from kedro.framework.cli.project import run | ||
# def main(args=None, **kwargs): | ||
# package_name = Path(__file__).parent.name | ||
# configure_project(package_name) | ||
# run(args or sys.argv[1:], **kwargs) | ||
# return 0 | ||
|
||
return run | ||
# fail badly if cli.py exists, but has no `cli` in it | ||
if not hasattr(project_cli, "cli"): | ||
raise KedroCliError(f"Cannot load commands from {package_name}.cli") | ||
return project_cli.run | ||
|
||
|
||
def _find_run_command_in_plugins(plugins): | ||
for group in plugins: | ||
if "run" in group.commands: | ||
return group.commands["run"] | ||
|
||
|
||
def main(*args, **kwargs): | ||
def main(**kwargs): | ||
package_name = Path(__file__).parent.name | ||
configure_project(package_name) | ||
run = _find_run_command(package_name) | ||
run(*args, **kwargs) | ||
if kwargs: | ||
run(**kwargs) | ||
else: | ||
run(sys.argv[1:]) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
sys.exit(main()) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is unfinished? as I can see in the other
__main__.py
the result ofsession.run
is return but here it doesn't return the output