-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from joerick/html-features
HTML renderer upgrade
- Loading branch information
Showing
86 changed files
with
4,462 additions
and
1,335 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
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,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from glob import glob | ||
from pathlib import Path | ||
|
||
ROOT_DIR = Path(__file__).parent.parent | ||
|
||
|
||
def main(): | ||
os.chdir(ROOT_DIR) | ||
for script in glob(str("examples/demo_scripts/*.py")): | ||
subprocess.run([sys.executable, "bin/create_sample_json.py", script], check=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,36 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
ROOT_DIR = Path(__file__).parent.parent | ||
OUTPUT_DIR = ROOT_DIR / "html_renderer" / "demo-data" | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("SCRIPT", help="The script to run to produce the sample", type=Path) | ||
args = parser.parse_args() | ||
script_file: Path = args.SCRIPT | ||
output_file = (OUTPUT_DIR / script_file.with_suffix("").name).with_suffix(".json") | ||
|
||
result = subprocess.run( | ||
[ | ||
"pyinstrument", | ||
"-o", | ||
str(output_file), | ||
"-r", | ||
"pyinstrument.renderers.html.JSONForHTMLRenderer", | ||
script_file, | ||
] | ||
) | ||
|
||
if result.returncode != 0: | ||
return result.returncode | ||
|
||
print(f"Sample JSON written to {output_file}") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
docs/_static/preview/assets/wikipedia_article_word_count-CGt_pvsZ.js
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Pyinstrument Demo</title> | ||
<script type="module" crossorigin src="./assets/index-DhaBtkCM.js"></script> | ||
<link rel="stylesheet" crossorigin href="./assets/index-paBu1EOJ.css"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<script lang="ts"> | ||
import pyinstrumentHTMLRenderer from "../src/main"; | ||
const fileURLs = import.meta.glob("../demo-data/*.json", {import: "default"}) | ||
const files = Object.entries(fileURLs).map(([srcURL, promiseFn]) => { | ||
const filename = srcURL.split("/").pop()!; | ||
const stem = filename.split(".").slice(0, -1).join("."); | ||
return { name: stem, promiseFn }; | ||
}); | ||
let file = files[0]; | ||
let data: any = null; | ||
let error: Error | null = null; | ||
let loading = false; | ||
$: { | ||
loading = true; | ||
error = null; | ||
data = null; | ||
file.promiseFn() | ||
.then((json) => { | ||
data = json; | ||
error = null; | ||
}) | ||
.catch((e) => { | ||
error = e; | ||
}) | ||
.finally(() => { | ||
loading = false; | ||
}); | ||
} | ||
let appComponent: ReturnType< | ||
(typeof pyinstrumentHTMLRenderer)["render"] | ||
> | null = null; | ||
let resultElement: HTMLElement | undefined; | ||
$: if (resultElement && data) { | ||
if (appComponent) { | ||
appComponent.$destroy(); | ||
} | ||
appComponent = pyinstrumentHTMLRenderer.render(resultElement, data); | ||
} | ||
</script> | ||
|
||
<div class="demo-app"> | ||
<div class="header"> | ||
<div class="left"></div> | ||
<div class="right"> | ||
Choose a demo profile: | ||
<select bind:value={file}> | ||
{#each files as optionFile} | ||
<option value={optionFile}>{optionFile.name}</option> | ||
{/each} | ||
</select> | ||
</div> | ||
</div> | ||
<div class="body"> | ||
{#if loading} | ||
<div>Loading...</div> | ||
{:else if error} | ||
<div>Error loading file: {error.message}</div> | ||
{/if} | ||
|
||
<div class="result-element" style={!data ? 'display: none' : ''} bind:this={resultElement}></div> | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.demo-app { | ||
background-color: #111; | ||
color: white; | ||
font-size: 11px; | ||
font-family: | ||
system-ui, | ||
-apple-system, | ||
BlinkMacSystemFont, | ||
"Segoe UI", | ||
Roboto, | ||
Oxygen, | ||
Ubuntu, | ||
Cantarell, | ||
"Open Sans", | ||
"Helvetica Neue", | ||
sans-serif; | ||
display: flex; | ||
flex-direction: column; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
} | ||
.header { | ||
// background: #292f32; | ||
// font-size: 14px; | ||
padding: 5px 10px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
.body { | ||
position: relative; | ||
flex: 1; | ||
} | ||
select { | ||
font: inherit; | ||
} | ||
</style> |
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,5 @@ | ||
import DemoApp from "./DemoApp.svelte"; | ||
|
||
new DemoApp({ | ||
target: document.body, | ||
}); |
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.