-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eb8e1fd
Showing
17 changed files
with
2,021 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: build | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install $(realpath "./skrub.whl") | ||
- name: Build the site | ||
run: | | ||
python build.py | ||
- name: GitHub Pages action | ||
uses: peaceiris/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: _build |
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 @@ | ||
_build/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Jérôme Dockès | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>skrub example report</title> | ||
<link rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/build/pure-min.css" | ||
integrity="sha384-X38yfunGUhNzHpBaEBsWLO+A0HDYOQi8ufWDkZ0k9e0eXz/tH3II7uKZ9msv++Ls" | ||
crossorigin="anonymous"> | ||
<style> | ||
{% include "skrub-online-report.css" %} | ||
</style> | ||
<link rel="icon" href="../skrub.svg"> | ||
</head> | ||
|
||
<body class="color-links"> | ||
{% include "nav.html" %} | ||
|
||
{% include "small-banner.html" %} | ||
|
||
<main> | ||
<div> | ||
{{ report | safe }} | ||
</div> | ||
</main> | ||
</body> | ||
|
||
</html> |
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,39 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>skrub reports</title> | ||
<link rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/build/pure-min.css" | ||
integrity="sha384-X38yfunGUhNzHpBaEBsWLO+A0HDYOQi8ufWDkZ0k9e0eXz/tH3II7uKZ9msv++Ls" | ||
crossorigin="anonymous"> | ||
<style> | ||
{% include "skrub-online-report.css" %} | ||
</style> | ||
<link rel="icon" href="../skrub.svg"> | ||
</head> | ||
|
||
<body class="color-links"> | ||
{% include "nav.html" %} | ||
|
||
{% include "small-banner.html" %} | ||
|
||
<main> | ||
<p class="narrow-wrapper"> | ||
Follow one of the links below to see a report computed with | ||
<a href="https://skrub-data.org/dev/reference/generated/skrub.TableReport.html#" class="table-report"><code>skrub.TableReport</code></a> | ||
for the corresponding dataset. | ||
</p> | ||
<ul class="examples-index example-dataset-list"> | ||
{% for report_name in report_names %} | ||
<li> | ||
<a href="{{ report_name }}.html">{{ report_name.replace('_', ' ').capitalize() }}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</main> | ||
</body> | ||
|
||
</html> |
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 @@ | ||
<nav> | ||
<ul class="nav"> | ||
{% for name, href in nav_links %} | ||
<li> | ||
<a | ||
href={{ href | relative }} | ||
{% if href == current_page %} | ||
class="current-page" | ||
{% endif %} | ||
>{{ name }}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</nav> |
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 @@ | ||
<div class="small-banner flex padding"> | ||
<a href="https://skrub-data.org/"><img class="skrub" src="../skrub.svg"></a> | ||
<a href="https://skrub-data.org/dev/reference/generated/skrub.TableReport.html#" | ||
class="table-report"><code>skrub.TableReport</code></a> | ||
</div> |
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,152 @@ | ||
#! /usr/bin/env python | ||
|
||
import argparse | ||
from pathlib import Path | ||
import shutil | ||
import re | ||
import secrets | ||
import time | ||
|
||
import jinja2 | ||
import pandas as pd | ||
from skrub import datasets as skrub_data | ||
from sklearn import datasets as sklearn_data | ||
from skrub import TableReport | ||
|
||
|
||
NAV_LINKS = [("Demo", "index.html"), ("Examples", "examples/index.html")] | ||
|
||
|
||
def write(text, path): | ||
path.write_text(bust(text), encoding="utf-8") | ||
|
||
|
||
@jinja2.pass_context | ||
def relative(context, path): | ||
current_page = context["current_page"] | ||
depth = len(current_page.split("/")) - 1 | ||
parts = [".."] * depth + path.split("/") | ||
return "/".join(parts) | ||
|
||
|
||
def get_jinja_env(): | ||
env = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader( | ||
[REPO, REPO / "_includes"], | ||
encoding="UTF-8", | ||
), | ||
autoescape=True, | ||
) | ||
env.filters["relative"] = relative | ||
env.globals = { | ||
"nav_links": NAV_LINKS, | ||
} | ||
return env | ||
|
||
|
||
def bust(text): | ||
return re.sub(r"\?__skrub_[a-zA-Z0-9]+__", f"?__skrub_{VERSION}__", text) | ||
|
||
|
||
def get_datasets(): | ||
AMES_HOUSING_CSV = ( | ||
"https://www.openml.org/data/get_csv/20649135/file2ed11cebe25.arff" | ||
) | ||
datasets = [("AMES Housing", (lambda: pd.read_csv(AMES_HOUSING_CSV)))] | ||
skrub_dataset_names = [ | ||
"employee_salaries", | ||
"medical_charge", | ||
"traffic_violations", | ||
"drug_directory", | ||
] | ||
for name in skrub_dataset_names: | ||
|
||
def fetch(name=name): | ||
return getattr(skrub_data, f"fetch_{name}")().X | ||
|
||
datasets.append((name, fetch)) | ||
sklearn_dataset_names = ["titanic"] | ||
for name in sklearn_dataset_names: | ||
|
||
def fetch(name=name): | ||
return sklearn_data.fetch_openml( | ||
name, as_frame=True, parser="auto", version=1 | ||
).frame | ||
|
||
datasets.append((name, fetch)) | ||
return datasets | ||
|
||
|
||
def add_report(name, fetcher): | ||
if ARGS.no_reports: | ||
html = '<div class="report-placeholder">report</div>' | ||
elapsed = 0 | ||
else: | ||
df = fetcher() | ||
print(f"making report for {name}") | ||
pretty_name = name.replace("_", " ").capitalize() | ||
start = time.time() | ||
html = TableReport(df, title=pretty_name).html_snippet() | ||
elapsed = time.time() - start | ||
print(f"{name} took {elapsed:.2f}s") | ||
report_template = ENV.get_template("example-report.html") | ||
current_page = f"examples/{name}.html" | ||
html = report_template.render( | ||
nav_links=NAV_LINKS + [(name, current_page)], | ||
current_page=current_page, | ||
report=html, | ||
time=elapsed, | ||
) | ||
write(html, EXAMPLES_DIR / f"{name}.html") | ||
|
||
|
||
def build_examples(): | ||
datasets = get_datasets() | ||
for name, fetcher in datasets: | ||
add_report(name, fetcher) | ||
|
||
examples_index = ENV.get_template("examples-index.html") | ||
html = examples_index.render( | ||
report_names=[name for name, _ in datasets], current_page="examples/index.html" | ||
) | ||
write(html, EXAMPLES_DIR / "index.html") | ||
|
||
|
||
def build_pages(): | ||
all_pages = REPO.glob("*.html") | ||
for page in all_pages: | ||
template = ENV.get_template(page.name) | ||
rendered = template.render(current_page=f"{page.name}") | ||
write(rendered, BUILD_DIR / page.name) | ||
|
||
for ext in ["css", "js", "svg"]: | ||
for file_path in REPO.glob(f"*.{ext}"): | ||
text = file_path.read_text("utf-8") | ||
write(text, BUILD_DIR / file_path.name) | ||
|
||
for asset in REPO.glob(f"*.whl"): | ||
shutil.copyfile(asset, BUILD_DIR / asset.name) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--no_reports", help="skip building example reports", action="store_true" | ||
) | ||
ARGS = parser.parse_args() | ||
|
||
REPO = Path(__file__).parent.resolve() | ||
BUILD_DIR = REPO / "_build" | ||
if BUILD_DIR.is_dir(): | ||
shutil.rmtree(BUILD_DIR) | ||
BUILD_DIR.mkdir() | ||
|
||
EXAMPLES_DIR = BUILD_DIR / "examples" | ||
EXAMPLES_DIR.mkdir() | ||
|
||
VERSION = secrets.token_hex()[:4] | ||
|
||
ENV = get_jinja_env() | ||
|
||
build_pages() | ||
build_examples() |
Binary file not shown.
Oops, something went wrong.