Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python Dependency Deck (flyteorg#2264)
* feat: refactor source code rendering in `SourceCodeDeck` class - Add a new class `SourceCodeDeck` to render the source code of a task - Implement the `html` property in the `SourceCodeDeck` class Signed-off-by: jason.lai <[email protected]> * refactor: refactor deck rendering for Python dependencies - Change the class name from `SourceCodeDeck` to `PythonDependencyDeck` - Update the deck description to reflect python dependencies instead of source code - Remove the source code rendering functionality and replace it with a table renderer for python dependencies - Add subprocess logic to fetch installed python packages and render them in an HTML table Signed-off-by: jason.lai <[email protected]> * refactor: refactor class properties and initialization - Add a property method for `pythondependency_deck` - Initialize `python_dependency_deck` if it is None - Remove a property method for `timeline_deck` Signed-off-by: jason.lai <[email protected]> * - feat: consolidate Python dependencies in `flytekit/__init__.py` - Add `PythonDependencyDeck` to `flytekit/__init__.py` Signed-off-by: jason.lai <[email protected]> * refactor: refactor `flytekit/deck/deck.py` for `pandas` compatibility - Add `pandas` import to `flytekit/deck/deck.py` - Change the input of `TableRenderer().to_html` to a `pd.DataFrame` in `flytekit/deck/deck.py` Signed-off-by: jason.lai <[email protected]> * refactor: refactor return types across multiple files - Update the return type annotation for `pythondependency_deck` in `context_manager.py` Signed-off-by: jason.lai <[email protected]> * feat: consolidate Python dependency management in FlyteContext - Add `PythonDependencyDeck` to the TYPE_CHECKING import - Add a method `add_deck` to `FlyteContext` class Signed-off-by: jason.lai <[email protected]> * refactor: refactor code to use DataFrame for package handling - Refactor the code to use a DataFrame for installed packages handling Signed-off-by: jason.lai <[email protected]> * chore: refactor code for improved naming conventions - Update the name of the PythonDependencyDeck instance from "PythonDependencyDeck" to "Python Dependency" Signed-off-by: jason.lai <[email protected]> * style: improve table alignment styling in CSS - Add CSS style to center align the table content Signed-off-by: jason.lai <[email protected]> * refactor: refactor method and variable names across files - Rename method `pythondependency_deck` to `python_dependency_deck` - Update variable names in method `python_dependency_deck` - Update method comments in class `FlyteContext` - Update method comments in class `PythonDependencyDeck` Signed-off-by: jason.lai <[email protected]> * refactor: refactor imports in flytekit package - Remove import of `PythonDependencyDeck` from `flytekit/__init__.py` Signed-off-by: jason.lai <[email protected]> * refactor: consolidate import statements in core/context_manager.py - Remove the import of `PythonDependencyDeck` from `flytekit/core/context_manager.py` - Add an import of `Deck` to `flytekit/core/context_manager.py` Signed-off-by: jason.lai <[email protected]> * style: improve code consistency and error checking - Add a condition to check for deck existence before appending - Change single quotes to double quotes for consistency - Update package split delimiter to double quotes Signed-off-by: jason.lai <[email protected]> * refactor: refactor Python dependency handling in classes - Remove the `python_dependency_deck` property from the `ExecutionParameters` class in `context_manager.py` - Update the `__init__` method signature in the `PythonDependencyDeck` class in `deck.py` Signed-off-by: jason.lai <[email protected]> * chore: optimize imports in deck.py files - Remove unnecessary import of `pandas` in `flytekit/deck/deck.py` - Add import of `pandas` in `flytekit/deck/deck.py` Signed-off-by: jason.lai <[email protected]> * test: improve test coverage for PythonDependencyDeck class - Add a new test for the PythonDependencyDeck class in test_deck.py - Add assertions for specific strings in the HTML content in the test_python_dependency_deck() function Signed-off-by: jason.lai <[email protected]> * feat: enhance user space deck management - Clear user space decks before adding a new deck - Ensure only one deck is added to user space params Signed-off-by: jason.lai <[email protected]> * refactor: refactor deck module and unit tests - Import json and TableRenderer in `flytekit/deck/deck.py` - Change how installed packages are fetched in `flytekit/deck/deck.py` - Remove unused code in `flytekit/deck/deck.py` - Remove assertions for "Library" and "Version" in `tests/flytekit/unit/deck/test_deck.py` Signed-off-by: jason.lai <[email protected]> * fix: update subprocess calls to use `sys.executable` - Import `sys` to fix an issue with subprocess execution - Update the subprocess call to use `sys.executable` instead of `pip` Signed-off-by: jason.lai <[email protected]> * feat: refactor HTML generation logic and improve user experience - Update the HTML generation logic to include a button for copying the table as requirements.txt. Signed-off-by: jason.lai <[email protected]> * feat: enhance table content copying functionality - Add functionality to copy table content as requirements.txt - Improve error handling when copying table content - Display table content as hidden div for copying Signed-off-by: jason.lai <[email protected]> * refactor: improve table content copying functionality - Remove unnecessary code for table content copying - Update table content copying functionality to use innerText of requirements_txt element Signed-off-by: jason.lai <[email protected]> * refactor: improve package management and error handling - Add logic to generate a `requirements.txt` file from installed packages - Update error logging message in case of subprocess error - Update console log message when accessing clipboard - Update `requirements_txt` div content with actual `requirements_txt` variable Signed-off-by: jason.lai <[email protected]> * chore: standardize whitespace in requirements_txt handling - Remove trailing whitespace from `requirements_txt` string - Add a whitespace to the end of the `requirements_txt` variable - Log an error message when fetching installed packages fails Signed-off-by: jason.lai <[email protected]> * style: standardize quotation marks for package_info keys - Corrected quotation marks in package_info keys - Changed single quotes to double quotes for consistency Signed-off-by: jason.lai <[email protected]> * refactor: simplify requirements_txt generation - Refactor code to simplify the generation of `requirements_txt` - Add the output of `pip freeze` to `requirements_txt` Signed-off-by: jason.lai <[email protected]> * docs: fix typos and improve code consistency across files - Fix a typo in the usage of the `pip freeze` command in the PythonDependencyDeck class Signed-off-by: jason.lai <[email protected]> * refactor: refactor dependency handling in PythonDependencyDeck class - Update the way `requirements_txt` is populated in the `PythonDependencyDeck` class Signed-off-by: jason.lai <[email protected]> * refactor: update default name and test assertion in PythonDependencyDeck - Update the default name in the PythonDependencyDeck constructor from "Python Dependency" to "Python Dependencies" - Update the assertion in the test_python_dependency_deck function to check for the new default name "Python Dependencies" Signed-off-by: jason.lai <[email protected]> * refactor: update rendering of Pandas DataFrame using MarkdownRenderer - Import `MarkdownRenderer` from `flytekit.deck` instead of `TableRenderer` - Render the Pandas DataFrame as markdown using `MarkdownRenderer` instead of `TableRenderer` Signed-off-by: jason.lai <[email protected]> * refactor: refactor PythonDependencyDeck and related classes - Remove the `add_deck` method from `FlyteContext` - Add imports for `PythonDependencyRenderer` and `PythonDependencyDeck` in `PythonFunctionTask` - Remove the `PythonDependencyDeck` class and related methods from the `deck.py` file - Add the `PythonDependencyRenderer` class in `renderer.py` Signed-off-by: jason.lai <[email protected]> * feat: use `TableRenderer` for rendering DataFrames - Import `TableRenderer` from a different module - Replace the `MarkdownRenderer` with `TableRenderer` to render a DataFrame as a table Signed-off-by: jason.lai <[email protected]> * test: refactor codebase for improved performance - Remove unused import statements in `flytekit/deck/renderer.py` - Add a new test for `PythonDependencyRenderer` in `tests/flytekit/unit/deck/test_deck.py` Signed-off-by: jason.lai <[email protected]> * test: update test_deck.py for python dependency deck testing - Update test_deck.py to include python dependency deck in various test cases - Adjust expected deck counts in test cases to reflect the changes - Add test cases for scenarios involving python dependency deck and input and output decks Signed-off-by: jason.lai <[email protected]> * style: standardize import statements for pandas in project files - Remove `import pandas as pd` and replace it with `import pandas as pandas` Signed-off-by: jason.lai <[email protected]> * refactor: refactor import statements for `TableRenderer` usage - Import `TableRenderer` from a different location in `flytekit/deck/renderer.py` - Remove `TableRenderer` from the imports in `flytekit-deck-standard/flytekitplugins/deck/__init__.py` Signed-off-by: jason.lai <[email protected]> * refactor: update PythonDependencyRenderer description - Update the description of PythonDependencyDeck in PythonDependencyRenderer Signed-off-by: jason.lai <[email protected]> * refactor: refactor type hints and assertions across files - Change the type hint for `df` parameter to `pandas.DataFrame` - Add an assertion to check the type of `df` is `pandas.DataFrame` Signed-off-by: jason.lai <[email protected]> * feat: refactor rendering classes in deck and plugins - Add TableRenderer to TimeLineDeck class in deck.py - Remove TableRenderer from deck/renderer.py - Add TableRenderer to PythonDependencyRenderer in deck/renderer.py - Add TableRenderer to flytekit-deck-standard plugin - Remove TableRenderer from test_renderer.py Signed-off-by: jason.lai <[email protected]> * docs: standardize markdown formatting across files - Update the markdown table format in PythonDependencyRenderer class Signed-off-by: jason.lai <[email protected]> * refactor: refactor markdown table rendering in PythonDependencyRenderer - Update the markdown table format in the PythonDependencyRenderer class to use HTML table tags - Modify the markdown_table variable concatenation for installed packages entries in the PythonDependencyRenderer class Signed-off-by: jason.lai <[email protected]> * style: improve code consistency in PythonDependencyRenderer - Add a line break after the button element in PythonDependencyRenderer Signed-off-by: jason.lai <[email protected]> * style: standardize formatting for better readability - Modify the table headers to have left-aligned text - Add extra line breaks after the button element Signed-off-by: jason.lai <[email protected]> * fix: update assertion to check for `Name` and `Version` consistency - Change the assertion to check for `Name` and `Version` instead of `name` and `version` in the result Signed-off-by: jason.lai <[email protected]> * test: extend test deadlines across various tests - Increase the test deadlines from 2 to 20 seconds in test_type_conversion_errors.py - Update test deadlines from 2 to 40 seconds in test_type_conversion_errors.py - Adjust test deadlines in test_eager_workflows.py for various tests Signed-off-by: jason.lai <[email protected]> * Revert "test: extend test deadlines across various tests" This reverts commit 1885662. Signed-off-by: Eduardo Apolinario <[email protected]> * Only run generate decks in python_function_task if decks are enabled Signed-off-by: Eduardo Apolinario <[email protected]> * Remove breakpoint Signed-off-by: Eduardo Apolinario <[email protected]> * Fix test_deck.py tests to account for the number of expected decks (now that we're no longer writing decks unnecessarily) Signed-off-by: Eduardo Apolinario <[email protected]> * Increase deadline of eager tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix lint error Signed-off-by: Eduardo Apolinario <[email protected]> * test: update test assertions in test_deck.py - Add a patch to the `test_python_dependency_renderer` function - Include assertions for `numpy` and `1.21.0` in the test result - Update the `test_deck.py` file in the `tests/flytekit/unit/deck` directory Signed-off-by: jason.lai <[email protected]> * refactor: refactor Python code organization - Import `PythonDependencyRenderer` and `SourceCodeRenderer` in `PythonFunctionTask` from separate files - Modify the way `requirements_txt` is generated in `PythonDependencyRenderer` - Refactor the creation of the `table` variable in `PythonDependencyRenderer` to improve readability Signed-off-by: jason.lai <[email protected]> * docs: refactor project structure and improve user experience - Change the title of the deck from `Python Dependencies` to `Dependencies` - Update the error message in case of a subprocess error in fetching installed packages - Add a heading `Python Dependencies` above the table output in the HTML Signed-off-by: jason.lai <[email protected]> * Separate out tests that require hypothesis Signed-off-by: Eduardo Apolinario <[email protected]> --------- Signed-off-by: jason.lai <[email protected]> Signed-off-by: Eduardo Apolinario <[email protected]> Co-authored-by: Eduardo Apolinario <[email protected]>
- Loading branch information