Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/javascript-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20]
node-version: [24]

steps:
- name: Check out repository
Expand Down
40 changes: 25 additions & 15 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.12
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.12

- name: Install dependencies
run: pip install -r requirements/pip.txt
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24

- name: Build package
run: python setup.py sdist bdist_wheel
- name: Build JavaScript bundles
run: |
npm ci
npm run build

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
- name: Install dependencies
run: pip install -r requirements/pip.txt

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
81 changes: 65 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
# Python bytecode / caches
*.py[cod]
__pycache__
.pytest_cache
__pycache__/
.pytest_cache/

### Editor and IDE artifacts
# Editor and IDE artifacts
.idea/
.vscode/
*.iml

# C extensions
*.so

# Packages
# Packages / build artifacts
*.egg
*.egg-info
/dist
/build
/eggs
/parts
/bin
/var
/sdist
/develop-eggs
/dist/
/build/
/eggs/
/parts/
/bin/
/var/
/sdist/
/develop-eggs/
/.installed.cfg
/lib
/lib64
/lib/
/lib64/
wheels/
pip-wheel-metadata/

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.cache/
.pytest_cache/
.coverage
.coverage.*
.tox
.tox/
nox/
coverage.xml
htmlcov/
coverage/
test-results/
junit.xml

# Virtual environments
/venv/
/venv-*/
/.venv/
/.venv-*/

# Python type checkers / linters
.mypy_cache/
.ruff_cache/
.pyre/
.pytype/

# The Silver Searcher
.agignore

# OS X artifacts
*.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes

# Logging
log/
logs/
*.log
chromedriver.log
ghostdriver.log

Expand All @@ -58,7 +79,7 @@ output/*.html
output/*/index.html

# Sphinx
docs/_build
docs/_build/
docs/modules.rst
docs/xblocks_contrib.rst
docs/xblocks_contrib.*.rst
Expand All @@ -71,3 +92,31 @@ requirements/private.txt
*.mo
*.pot
*.po

# Node.js / npm / yarn / pnpm
node_modules/
**/node_modules/

npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

.npm/
.yarn/
.pnpm-store/

# Webpack / bundling outputs
public/
**/public/

webpack-stats.json
webpack-stats.*
stats.json

*.hot-update.*
*.map

# Karma
.karma/
**/.karma/
14 changes: 13 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@ include LICENSE.txt
include README.rst
include requirements/base.in
include requirements/constraints.txt
recursive-include xblocks_contrib *.html *.png *.gif *.js *.css *.jpg *.jpeg *.svg
recursive-include xblocks_contrib *.html *.yaml *.png *.gif *.jpg *.jpeg *.svg
recursive-include xblocks_contrib/*/public *.js *.css
recursive-include xblocks_contrib/*/static *.js *.css

# --- EXCLUSIONS ---
prune xblocks_contrib/*/assets
prune xblocks_contrib/*/node_modules
prune */tests
prune */spec
global-exclude webpack*.config.js
global-exclude karma*.js
global-exclude package*.json
global-exclude .gitignore
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"private": true,
"workspaces": [
"xblocks_contrib/*/static"
"xblocks_contrib/*/*"
],
"scripts": {
"build": "npm run build --workspaces",
"build:dev": "npm run build:dev --workspaces",
"test": "npm run test --workspaces",
"test:ci": "npm run test:ci --workspaces"
}
Expand Down
55 changes: 55 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import os
import re
import sys
import shutil
import subprocess

from setuptools import find_packages, setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist


def get_version(*file_paths):
Expand Down Expand Up @@ -151,6 +156,51 @@ def package_data(pkg, sub_roots):
return {pkg: data}


JS_BUILD_DONE = False


def build_js(dist=None):
"""Run npm install & build once. Updates package_data if run."""
global JS_BUILD_DONE
if JS_BUILD_DONE:
return
JS_BUILD_DONE = True

# Skip if no package.json (e.g. installing from PyPI) or no npm
if not os.path.exists("package.json") or not shutil.which("npm"):
if os.path.exists("package.json"):
print("Warning: npm not found, skipping JS build.")
return

try:
print("Building JS assets...")
subprocess.check_call(["npm", "install"])
subprocess.check_call(["npm", "run", "build"])
# Refresh package data to include new assets
if dist:
dist.package_data = package_data("xblocks_contrib", ["static", "public", "templates"])
except Exception as e:
print(f"Warning: JS build failed: {e}. Continuing installation...")


class JSBuildPy(build_py):
def run(self):
build_js(self.distribution)
super().run()


class JSDevelop(develop):
def run(self):
build_js(self.distribution)
super().run()


class JSSdist(sdist):
def run(self):
build_js(self.distribution)
super().run()


VERSION = get_version("xblocks_contrib", "__init__.py")

if sys.argv[-1] == "tag":
Expand Down Expand Up @@ -207,4 +257,9 @@ def package_data(pkg, sub_roots):
]
},
package_data=package_data("xblocks_contrib", ["static", "public", "templates"]),
cmdclass={
"build_py": JSBuildPy,
"develop": JSDevelop,
"sdist": JSSdist,
},
)