-
Notifications
You must be signed in to change notification settings - Fork 299
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
Add Python Dependency Deck #2264
Changes from 51 commits
fccb28d
1fec103
4ec42a7
6e70e23
4dfeb34
27ec1f2
5fd853d
bc21848
9b30dc6
5ebc980
501fcb6
6ce4575
7556126
534fa0f
c4358f0
363f84f
a775c7f
a4773e0
05db9ab
d2bc23b
099a931
b02db7c
aaedf7a
938e0dd
265cc60
7e132c0
9eacfe7
20a3e9f
341a7da
de90326
b5f49b4
5634e78
9bd7995
79a09ac
e4c0bd0
0091f25
5a58a8e
12ae643
16e681c
fc21591
ac21522
96a852c
20b84fc
8572008
1c93057
a32ce2d
8a40607
f731757
20e96c5
352b79b
0aad322
7f40ad8
1885662
3a262c4
1534070
03cb07c
6153065
3574aad
edb7c18
57597ed
9a2470e
fc81271
0f5a455
ef47b14
8c9af6b
814a952
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -86,3 +86,73 @@ | |||||
css = formatter.get_style_defs(".highlight").replace("#fff0f0", "#ffffff") | ||||||
html = highlight(source_code, PythonLexer(), formatter) | ||||||
return f"<style>{css}</style>{html}" | ||||||
|
||||||
|
||||||
class PythonDependencyRenderer: | ||||||
""" | ||||||
PythonDependencyDeck is a deck that contains information about packages installed via pip. | ||||||
""" | ||||||
|
||||||
def __init__(self, title: str = "Python Dependencies"): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
self._title = title | ||||||
|
||||||
def to_html(self) -> str: | ||||||
import json | ||||||
import subprocess | ||||||
import sys | ||||||
|
||||||
from flytekit.loggers import logger | ||||||
|
||||||
try: | ||||||
installed_packages = json.loads( | ||||||
subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"]) | ||||||
) | ||||||
requirements_txt = subprocess.check_output(["pip", "freeze"]).decode("utf-8").replace("\\n", "\n").rstrip() | ||||||
jasonlai1218 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
except subprocess.CalledProcessError as e: | ||||||
logger.error(f"Error occurred while fetching installed packages: {e}") | ||||||
return "" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having an empty HTML feels like a bad dev experience. I think it's worth having an error message:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree |
||||||
|
||||||
markdown_table = ( | ||||||
"<table>\n<tr>\n<th style='text-align:left;'>Name</th>\n<th style='text-align:left;'>Version</th>\n</tr>\n" | ||||||
) | ||||||
jasonlai1218 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
for entry in installed_packages: | ||||||
markdown_table += f"<tr>\n<td>{entry['name']}</td>\n<td>{entry['version']}</td>\n</tr>\n" | ||||||
|
||||||
markdown_table += "</table>" | ||||||
|
||||||
table = MarkdownRenderer().to_html(markdown_table) | ||||||
html = f""" | ||||||
<!DOCTYPE html> | ||||||
<html lang="en"> | ||||||
<head> | ||||||
<meta charset="UTF-8"> | ||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
<title>Flyte Dependencies</title> | ||||||
<script> | ||||||
async function copyTable() {{ | ||||||
var requirements_txt = document.getElementById('requirements_txt'); | ||||||
|
||||||
try {{ | ||||||
await navigator.clipboard.writeText(requirements_txt.innerText); | ||||||
}} catch (err) {{ | ||||||
console.log('Error accessing the clipboard: ' + err); | ||||||
}} | ||||||
}} | ||||||
</script> | ||||||
</head> | ||||||
<body> | ||||||
|
||||||
<button onclick="copyTable()"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eapolinario This copy button does not work. I get this error in the console: If we can not get this to work, I'm okay with removing the copy button and just showing the table. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is blocked on flyteorg/flyteconsole#852. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That just got merged, so next Flyte release is going to have this. |
||||||
<span>Copy table as requirements.txt</span> | ||||||
</button> | ||||||
<br><br><br> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
{table} | ||||||
|
||||||
<div id="requirements_txt" style="display:none">{requirements_txt}</div> | ||||||
|
||||||
</body> | ||||||
</html> | ||||||
""" | ||||||
return html | ||||||
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.
Nit: Making this shorter looks better in the UI:
"Python Dependencies using a second line":