Skip to content

Commit

Permalink
Better way of compiling javascript sources in setuptools
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Jun 23, 2021
1 parent 06d2fc5 commit 88b7d24
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pip-log.txt
*.un~
Session.vim

# VSCode
.vscode/*
*.code-workspace
.history/

# test stuff
.cache
__pycache__
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ install_requires =
zip_safe = False
include_package_data = True

[options.package_data]
* = WebApp/static

[options.packages.find]
where=src

Expand Down
90 changes: 64 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import subprocess
from pathlib import Path
from setuptools import setup


# HACK: Compile the webapp sources
subprocess.run(
[
"docker",
"run",
"--rm",
f"-v={Path(__file__).parent}:/shared",
"-w=/shared",
"diracgrid/dirac-distribution",
"/dirac-webapp-compile.py",
"-D=/shared/src",
"-n=WebAppDIRAC",
],
check=True
)

# This is required to allow editable pip installs while using the declarative configuration (setup.cfg)
setup()

# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if os.path.exists('MANIFEST'): os.remove('MANIFEST')

from setuptools import Command, setup
# Note: distutils must be imported after setuptools
from distutils import log
from setuptools.command.develop import develop as _develop
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel


class build_extjs_sources(Command):
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def get_inputs(self):
return []

def get_outputs(self):
return []

def run(self):
path = os.path.abspath(os.getcwd())
cmd = [
"docker",
"run",
"--rm",
f"-v={path}:/shared",
"-w=/shared",
"diracgrid/dirac-distribution",
"/dirac-webapp-compile.py",
"-D=/shared/src",
"-n=WebAppDIRAC",
]
log.info('> %r', cmd)
subprocess.check_call(cmd)


class develop(_develop):
def run(self):
self.run_command("build_extjs_sources")
super().run()


class bdist_wheel(_bdist_wheel):
def run(self):
self.run_command("build_extjs_sources")
super().run()


cmdclass = {
"develop": develop,
"bdist_wheel": bdist_wheel,
"build_extjs_sources": build_extjs_sources,
}

setup(cmdclass=cmdclass)

0 comments on commit 88b7d24

Please sign in to comment.