File size: 2,585 Bytes
fc0f7bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import argparse
import logging
import os
import shutil
import subprocess
import sys
from _utils import _ensure_cwd_is_fairlearn_root_dir, _LogWrapper
_logger = logging.getLogger(__file__)
logging.basicConfig(level=logging.INFO)
_widget_js_directory = os.path.join("fairlearn", "widget", "js")
_widget_generated_files = [
'fairlearn/widget/static/extension.js',
'fairlearn/widget/static/extension.js.map',
'fairlearn/widget/static/index.js',
'fairlearn/widget/static/index.js.map',
'jupyter-config/nbconfig/notebook.d/fairlearn-widget.json',
'fairlearn/widget/js/fairlearn_widget/labextension/fairlearn-widget-0.1.0.tgz'
]
def build_argument_parser():
desc = "Build widget for fairlearn dashboard"
parser = argparse.ArgumentParser(description=desc)
# example for yarn_path: 'C:\Program Files (x86)\Yarn\bin\yarn.cmd'
parser.add_argument("--yarn-path",
help="The full path to the yarn executable.",
required=True)
parser.add_argument("--assert-no-changes",
help="Assert that the generated files did not change.",
required=False,
default=False,
action='store_true')
return parser
def main(argv):
_ensure_cwd_is_fairlearn_root_dir()
parser = build_argument_parser()
args = parser.parse_args(argv)
with _LogWrapper("yarn install of dependencies"):
subprocess.check_call([args.yarn_path, "install"],
cwd=os.path.join(os.getcwd(), _widget_js_directory))
with _LogWrapper("yarn build"):
subprocess.check_call([args.yarn_path, "build:all"],
cwd=os.path.join(os.getcwd(), _widget_js_directory))
with _LogWrapper("removal of extra directories"):
shutil.rmtree(os.path.join(_widget_js_directory, "dist"))
shutil.rmtree(os.path.join(_widget_js_directory, "lib"))
shutil.rmtree(os.path.join(_widget_js_directory, "node_modules"))
if args.assert_no_changes:
with _LogWrapper("comparison between old and newly generated widget files."):
for file_path in _widget_generated_files:
# git diff occasionally leaves out some of the JS files so use git status
diff_result = subprocess.check_output(["git", "status"])
if file_path in diff_result.decode('utf-8'):
raise Exception("File {} was unexpectedly modified.".format(file_path))
if __name__ == "__main__":
main(sys.argv[1:])
|