-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* user-facing `MetaflowCardComponent`s - import via `from metaflow.cards import Artifact,..` * 7 Major Changes: - Removed `Section` component from `metaflow.cards` - Making user-facing component inherent to `UserComponent` which in turn inherits `MetaflowCardComponent` - Wrap all `UserComponents` inside a section after rendering everything per card - created a `render_safely` decorator to ensure fail-safe render of `UserComponent`s - removed code from component serializer which used internal components - Refactored some components that return render - Added docstrings to all components. * JS + CSS + Cards UI Build * Stacked @card v1.2 : Graph Related Changes to card cli (#911) * accomodating changes from #833 - Minor tweaks to `graph.py` * Stacked @card v1.2 : Namespace Packages with `@card` (#897) * setup import of cards from `metaflow_extensions` using `metaflow.extension_support` - Added import modules in `card_modules` - Added hook in card decorators to add custom packages * Added some debug statements for external imports. * Stacked @card v1.2 : Test cases for Multiple `@card`s (#898) * Multiple Cards Test Suite Mods (#27) - Added `list_cards` to `CliCheck` and `MetadataCheck` - Bringing #875 into the code - Added a card that prints taskspec with random number * Added test case for multiple cards * Added tests card, summary : - `current.cards['myid']` should be accessible when cards have an `id` argument in decorator - `current.cards.append` should not work when there are no single default editable card. - if a card has `ALLOW_USER_COMPONENTS=False` then it can still be edited via accessing it with `id` property. - adding arbitrary information to `current.cards.append` should not break user code. - Only cards with `ALLOW_USER_COMPONENTS=True` are considered default editable. - If a single @card decorator is present with `id` then it `current.cards.append` should still work - Access of `current.cards` with non existant id should not fail. - `current.cards.append` should be accessible to the card with `customize=True`. - * fixed `DefaultEditableCardTest` test case - Fixed comment - Fixed the `customize=True` test case. * ensure `test_pathspec_card` has no duplicates - ensure entropy of rendered information is high enough to not overwrite a file. * test case fix : `current.cards` to `current.card` * Added Test case to support import of cards. - Test case validates that broken card modules don't break metaflow - test case validates that we are able to import cards from metaflow_extensions - Test case validate that cards can be editable if they are importable. * Added Env var to tests to avoid warnings added to cards. * Added Test for card resume. * Stacked @card v1.2: Card Dev Docs (#899) Co-authored-by: Romain Cledat <[email protected]> Co-authored-by: Brendan Gibson <[email protected]> Co-authored-by: Brendan Gibson <[email protected]> Co-authored-by: adam <[email protected]> Co-authored-by: Romain Cledat <[email protected]>
- Loading branch information
1 parent
1936960
commit 77c35a6
Showing
72 changed files
with
4,572 additions
and
533 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
from metaflow.plugins.cards.card_client import get_cards | ||
from metaflow.plugins.cards.card_modules.card import MetaflowCardComponent, MetaflowCard | ||
from metaflow.plugins.cards.card_modules.components import ( | ||
Artifact, | ||
Table, | ||
Image, | ||
Error, | ||
Markdown, | ||
) | ||
from metaflow.plugins.cards.card_modules.basic import ( | ||
DefaultCard, | ||
TitleComponent, | ||
SubTitleComponent, | ||
SectionComponent, | ||
ImageComponent, | ||
BarChartComponent, | ||
LineChartComponent, | ||
TableComponent, | ||
DagComponent, | ||
PageComponent, | ||
ArtifactsComponent, | ||
RENDER_TEMPLATE_PATH, | ||
TaskToDict, | ||
DefaultComponent, | ||
ChartComponent, | ||
TaskInfoComponent, | ||
ErrorCard, | ||
BlankCard, | ||
) |
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
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 +1,112 @@ | ||
import os | ||
import traceback | ||
from .card import MetaflowCard, MetaflowCardComponent | ||
from metaflow.extension_support import get_modules, EXT_PKG, _ext_debug | ||
|
||
|
||
def iter_namespace(ns_pkg): | ||
# Specifying the second argument (prefix) to iter_modules makes the | ||
# returned name an absolute name instead of a relative one. This allows | ||
# import_module to work without having to do additional modification to | ||
# the name. | ||
import pkgutil | ||
|
||
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".") | ||
|
||
|
||
def _get_external_card_packages(with_paths=False): | ||
""" | ||
Safely extract all exteranl card modules | ||
Args: | ||
with_paths (bool, optional): setting `with_paths=True` will result in a list of tuples: `[( mf_extensions_parent_path , relative_path_to_module, module)]`. setting false will return a list of modules Defaults to False. | ||
Returns: | ||
`list` of `ModuleType` or `list` of `tuples` where each tuple if of the form (mf_extensions_parent_path , relative_path_to_module, ModuleType) | ||
""" | ||
import importlib | ||
|
||
available_card_modules = [] | ||
for m in get_modules("plugins.cards"): | ||
# Iterate submodules of metaflow_extensions.X.plugins.cards | ||
# For example metaflow_extensions.X.plugins.cards.monitoring | ||
card_packages = [] | ||
for fndx, card_mod, ispkg_c in iter_namespace(m.module): | ||
try: | ||
if not ispkg_c: | ||
continue | ||
cm = importlib.import_module(card_mod) | ||
_ext_debug("Importing card package %s" % card_mod) | ||
if with_paths: | ||
card_packages.append((fndx.path, cm)) | ||
else: | ||
card_packages.append(cm) | ||
except Exception as e: | ||
_ext_debug( | ||
"External Card Module Import Exception \n\n %s \n\n %s" | ||
% (str(e), traceback.format_exc()) | ||
) | ||
if with_paths: | ||
card_packages = [ | ||
( | ||
os.path.abspath( | ||
os.path.join(pth, "../../../../") | ||
), # parent path to metaflow_extensions | ||
os.path.join( | ||
EXT_PKG, | ||
os.path.relpath(m.__path__[0], os.path.join(pth, "../../../")), | ||
), # construct relative path to parent. | ||
m, | ||
) | ||
for pth, m in card_packages | ||
] | ||
available_card_modules.extend(card_packages) | ||
return available_card_modules | ||
|
||
|
||
def _load_external_cards(): | ||
# Load external card packages | ||
card_packages = _get_external_card_packages() | ||
if not card_packages: | ||
return [] | ||
external_cards = {} | ||
card_arr = [] | ||
# Load cards from all external packages. | ||
for package in card_packages: | ||
try: | ||
cards = package.CARDS | ||
# Ensure that types match. | ||
if not type(cards) == list: | ||
continue | ||
except AttributeError: | ||
continue | ||
else: | ||
for c in cards: | ||
if not isinstance(c, type) or not issubclass(c, MetaflowCard): | ||
# every card should only be inheriting a MetaflowCard | ||
continue | ||
if not getattr(c, "type", None): | ||
# todo Warn user of non existant `type` in MetaflowCard | ||
continue | ||
if c.type in external_cards: | ||
# todo Warn user of duplicate card | ||
continue | ||
# external_cards[c.type] = c | ||
card_arr.append(c) | ||
return card_arr | ||
|
||
|
||
def _get_external_card_package_paths(): | ||
pkg_iter = _get_external_card_packages(with_paths=True) | ||
if pkg_iter is None: | ||
return None | ||
for ( | ||
mf_extension_parent_path, | ||
relative_path_to_module, | ||
_, | ||
) in pkg_iter: | ||
module_pth = os.path.join(mf_extension_parent_path, relative_path_to_module) | ||
arcname = relative_path_to_module | ||
yield module_pth, arcname | ||
|
||
|
||
MF_EXTERNAL_CARDS = _load_external_cards() |
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
Oops, something went wrong.