Skip to content

Commit

Permalink
Don't build the generated javascript files when running the build
Browse files Browse the repository at this point in the history
To avoid adding a dependency on `npm` when building the package, check
in the generated javascript files in the tree.
  • Loading branch information
pablogsal committed Apr 12, 2022
1 parent 8737178 commit 3b9cafe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ on:
- main

jobs:
check_generated_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -qy npm git
- name: Check if files are up to date
run: make build-js
- name: Check for changes
run: |
git add -u
changes=$(git status --porcelain)
# Check for changes in regenerated files
if test -n "$changes"; then
echo "Generated files not up to date."
echo "$changes"
echo ""
git diff --staged || true
exit 1
fi
test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -23,7 +46,7 @@ jobs:
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -qy libunwind-dev pkg-config nodejs npm
sudo apt-get install -qy libunwind-dev pkg-config npm
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
Expand All @@ -42,7 +65,7 @@ jobs:
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -qy clang-format nodejs npm libunwind-dev pkg-config
sudo apt-get install -qy clang-format npm libunwind-dev pkg-config
npm install -g prettier
- name: Install Python dependencies
run: |
Expand All @@ -68,7 +91,7 @@ jobs:
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -qy libunwind-dev pkg-config nodejs npm valgrind
sudo apt-get install -qy libunwind-dev pkg-config npm valgrind
- name: Install Python dependencies and package
run: |
python3 -m pip install --upgrade pip
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ cython_debug/
# memray stuff
pensieve-*

# Generated files
**/templates/assets/*.js

# VSCode
.devcontainer
.vscode
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ build-ext: ## Build package extensions in-place
$(PYTHON) setup.py build_ext --inplace

$(reporters_path)/templates/assets/%.js: $(reporters_path)/assets/%.js
$(PYTHON) setup.py build_js
$(NPM) install
$(NPM) run-script build
touch $(generated_js_files)

.PHONY: build-js
Expand Down Expand Up @@ -178,7 +179,6 @@ gh-pages: ## Publish documentation on BBGitHub Pages
clean: ## Clean any built/generated artifacts
find . | grep -E '(\.o|\.so|\.gcda|\.gcno|\.gcov\.json\.gz)' | xargs rm -rf
find . | grep -E '(__pycache__|\.pyc|\.pyo)' | xargs rm -rf
find src/memray/reporters/templates/assets | grep -E '\.js' | xargs rm -rf
rm -f src/memray/_memray.cpp
rm -f memray.info
rm -rf memray-coverage
Expand Down
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,11 @@
from sys import version_info

from Cython.Build import cythonize
from setuptools import Command
from setuptools import Extension
from setuptools import find_namespace_packages
from setuptools import setup
from setuptools.command.build_ext import build_ext as build_ext_orig


class BuildJSCommand(Command):
"""A custom command to run `npm install` during setup.py build."""

user_options = []
description = "Run `npm install`"

def initialize_options(self):
"""Required override."""

def finalize_options(self):
"""Required override."""

def run(self):
def announce_and_run(command):
self.announce(
"executing an `{}`".format(" ".join(command)),
level=distutils.log.INFO,
)
subprocess.run(command, check=True)

announce_and_run(["npm", "install"])
announce_and_run(["npm", "run-script", "build"])


LIBBACKTRACE_LOCATION = (
pathlib.Path(__file__).parent / "src" / "vendor" / "libbacktrace"
).resolve()
Expand Down Expand Up @@ -106,9 +80,6 @@ def build_js_files(self):
self.announce_and_run(["npm", "run-script", "build"])


# Add our custom build step to distutils's build command.
distutils.command.build.build.sub_commands.insert(0, ("build_js", None))

install_requires = [
"jinja2",
"typing_extensions; python_version < '3.8.0'",
Expand Down Expand Up @@ -285,7 +256,6 @@ def build_js_files(self):
],
},
cmdclass={
"build_js": BuildJSCommand,
"build_ext": BuildPensieve,
},
package_data={"memray": ["py.typed"]},
Expand Down
9 changes: 9 additions & 0 deletions src/memray/reporters/templates/assets/flamegraph.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/memray/reporters/templates/assets/table.js

Large diffs are not rendered by default.

0 comments on commit 3b9cafe

Please sign in to comment.