-
Notifications
You must be signed in to change notification settings - Fork 59
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
vdk-jupyter: add iPython extension #1482
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e04bfe
Add ipython extension
duyguHsnHsn c1715a9
changes on loading path in reload_job function
duyguHsnHsn 9f4aded
Add tests and edit README and requirements
duyguHsnHsn a210a86
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cd52504
build(deps): bump graphql-java-extended-scalars (#1474)
dependabot[bot] b437316
build(deps): bump byte-buddy (#1477)
dependabot[bot] a08fc7d
build(deps): bump nimbus-jose-jwt (#1476)
dependabot[bot] 4099efe
build(deps): bump mockito-core from 4.10.0 to 4.11.0 in /projects/con…
dependabot[bot] 2f6d138
vdk-jobs-troubleshooting: Add thread-dump utility (#1456)
doks5 440e245
vdk-jobs-troubleshooting: release the plugin (#1481)
be6c667
build(deps): bump nimbus-jose-jwt (#1479)
dependabot[bot] 50531c8
Change development status, delete unnedded testjobs, small changes on…
duyguHsnHsn 4b58c65
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
image: "python:3.7" | ||
|
||
.build-vdk-ipython-ext: | ||
variables: | ||
PLUGIN_NAME: vdk-ipython-ext | ||
extends: .build-plugin | ||
|
||
build-py37-vdk-ipython-ext: | ||
extends: .build-vdk-ipython-ext | ||
image: "python:3.7" | ||
|
||
|
||
build-py38-vdk-ipython-ext: | ||
extends: .build-vdk-ipython-ext | ||
image: "python:3.8" | ||
|
||
build-py39-vdk-ipython-ext: | ||
extends: .build-vdk-ipython-ext | ||
image: "python:3.9" | ||
|
||
build-py310-vdk-ipython-ext: | ||
extends: .build-vdk-ipython-ext | ||
image: "python:3.10" | ||
|
||
build-py311-vdk-ipython-ext: | ||
extends: .build-vdk-ipython-ext | ||
image: "python:3.11" | ||
|
||
release-vdk-ipython-ext: | ||
variables: | ||
PLUGIN_NAME: vdk-ipython-ext | ||
extends: .release-plugin |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# ipython-ext | ||
|
||
Ipython extension for VDK | ||
|
||
This extension introduces a magic command for Jupyter. | ||
The command enables the user to load job_input for his current data job and use it freely while working with Jupyter. | ||
|
||
See more about magic commands: https://ipython.readthedocs.io/en/stable/interactive/magics.html | ||
|
||
|
||
## Usage | ||
To use the extension it must be firstly installed with pip as a python package. | ||
Then to load the extension in Jupyter the user should use: | ||
``` | ||
%reload_ext vdk_ipython_ext | ||
``` | ||
And to load the job_input: | ||
``` | ||
%reload_job_input | ||
``` | ||
The %reload_job_input magic can be used with arguments such as passing the job's path with --path | ||
or giving the job a new with --name, etc. | ||
|
||
### Example | ||
The output of this example is "myjob" | ||
``` | ||
%reload_ext vdk_ipython_ext | ||
|
||
%reload_job_input --name=myjob | ||
|
||
job_input.get_name() | ||
``` | ||
|
||
### Build and testing | ||
|
||
``` | ||
pip install -r requirements.txt | ||
pip install -e . | ||
pytest | ||
``` | ||
|
||
In VDK repo [../build-plugin.sh](https://github.com/vmware/versatile-data-kit/tree/main/projects/vdk-plugins/build-plugin.sh) script can be used also. | ||
|
||
|
||
#### Note about the CICD: | ||
|
||
.plugin-ci.yaml is needed only for plugins part of [Versatile Data Kit Plugin repo](https://github.com/vmware/versatile-data-kit/tree/main/projects/vdk-plugins). | ||
|
||
The CI/CD is separated in two stages, a build stage and a release stage. | ||
The build stage is made up of a few jobs, all which inherit from the same | ||
job configuration and only differ in the Python version they use (3.7, 3.8, 3.9, 3.10 and 3.11). | ||
They run according to rules, which are ordered in a way such that changes to a | ||
plugin's directory trigger the plugin CI, but changes to a different plugin does not. |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# this file is used to provide testing requirements | ||
# for requirements (dependencies) needed during and after installation of the plugin see (and update) setup.py install_requires section | ||
|
||
IPython | ||
|
||
pytest | ||
vdk-core | ||
vdk-test-utils |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import pathlib | ||
|
||
import setuptools | ||
|
||
|
||
__version__ = "0.1.0" | ||
|
||
setuptools.setup( | ||
name="vdk-ipython-ext", | ||
version=__version__, | ||
url="https://github.com/vmware/versatile-data-kit", | ||
description="Ipython extension for VDK", | ||
long_description=pathlib.Path("README.md").read_text(), | ||
long_description_content_type="text/markdown", | ||
install_requires=["vdk-core"], | ||
package_dir={"": "src"}, | ||
packages=setuptools.find_namespace_packages(where="src"), | ||
entry_points={"vdk.plugin.run": ["ipython-ext = vdk_ipython_ext"]}, | ||
classifiers=[ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Framework :: IPython", | ||
], | ||
) |
45 changes: 45 additions & 0 deletions
45
projects/vdk-plugins/vdk-ipython-ext/src/vdk_ipython_ext.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
import pathlib | ||
|
||
from IPython import get_ipython | ||
from IPython.core.magic_arguments import argument | ||
from IPython.core.magic_arguments import magic_arguments | ||
from IPython.core.magic_arguments import parse_argstring | ||
from vdk.internal.builtin_plugins.run.standalone_data_job import ( | ||
StandaloneDataJobFactory, | ||
) | ||
|
||
|
||
def load_ipython_extension(ipython): | ||
""" | ||
IPython will look for this function specifically. | ||
See https://ipython.readthedocs.io/en/stable/config/extensions/index.html | ||
""" | ||
ipython.register_magic_function(magic_load_job, magic_name="reload_job_input") | ||
|
||
|
||
@magic_arguments() | ||
@argument("-p", "--path", type=str, default=None) | ||
@argument("-n", "--name", type=str, default=None) | ||
@argument("-a", "--arguments", type=str, default=None) | ||
@argument("-t", "--template", type=str, default=None) | ||
def magic_load_job(line: str): | ||
""" | ||
You can use %initialize_vdk_job line magic within your Notebook to reload the job_input variable | ||
for your current job | ||
See more for line magic: https://ipython.readthedocs.io/en/stable/interactive/magics.html | ||
""" | ||
args = parse_argstring(magic_load_job, line) | ||
load_job(args.path, args.name, args.arguments, args.template) | ||
|
||
|
||
def load_job( | ||
path: str = None, name: str = None, arguments: str = None, template: str = None | ||
): | ||
path = pathlib.Path(path) if path else pathlib.Path(os.getcwd()) | ||
with StandaloneDataJobFactory.create( | ||
data_job_directory=path, name=name, job_args=arguments, template_name=template | ||
) as job_input: | ||
get_ipython().push(variables={"job_input": job_input}) |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import pytest | ||
from IPython.core.error import UsageError | ||
from IPython.testing.globalipapp import start_ipython | ||
from vdk.api.job_input import IJobInput | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def session_ip(): | ||
yield start_ipython() | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def ip(session_ip): | ||
session_ip.run_line_magic(magic_name="load_ext", line="vdk_ipython_ext") | ||
yield session_ip | ||
session_ip.run_line_magic(magic_name="reset", line="-f") | ||
|
||
|
||
def test_load_job_input_with_no_arguments(ip): | ||
ip.run_line_magic(magic_name="reload_job_input", line="") | ||
assert ip.user_global_ns["job_input"] is not None | ||
assert isinstance(ip.user_global_ns["job_input"], IJobInput) | ||
|
||
|
||
def test_load_job_input_with_valid_argument(ip): | ||
ip.run_line_magic(magic_name="reload_job_input", line="--name=test") | ||
assert ip.user_global_ns["job_input"] is not None | ||
assert isinstance(ip.user_global_ns["job_input"], IJobInput) | ||
assert ip.user_global_ns["job_input"].get_name() == "test" | ||
|
||
|
||
def test_load_job_input_with_invalid_argument(ip): | ||
with pytest.raises( | ||
UsageError, match=r"unrecognized arguments: --invalid_arg=dummy" | ||
): | ||
ip.run_line_magic(magic_name="reload_job_input", line="--invalid_arg=dummy") |
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
45 changes: 45 additions & 0 deletions
45
...bleshooting/src/vdk/plugin/jobs_troubleshoot/troubleshoot_utilities/healthcheck_server.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import logging | ||
from http.server import HTTPServer | ||
from threading import Thread | ||
from typing import Any | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class HealthCheckServer: | ||
""" | ||
A class for creating an HTTP server for serving requests. | ||
""" | ||
|
||
def __init__(self, port: int, handler: Any = None): | ||
""" | ||
Initializes a new instance of the HealthCheckServer class. | ||
|
||
Parameters: | ||
port (int): The port number on which the server will listen for requests. | ||
handler (Any, optional): The request handler class. Defaults to SimpleHTTPRequestHandler. | ||
""" | ||
if handler: | ||
self._server = HTTPServer(("", port), handler) | ||
self._thread = Thread(target=self._server.serve_forever) | ||
log.error(f"Troubleshooting utility server started on port {port}.") | ||
else: | ||
log.error( | ||
"Troubleshooting utility handler not specified. Will not start the server." | ||
) | ||
|
||
def start(self): | ||
""" | ||
Starts the server. | ||
""" | ||
self._thread.start() | ||
|
||
def stop(self): | ||
""" | ||
Stops the server. | ||
""" | ||
self._server.shutdown() | ||
self._server.server_close() | ||
self._thread.join() |
Oops, something went wrong.
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.
would it not look a bit nicer if it was just
%reload_ext vdk
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.
In this way I get some errors with the imports and I thing it would be good to have a little difference since it is not loading the whole vdk but only a small part of it