Created
February 3, 2022 20:36
-
-
Save machristie/7421b2ae91f0d28345f7e52cd94216f6 to your computer and use it in GitHub Desktop.
javascript install in python setup.py
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
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