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

Get version using restAPI #2242

Open
wants to merge 9 commits into
base: feature_branch/remove-experiment-tracking
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@ jobs:
- name: Run security scan
run: make security-scan

- name: Verify GraphQL schema is up to date
run: make schema-check

- name: Run Python formatters and linters
run: make format-check lint-check
2 changes: 0 additions & 2 deletions package/kedro_viz/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from kedro_viz.api.rest.responses.utils import EnhancedORJSONResponse
from kedro_viz.integrations.kedro import telemetry as kedro_telemetry

from .graphql.router import router as graphql_router
from .rest.router import router as rest_router

_HTML_DIR = Path(__file__).parent.parent.absolute() / "html"
Expand Down Expand Up @@ -63,7 +62,6 @@ def create_api_app_from_project(
"""
app = _create_base_api_app()
app.include_router(rest_router)
app.include_router(graphql_router)

# Check for html directory existence.
if Path(_HTML_DIR).is_dir():
Expand Down
1 change: 0 additions & 1 deletion package/kedro_viz/api/graphql/__init__.py

This file was deleted.

18 changes: 0 additions & 18 deletions package/kedro_viz/api/graphql/router.py

This file was deleted.

39 changes: 0 additions & 39 deletions package/kedro_viz/api/graphql/schema.py

This file was deleted.

12 changes: 0 additions & 12 deletions package/kedro_viz/api/graphql/types.py

This file was deleted.

43 changes: 43 additions & 0 deletions package/kedro_viz/api/rest/responses/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""`kedro_viz.api.rest.responses.version` contains response classes
and utility functions for the `/version` REST endpoint"""

from pydantic import ConfigDict

from kedro_viz import __version__
from kedro_viz.api.rest.responses.base import BaseAPIResponse
from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version


class VersionAPIResponse(BaseAPIResponse):
"""
VersionAPIResponse is a subclass of BaseAPIResponse that represents the response structure for version API.

Attributes:
installed (str): The installed version of the Kedro Viz package.
is_outdated (bool): Whether the installed version is outdated.
latest (str): The latest available version of the Kedro Viz package.
"""

installed: str
is_outdated: bool
latest: str
model_config = ConfigDict(
json_schema_extra={
"installed": __version__,
"is_outdated": False,
"latest": "0.0.0",
}
)


def get_version_response():
"""API response for `/api/version`."""
installed_version = str(__version__)
latest_version = str(get_latest_version())
is_outdated = is_running_outdated_version(installed_version, latest_version)

return VersionAPIResponse(
installed=installed_version,
is_outdated=is_outdated,
latest=latest_version,
)
12 changes: 12 additions & 0 deletions package/kedro_viz/api/rest/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
GraphAPIResponse,
get_pipeline_response,
)
from kedro_viz.api.rest.responses.version import (
VersionAPIResponse,
get_version_response,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,6 +54,14 @@ async def get_single_pipeline_data(registered_pipeline_id: str):
return get_pipeline_response(registered_pipeline_id)


@router.get(
"/version",
response_model=VersionAPIResponse,
)
async def get_version():
return get_version_response()


@router.post("/deploy")
async def deploy_kedro_viz(input_values: DeployerConfiguration):
from kedro_viz.integrations.deployment.deployer_factory import DeployerFactory
Expand Down
25 changes: 0 additions & 25 deletions package/tests/test_api/test_graphql/test_queries.py

This file was deleted.

14 changes: 14 additions & 0 deletions package/tests/test_api/test_rest/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,17 @@ def test_metadata(
mock_get_metadata_response.assert_called_once()
assert response.status_code == expected_status_code
assert response.json() == expected_response


def test_version(client):
response = client.get("/api/version")
assert response.status_code == 200

json_response = response.json()
assert "installed" in json_response
assert "is_outdated" in json_response
assert "latest" in json_response

assert isinstance(json_response["installed"], str)
assert isinstance(json_response["is_outdated"], bool)
assert isinstance(json_response["latest"], str)
20 changes: 16 additions & 4 deletions src/components/wrapper/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useApolloQuery } from '../../apollo/utils';
import { client } from '../../apollo/config';
import { GraphQLProvider } from '../provider/provider';
import { GET_VERSIONS } from '../../apollo/queries';
import { getVersion } from '../../utils';

import FeatureHints from '../feature-hints';
import GlobalToolbar from '../global-toolbar';
Expand All @@ -29,11 +30,22 @@ export const Wrapper = ({ displayGlobalNavigation, theme }) => {
const [latestVersion, setLatestVersion] = useState(null);

useEffect(() => {
if (versionData) {
setIsOutdated(versionData.version.isOutdated);
setLatestVersion(versionData.version.latest);
async function checkKedroVizVersion() {
try {
const request = await getVersion();
const response = await request.json();

if (request.ok) {
setIsOutdated(response.is_outdated);
setLatestVersion(response.latest);
}
} catch (error) {
console.error('Error fetching Kedro-Viz version:', error);
}
}
}, [versionData]);

checkKedroVizVersion();
}, []);

return (
<div
Expand Down
10 changes: 10 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ export async function deployViz(inputValues) {
return request;
}

export async function getVersion() {
const request = await fetch(`${pathRoot}/version`, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});
return request;
}

const nodeTypeMapObj = {
nodes: 'task',
task: 'nodes',
Expand Down
Loading