Skip to content

Commit

Permalink
chore: Cleanup and remove frontend build processes #2644
Browse files Browse the repository at this point in the history
  • Loading branch information
tssweeney authored Oct 10, 2024
1 parent 5b88efd commit 0faef09
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 158 deletions.
55 changes: 0 additions & 55 deletions .github/workflows/upload-assets.yaml

This file was deleted.

5 changes: 1 addition & 4 deletions weave_query/build_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
f"Unknown directories: {bad_dirs}, modify MANIFEST.in or build.py to include them."
)

if os.getenv("WEAVE_SKIP_BUILD") == None:
subprocess.run(["bash", "weave_query/frontend/build.sh"], check=True)
else:
print("!!! Skipping frontend build !!!")
print("!!! Skipping frontend build !!!")

subprocess.run(["python", "-m", "build"], check=True)

Expand Down
2 changes: 0 additions & 2 deletions weave_query/scripts/build_frontend.sh

This file was deleted.

83 changes: 0 additions & 83 deletions weave_query/setup.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,25 @@
import os
import subprocess
import tarfile
import tempfile
import urllib.request
from pathlib import Path
from typing import Union
from urllib.error import HTTPError

from setuptools import find_namespace_packages, setup # type: ignore[import]
from setuptools.command.build import build # type: ignore[import]
from setuptools.command.editable_wheel import editable_wheel # type: ignore[import]
from setuptools.command.sdist import sdist # type: ignore[import]

ROOT = Path(__file__).resolve().parent
SKIP_BUILD = os.environ.get("WEAVE_SKIP_BUILD", False)
IS_BUILT = (ROOT / "weave_query" / "frontend" / "assets").is_dir() or SKIP_BUILD
FORCE_BUILD = os.environ.get("WEAVE_FORCE_BUILD", False)


def check_build_deps() -> bool:
have_yarn = False
try:
subprocess.run(["yarn", "--version"], capture_output=True)
have_yarn = True
except OSError:
pass

if not have_yarn:
try:
print("Attempting to install yarn...")
subprocess.run(["npm", "install", "-g", "yarn"], capture_output=True)
except OSError:
raise RuntimeError(
"You must have node v16+ (https://nodejs.org/en/download) installed to build weave."
)
return True


def build_frontend() -> None:
check_build_deps()
try:
build_script = str(Path("weave_query", "frontend", "build.sh"))
subprocess.run(["bash", build_script], cwd=ROOT)
except OSError:
raise RuntimeError("Failed to build frontend.")


def download_and_extract_tarball(
url: str, extract_path: Union[Path, str] = "."
) -> None:
file_name = os.path.basename(url)
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = os.path.join(temp_dir, file_name)
try:
# Download the tarball
urllib.request.urlretrieve(url, temp_path)
except urllib.error.URLError as e:
raise RuntimeError(f"Couldn't download the tarball {url} due to error: {e}")

try:
# Extract the tarball
if tarfile.is_tarfile(temp_path):
with tarfile.open(temp_path, "r:gz") as tar:
tar.extractall(path=extract_path)
# TODO: detect when the extracted assets are out of sync with git
else:
raise RuntimeError(f"{file_name} is not a tarball file.")
except tarfile.TarError as e:
raise RuntimeError(f"Couldn't extract {file_name} due to error: {e}")


def download_frontend() -> None:
sha = open(ROOT / "weave_query" / "frontend" / "sha1.txt").read().strip()
url = f"https://storage.googleapis.com/wandb-cdn-prod/weave/{sha}.tar.gz"
try:
download_and_extract_tarball(url, extract_path=ROOT / "weave_query")
except HTTPError:
print(f"Warning: Failed to download frontend for sha {sha}")


class Build(build): # type: ignore
def run(self) -> None:
if FORCE_BUILD:
build_frontend()
elif not IS_BUILT:
download_frontend()
super().run()


class EditableWheel(editable_wheel): # type: ignore
def run(self) -> None:
if FORCE_BUILD:
build_frontend()
elif not IS_BUILT:
download_frontend()
super().run()


class Sdist(sdist): # type: ignore
def run(self) -> None:
if FORCE_BUILD:
build_frontend()
elif not IS_BUILT:
download_frontend()
super().run()


Expand Down
14 changes: 0 additions & 14 deletions weave_query/weave_query/frontend/bundle.sh

This file was deleted.

0 comments on commit 0faef09

Please sign in to comment.