Skip to content

Instantly share code, notes, and snippets.

@machristie
Created February 3, 2022 20:36
Show Gist options
  • Save machristie/7421b2ae91f0d28345f7e52cd94216f6 to your computer and use it in GitHub Desktop.
Save machristie/7421b2ae91f0d28345f7e52cd94216f6 to your computer and use it in GitHub Desktop.
javascript install in python setup.py
import distutils
import os
import subprocess
import setuptools
from setuptools.command.develop import develop
from setuptools.command.install import install
def build_js():
subprocess.check_call(["yarn"], cwd=os.path.join(os.getcwd(), "trecx_django_app"))
subprocess.check_call(["yarn", "run", "build"], cwd=os.path.join(os.getcwd(), "trecx_django_app"))
# Build JS code when this package is installed in virtual env
# https://stackoverflow.com/a/36902139
class BuildJSDevelopCommand(develop):
def run(self):
self.announce("Building JS code", level=distutils.log.INFO)
build_js()
super().run()
class BuildJSInstallCommand(install):
def run(self):
self.announce("Building JS code", level=distutils.log.INFO)
build_js()
super().run()
setuptools.setup(
cmdclass={
'develop': BuildJSDevelopCommand,
'install': BuildJSInstallCommand,
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment