Skip to content

Commit

Permalink
update buildsetup to yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
tardyp committed Oct 23, 2016
1 parent 7adeab9 commit d8f9196
Show file tree
Hide file tree
Showing 17 changed files with 16,016 additions and 62 deletions.
129 changes: 82 additions & 47 deletions pkg/buildbot_pkg.py
Expand Up @@ -13,19 +13,31 @@
#
# Copyright Buildbot Team Members

# Method to add build step taken from here
# https://seasonofcode.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy.html
import distutils.cmd
import os
import subprocess
# XXX(sa2ajj): this is an interesting mix of distutils and setuptools. Needs
# to be reviewed.
from distutils.command.build import build
from distutils.version import LooseVersion

import setuptools.command.build_py
import setuptools.command.egg_info
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.egg_info import egg_info

old_listdir = os.listdir


def listdir(path):
# patch listdir to avoid looking into node_modules
l = old_listdir(path)
if "node_modules" in l:
l.remove("node_modules")
return l
os.listdir = listdir


def check_output(cmd):
"""Version of check_output which does not throw error"""
popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
return popen.communicate()[0].strip()

Expand Down Expand Up @@ -92,59 +104,82 @@ def getVersion(init_file):
# This is why we override both egg_info and build, and the first run build
# the js.

js_built = False


def build_js(cmd):
global js_built
if js_built:
return
package = cmd.distribution.packages[0]
if os.path.exists("gulpfile.js"):
npm_version = check_output("npm -v")
npm_bin = check_output("npm bin").strip()
assert npm_version != "", "need nodejs and npm installed in current PATH"
assert LooseVersion(npm_version) >= LooseVersion(
"1.4"), "npm < 1.4 (%s)" % (npm_version)
npm_cmd = ['npm', 'install']
gulp_cmd = [os.path.join(npm_bin, "gulp"), 'prod', '--notests']
if os.name == 'nt':
subprocess.call(npm_cmd, shell=True)
subprocess.call(gulp_cmd, shell=True)
else:
cmd.spawn(npm_cmd)
cmd.spawn(gulp_cmd)

cmd.copy_tree(os.path.join(package, 'static'), os.path.join(
"build", "lib", package, "static"))
class BuildJsCommand(distutils.cmd.Command):
"""A custom command to run JS build."""

with open(os.path.join("build", "lib", package, "VERSION"), "w") as f:
f.write(cmd.distribution.metadata.version)
description = 'run JS build'
already_run = False
def initialize_options(self):
"""Set default values for options."""

with open(os.path.join(package, "VERSION"), "w") as f:
f.write(cmd.distribution.metadata.version)
def finalize_options(self):
"""Post-process options."""

js_built = True


class my_build(build):
def run(self):
"""Run command."""
if self.already_run:
return
package = self.distribution.packages[0]
if os.path.exists("gulpfile.js"):
yarn_version = check_output("yarn --version")
npm_version = check_output("npm -v")
print "yarn:", yarn_version, "npm: ", npm_version
npm_bin = check_output("npm bin").strip()
assert npm_version != "", "need nodejs and npm installed in current PATH"
assert LooseVersion(npm_version) >= LooseVersion(
"1.4"), "npm < 1.4 (%s)" % (npm_version)
# if we find yarn, then we use it as it is much faster
if yarn_version != "":
npm_cmd = ['yarn', 'install']
else:
npm_cmd = ['npm', 'install']
gulp_cmd = [os.path.join(npm_bin, "gulp"), 'prod', '--notests']

if os.name == 'nt':
shell = True
else:
shell = False

for command in [npm_cmd, gulp_cmd]:
self.announce(
'Running command: %s' % str(" ".join(command)),
level=distutils.log.INFO)
subprocess.call(command, shell=shell)

self.copy_tree(os.path.join(package, 'static'), os.path.join(
"build", "lib", package, "static"))

with open(os.path.join("build", "lib", package, "VERSION"), "w") as f:
f.write(self.distribution.metadata.version)

with open(os.path.join(package, "VERSION"), "w") as f:
f.write(self.distribution.metadata.version)

self.already_run = True


class BuildPyCommand(setuptools.command.build_py.build_py):
"""Custom build command."""

def run(self):
build_js(self)
return build.run(self)
self.run_command('build_js')
setuptools.command.build_py.build_py.run(self)


class my_egg_info(egg_info):
class EggInfoCommand(setuptools.command.egg_info.egg_info):
"""Custom egginfo command."""

def run(self):
build_js(self)
return egg_info.run(self)

self.run_command('build_js')
setuptools.command.egg_info.egg_info.run(self)

def setup_www_plugin(**kw):
package = kw['packages'][0]
if 'version' not in kw:
kw['version'] = getVersion(os.path.join(package, "__init__.py"))
setup(cmdclass=dict(build=my_build,
egg_info=my_egg_info),
**kw)

setup(cmdclass=dict(
egg_info=EggInfoCommand,
build_py=BuildPyCommand,
build_js=BuildJsCommand),
**kw)
4 changes: 2 additions & 2 deletions www/base/package.json
Expand Up @@ -5,8 +5,8 @@
"npm": ">=1.4.10"
},
"dependencies": {
"guanlecoja": "~0.7.0",
"gulp": "3.9.0",
"guanlecoja": "~0.8.0",
"gulp": "3.9.1",
"gulp-shell": "^0.4.1",
"http-proxy": "^1.11.1",
"minimist": "^1.1.1"
Expand Down
2 changes: 1 addition & 1 deletion www/base/src/app/builders/builders.tpl.jade
Expand Up @@ -37,7 +37,7 @@
span(ng-show="tags_filter.length > 0")
span.label.label-danger(ng-click="tags_filter = []") x
th(style="width:20%px;") Workers
tr(ng-repeat='builder in builders | filter: isBuilderFiltered | orderBy: "name"')
tr(ng-repeat='builder in builders | filter: isBuilderFiltered | orderBy: "name"')
td(style="width:200px")
a(ui-sref='builder({builder: builder.builderid})')
| {{ builder.name }}
Expand Down
6 changes: 3 additions & 3 deletions www/base/src/app/builders/builds/build.tpl.jade
Expand Up @@ -22,9 +22,9 @@
uib-tab(heading="Worker: {{worker.name}}")
table.table.table-hover.table-striped.table-condensed
tbody
tr
td.text-left name
td.text-center {{worker.name}}
tr
td.text-left name
td.text-center {{worker.name}}
tr(ng-repeat="(name, value) in worker.workerinfo")
td.text-left {{ name }}
td.text-right {{ value }}
Expand Down
2 changes: 1 addition & 1 deletion www/base/src/app/index.jade
@@ -1,4 +1,4 @@
extends layout
extends layout.jade
block content
gl-page-with-sidebar
gl-topbar
Expand Down
4 changes: 2 additions & 2 deletions www/base/src/app/schedulers/schedulers.tpl.jade
Expand Up @@ -5,14 +5,14 @@
tr
td Scheduler Name
td Master
tr(ng-repeat='scheduler in schedulers | orderBy: ["name"]')
tr(ng-repeat='scheduler in schedulers | orderBy: ["name"]')
td {{ scheduler.name }}
td {{ scheduler.master.name }}
uib-tab(heading="All schedulers by master")
table.table.table-hover.table-striped.table-condensed
tr
td Scheduler Name
td Master
tr(ng-repeat='scheduler in schedulers | orderBy: ["master.name", "name"]')
tr(ng-repeat='scheduler in schedulers | orderBy: ["master.name", "name"]')
td {{ scheduler.name }}
td {{ scheduler.master.name }}

0 comments on commit d8f9196

Please sign in to comment.