-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kedro Viz Lite User Warning UI (#2092)
* sync remote * add lite viz banner * banner design change * add tests * refactor metadata api * fix permissions * working state * comment out banner condition for testing * address PR comments * fix tests * update tests * update release
- Loading branch information
1 parent
28a2fd0
commit 30d5cef
Showing
30 changed files
with
744 additions
and
190 deletions.
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,15 @@ | ||
{ | ||
"has_missing_dependencies": false, | ||
"package_compatibilities": [ | ||
{ | ||
"package_name": "fsspec", | ||
"package_version": "2023.9.1", | ||
"is_compatible": true | ||
}, | ||
{ | ||
"package_name": "kedro-datasets", | ||
"package_version": "2.0.0", | ||
"is_compatible": true | ||
} | ||
] | ||
} |
15 changes: 9 additions & 6 deletions
15
...package-compatibilities-incompatible.json → ...s/fixtures/mock/inCompatibleMetadata.json
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,12 +1,15 @@ | ||
[ | ||
{ | ||
{ | ||
"has_missing_dependencies": true, | ||
"package_compatibilities": [ | ||
{ | ||
"package_name": "fsspec", | ||
"package_version": "2023.8.1", | ||
"is_compatible": false | ||
}, | ||
{ | ||
}, | ||
{ | ||
"package_name": "kedro-datasets", | ||
"package_version": "1.8.0", | ||
"is_compatible": false | ||
} | ||
] | ||
} | ||
] | ||
} |
12 changes: 0 additions & 12 deletions
12
cypress/fixtures/mock/package-compatibilities-compatible.json
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
describe('Banners in Kedro-Viz', () => { | ||
beforeEach(() => { | ||
// Clears localStorage before each test | ||
cy.clearLocalStorage(); | ||
}); | ||
|
||
it("shows a missing dependencies banner in viz lite mode if the kedro project dependencies are not installed.", () => { | ||
// Intercept the network request to mock with a fixture | ||
cy.__interceptRest__( | ||
'/api/metadata', | ||
'GET', | ||
'/mock/inCompatibleMetadata.json' | ||
).as("appMetadata"); | ||
|
||
// Action | ||
cy.reload(); | ||
|
||
// Assert after action | ||
cy.get('[data-test="flowchart-wrapper--lite-banner"]').should('exist'); | ||
cy.get('.banner-message-body').should('contains.text', 'please install the missing Kedro project dependencies') | ||
cy.get('.banner-message-title').should('contains.text', 'Missing dependencies') | ||
|
||
// Test Learn more link | ||
cy.get(".banner a") | ||
.should("contains.attr", "href", "https://docs.kedro.org/projects/kedro-viz/en/latest/kedro-viz_visualisation.html#visualise-a-kedro-project-without-installing-project-dependencies"); | ||
|
||
// Close the banner | ||
cy.get(".banner-close").click() | ||
cy.get('[data-test="flowchart-wrapper--lite-banner"]').should('not.exist'); | ||
|
||
}); | ||
}); |
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
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,10 +1,49 @@ | ||
"""`kedro_viz.api.rest.utils` contains utility functions used in the `kedro_viz.api.rest` package""" | ||
|
||
import logging | ||
from importlib.metadata import PackageNotFoundError | ||
from typing import List | ||
|
||
import packaging | ||
|
||
from kedro_viz.constants import PACKAGE_REQUIREMENTS | ||
from kedro_viz.models.metadata import PackageCompatibility | ||
|
||
try: | ||
from importlib.metadata import version | ||
except ImportError: # pragma: no cover | ||
from importlib_metadata import version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_package_version(package_name: str): | ||
"""Returns the version of the given package.""" | ||
return version(package_name) # pragma: no cover | ||
|
||
|
||
def get_package_compatibilities() -> List[PackageCompatibility]: | ||
"""Returns the package compatibilities information | ||
for the current python env.""" | ||
package_compatibilities: List[PackageCompatibility] = [] | ||
|
||
for package_name, package_info in PACKAGE_REQUIREMENTS.items(): | ||
compatible_version = package_info["min_compatible_version"] | ||
try: | ||
package_version = get_package_version(package_name) | ||
except PackageNotFoundError: | ||
logger.warning(package_info["warning_message"]) | ||
package_version = "0.0.0" | ||
|
||
is_compatible = packaging.version.parse( | ||
package_version | ||
) >= packaging.version.parse(compatible_version) | ||
|
||
package_compatibilities.append( | ||
PackageCompatibility( | ||
package_name=package_name, | ||
package_version=package_version, | ||
is_compatible=is_compatible, | ||
) | ||
) | ||
return package_compatibilities |
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,47 @@ | ||
"""`kedro_viz.models.metadata` defines metadata for Kedro-Viz application.""" | ||
|
||
# pylint: disable=missing-function-docstring | ||
from typing import ClassVar, List | ||
|
||
from pydantic import BaseModel, field_validator | ||
|
||
|
||
class PackageCompatibility(BaseModel): | ||
"""Represent package compatibility in app metadata""" | ||
|
||
package_name: str | ||
package_version: str | ||
is_compatible: bool | ||
|
||
@field_validator("package_name") | ||
@classmethod | ||
def set_package_name(cls, value): | ||
assert isinstance(value, str) | ||
return value | ||
|
||
@field_validator("package_version") | ||
@classmethod | ||
def set_package_version(cls, value): | ||
assert isinstance(value, str) | ||
return value | ||
|
||
@field_validator("is_compatible") | ||
@classmethod | ||
def set_is_compatible(cls, value): | ||
assert isinstance(value, bool) | ||
return value | ||
|
||
|
||
class Metadata(BaseModel): | ||
"""Represent Kedro-Viz application metadata""" | ||
|
||
has_missing_dependencies: ClassVar[bool] = False | ||
package_compatibilities: ClassVar[List[PackageCompatibility]] = [] | ||
|
||
@classmethod | ||
def set_package_compatibilities(cls, value: List[PackageCompatibility]): | ||
cls.package_compatibilities = value | ||
|
||
@classmethod | ||
def set_has_missing_dependencies(cls, value: bool): | ||
cls.has_missing_dependencies = value |
Oops, something went wrong.