Fix /python/servo code formatting.

(My editor screams at me for flake8 lint errors.)
This commit is contained in:
Simon Sapin 2014-09-26 13:52:53 +01:00
parent ab17d31bbf
commit cd45258bf3
6 changed files with 85 additions and 76 deletions

View file

@ -16,6 +16,7 @@ from mach.decorators import (
from servo.command_base import CommandBase, cd from servo.command_base import CommandBase, cd
def host_triple(): def host_triple():
os_type = subprocess.check_output(["uname", "-s"]).strip().lower() os_type = subprocess.check_output(["uname", "-s"]).strip().lower()
if os_type == "linux": if os_type == "linux":
@ -39,8 +40,10 @@ def host_triple():
return "%s-%s" % (cpu_type, os_type) return "%s-%s" % (cpu_type, os_type)
def download(desc, src, dst): def download(desc, src, dst):
recved = [0] recved = [0]
def report(count, bsize, fsize): def report(count, bsize, fsize):
recved[0] += bsize recved[0] += bsize
pct = recved[0] * 100.0 / fsize pct = recved[0] * 100.0 / fsize
@ -53,6 +56,7 @@ def download(desc, src, dst):
if not dumb: if not dumb:
print() print()
def extract(src, dst, movedir=None): def extract(src, dst, movedir=None):
tarfile.open(src).extractall(dst) tarfile.open(src).extractall(dst)
@ -65,6 +69,7 @@ def extract(src, dst, movedir=None):
os.remove(src) os.remove(src)
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
@Command('env', @Command('env',
@ -95,7 +100,8 @@ class MachCommands(CommandBase):
shutil.rmtree(rust_dir) shutil.rmtree(rust_dir)
os.mkdir(rust_dir) os.mkdir(rust_dir)
snapshot_hash = open(path.join(self.context.topdir, "rust-snapshot-hash")).read().strip() filename = path.join(self.context.topdir, "rust-snapshot-hash")
snapshot_hash = open(filename).read().strip()
snapshot_path = "%s-%s.tar.gz" % (snapshot_hash, host_triple()) snapshot_path = "%s-%s.tar.gz" % (snapshot_hash, host_triple())
snapshot_url = "https://servo-rust.s3.amazonaws.com/%s" % snapshot_path snapshot_url = "https://servo-rust.s3.amazonaws.com/%s" % snapshot_path
tgz_file = path.join(rust_dir, path.basename(snapshot_path)) tgz_file = path.join(rust_dir, path.basename(snapshot_path))
@ -147,10 +153,14 @@ class MachCommands(CommandBase):
module_path = components[1] module_path = components[1]
if path.exists(module_path): if path.exists(module_path):
with cd(module_path): with cd(module_path):
output = subprocess.check_output(["git", "status", "--porcelain"]) output = subprocess.check_output(
["git", "status", "--porcelain"])
if len(output) != 0: if len(output) != 0:
print("error: submodule %s is not clean" % module_path) print("error: submodule %s is not clean"
% module_path)
print("\nClean the submodule and try again.") print("\nClean the submodule and try again.")
return 1 return 1
subprocess.check_call(["git", "submodule", "--quiet", "sync", "--recursive"]) subprocess.check_call(
subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"]) ["git", "submodule", "--quiet", "sync", "--recursive"])
subprocess.check_call(
["git", "submodule", "update", "--init", "--recursive"])

View file

@ -1,16 +1,9 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import json
import os
import os.path as path import os.path as path
import shutil
import subprocess import subprocess
import sys
import tarfile
from time import time from time import time
import urllib
from mach.registrar import Registrar
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,
CommandProvider, CommandProvider,
@ -19,6 +12,7 @@ from mach.decorators import (
from servo.command_base import CommandBase, cd from servo.command_base import CommandBase, cd
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
@Command('build', @Command('build',
@ -50,7 +44,9 @@ class MachCommands(CommandBase):
opts += ["-v"] opts += ["-v"]
build_start = time() build_start = time()
status = subprocess.call(["cargo", "build"] + opts, env=self.build_env()) status = subprocess.call(
["cargo", "build"] + opts,
env=self.build_env())
elapsed = time() - build_start elapsed = time() - build_start
print("Build completed in %0.2fs" % elapsed) print("Build completed in %0.2fs" % elapsed)
@ -90,7 +86,8 @@ class MachCommands(CommandBase):
opts = [] opts = []
if jobs is not None: if jobs is not None:
opts += ["-j", jobs] opts += ["-j", jobs]
return subprocess.call(["cargo", "test", "--no-run"], env=self.build_env()) return subprocess.call(
["cargo", "test", "--no-run"], env=self.build_env())
@Command('clean', @Command('clean',
description='Clean the build directory.', description='Clean the build directory.',

View file

@ -1,22 +1,23 @@
import os import os
from os import path from os import path
import contextlib
import subprocess import subprocess
import sys import sys
import toml import toml
from mach.registrar import Registrar from mach.registrar import Registrar
class cd:
@contextlib.contextmanager
def cd(new_path):
"""Context manager for changing the current working directory""" """Context manager for changing the current working directory"""
def __init__(self, newPath): previous_path = os.getcwd()
self.newPath = newPath try:
os.chdir(new_path)
yield
finally:
os.chdir(previous_path)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
class CommandBase(object): class CommandBase(object):
"""Base class for mach command providers. """Base class for mach command providers.
@ -42,23 +43,29 @@ class CommandBase(object):
self.config["tools"].setdefault("rust-root", "") self.config["tools"].setdefault("rust-root", "")
self.config["tools"].setdefault("cargo-root", "") self.config["tools"].setdefault("cargo-root", "")
if not self.config["tools"]["system-rust"]: if not self.config["tools"]["system-rust"]:
self.config["tools"]["rust-root"] = path.join(context.topdir, "rust") self.config["tools"]["rust-root"] = path.join(
context.topdir, "rust")
if not self.config["tools"]["system-cargo"]: if not self.config["tools"]["system-cargo"]:
self.config["tools"]["cargo-root"] = path.join(context.topdir, "cargo") self.config["tools"]["cargo-root"] = path.join(
context.topdir, "cargo")
def build_env(self): def build_env(self):
"""Return an extended environment dictionary.""" """Return an extended environment dictionary."""
env = os.environ.copy() env = os.environ.copy()
extra_path = [] extra_path = []
extra_lib = [] extra_lib = []
if not self.config["tools"]["system-rust"] or self.config["tools"]["rust-root"]: if not self.config["tools"]["system-rust"] \
or self.config["tools"]["rust-root"]:
extra_path += [path.join(self.config["tools"]["rust-root"], "bin")] extra_path += [path.join(self.config["tools"]["rust-root"], "bin")]
extra_lib += [path.join(self.config["tools"]["rust-root"], "lib")] extra_lib += [path.join(self.config["tools"]["rust-root"], "lib")]
if not self.config["tools"]["system-cargo"] or self.config["tools"]["cargo-root"]: if not self.config["tools"]["system-cargo"] \
extra_path += [path.join(self.config["tools"]["cargo-root"], "bin")] or self.config["tools"]["cargo-root"]:
extra_path += [
path.join(self.config["tools"]["cargo-root"], "bin")]
if extra_path: if extra_path:
env["PATH"] = "%s%s%s" % (os.pathsep.join(extra_path), os.pathsep, env["PATH"]) env["PATH"] = "%s%s%s" % (
os.pathsep.join(extra_path), os.pathsep, env["PATH"])
if extra_lib: if extra_lib:
if sys.platform == "darwin": if sys.platform == "darwin":
env["DYLD_LIBRARY_PATH"] = "%s%s%s" % \ env["DYLD_LIBRARY_PATH"] = "%s%s%s" % \
@ -74,7 +81,8 @@ class CommandBase(object):
return env return env
def ensure_bootstrapped(self): def ensure_bootstrapped(self):
if self.context.bootstrapped: return if self.context.bootstrapped:
return
submodules = subprocess.check_output(["git", "submodule", "status"]) submodules = subprocess.check_output(["git", "submodule", "status"])
for line in submodules.split('\n'): for line in submodules.split('\n'):
@ -82,13 +90,16 @@ class CommandBase(object):
if len(components) > 1 and components[0].startswith(('-', '+')): if len(components) > 1 and components[0].startswith(('-', '+')):
module_path = components[1] module_path = components[1]
subprocess.check_call(["git", "submodule", "update", subprocess.check_call(["git", "submodule", "update",
"--init", "--recursive", "--", module_path]) "--init", "--recursive",
"--", module_path])
if not self.config["tools"]["system-rust"] and \ if not self.config["tools"]["system-rust"] and \
not path.exists(path.join(self.context.topdir, "rust", "bin", "rustc")): not path.exists(path.join(
self.context.topdir, "rust", "bin", "rustc")):
Registrar.dispatch("bootstrap-rust", context=self.context) Registrar.dispatch("bootstrap-rust", context=self.context)
if not self.config["tools"]["system-cargo"] and \ if not self.config["tools"]["system-cargo"] and \
not path.exists(path.join(self.context.topdir, "cargo", "bin", "cargo")): not path.exists(path.join(
self.context.topdir, "cargo", "bin", "cargo")):
Registrar.dispatch("bootstrap-cargo", context=self.context) Registrar.dispatch("bootstrap-cargo", context=self.context)
self.context.bootstrapped = True self.context.bootstrapped = True

View file

@ -1,16 +1,7 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import json
import os
import os.path as path
import shutil
import subprocess import subprocess
import sys
import tarfile
from time import time
import urllib
from mach.registrar import Registrar
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,
CommandProvider, CommandProvider,
@ -19,14 +10,16 @@ from mach.decorators import (
from servo.command_base import CommandBase from servo.command_base import CommandBase
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
@Command('cargo', @Command('cargo',
description='Run Cargo', description='Run Cargo',
category='devenv', category='devenv',
allow_all_args=True) allow_all_args=True)
@CommandArgument('params', default=None, nargs='...', @CommandArgument(
help="Command-line arguments to be passed through to Cargo") 'params', default=None, nargs='...',
help="Command-line arguments to be passed through to Cargo")
def cargo(self, params): def cargo(self, params):
return subprocess.call(["cargo"] + params, return subprocess.call(["cargo"] + params,
env=self.build_env()) env=self.build_env())
@ -35,7 +28,8 @@ class MachCommands(CommandBase):
description='Run the Rust compiler', description='Run the Rust compiler',
category='devenv', category='devenv',
allow_all_args=True) allow_all_args=True)
@CommandArgument('params', default=None, nargs='...', @CommandArgument(
help="Command-line arguments to be passed through to rustc") 'params', default=None, nargs='...',
help="Command-line arguments to be passed through to rustc")
def rustc(self, params): def rustc(self, params):
return subprocess.call(["rustc"] + params, env=self.build_env()) return subprocess.call(["rustc"] + params, env=self.build_env())

View file

@ -1,16 +1,8 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import json
import os
import os.path as path import os.path as path
import shutil
import subprocess import subprocess
import sys
import tarfile
from time import time
import urllib
from mach.registrar import Registrar
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,
CommandProvider, CommandProvider,
@ -19,14 +11,16 @@ from mach.decorators import (
from servo.command_base import CommandBase from servo.command_base import CommandBase
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
@Command('run', @Command('run',
description='Run Servo', description='Run Servo',
category='post-build', category='post-build',
allow_all_args=True) allow_all_args=True)
@CommandArgument('params', default=None, nargs='...', @CommandArgument(
help="Command-line arguments to be passed through to Servo") 'params', default=None, nargs='...',
help="Command-line arguments to be passed through to Servo")
def run(self, params): def run(self, params):
subprocess.check_call([path.join("target", "servo")] + params, subprocess.check_call([path.join("target", "servo")] + params,
env=self.build_env()) env=self.build_env())
@ -35,10 +29,10 @@ class MachCommands(CommandBase):
description='Generate documentation', description='Generate documentation',
category='post-build', category='post-build',
allow_all_args=True) allow_all_args=True)
@CommandArgument('params', default=None, nargs='...', @CommandArgument(
help="Command-line arguments to be passed through to cargo doc") 'params', default=None, nargs='...',
help="Command-line arguments to be passed through to cargo doc")
def doc(self, params): def doc(self, params):
self.ensure_bootstrapped() self.ensure_bootstrapped()
return subprocess.call(["cargo", "doc"] + params, return subprocess.call(["cargo", "doc"] + params,
env=self.build_env()) env=self.build_env())

View file

@ -1,14 +1,9 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import json
import os import os
import os.path as path import os.path as path
import shutil
import subprocess import subprocess
import sys
import tarfile
from time import time from time import time
import urllib
from mach.registrar import Registrar from mach.registrar import Registrar
from mach.decorators import ( from mach.decorators import (
@ -20,6 +15,7 @@ from mach.decorators import (
from servo.command_base import CommandBase from servo.command_base import CommandBase
import tidy import tidy
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
def __init__(self, context): def __init__(self, context):
@ -28,13 +24,15 @@ class MachCommands(CommandBase):
self.context.built_tests = False self.context.built_tests = False
def ensure_built_tests(self): def ensure_built_tests(self):
if self.context.built_tests: return if self.context.built_tests:
return
Registrar.dispatch('build-tests', context=self.context) Registrar.dispatch('build-tests', context=self.context)
self.context.built_tests = True self.context.built_tests = True
def find_test(self, prefix): def find_test(self, prefix):
candidates = [f for f in os.listdir(path.join(self.context.topdir, "target")) candidates = [
if f.startswith(prefix + "-")] f for f in os.listdir(path.join(self.context.topdir, "target"))
if f.startswith(prefix + "-")]
if candidates: if candidates:
return path.join(self.context.topdir, "target", candidates[0]) return path.join(self.context.topdir, "target", candidates[0])
return None return None
@ -61,8 +59,9 @@ class MachCommands(CommandBase):
allow_all_args=True) allow_all_args=True)
@CommandArgument('test_name', default=None, nargs="...", @CommandArgument('test_name', default=None, nargs="...",
help="Only run tests that match this pattern") help="Only run tests that match this pattern")
@CommandArgument('params', default=None, nargs="...", @CommandArgument(
help="Command-line arguments to be passed to the test harness") 'params', default=None, nargs="...",
help="Command-line arguments to be passed to the test harness")
def test_unit(self, test_name=None, params=None): def test_unit(self, test_name=None, params=None):
if params is None: if params is None:
params = [] params = []
@ -79,8 +78,9 @@ class MachCommands(CommandBase):
help="'cpu' or 'gpu' (default both)") help="'cpu' or 'gpu' (default both)")
@CommandArgument('test_name', default=None, nargs="?", @CommandArgument('test_name', default=None, nargs="?",
help="Only run tests that match this pattern") help="Only run tests that match this pattern")
@CommandArgument('servo_params', default=None, nargs="...", @CommandArgument(
help="Command-line arguments to be passed through to Servo") 'servo_params', default=None, nargs="...",
help="Command-line arguments to be passed through to Servo")
def test_ref(self, kind=None, test_name=None, servo_params=None): def test_ref(self, kind=None, test_name=None, servo_params=None):
self.ensure_bootstrapped() self.ensure_bootstrapped()
self.ensure_built_tests() self.ensure_built_tests()
@ -103,7 +103,8 @@ class MachCommands(CommandBase):
print("Reference tests completed in %0.2fs" % elapsed) print("Reference tests completed in %0.2fs" % elapsed)
if error: return 1 if error:
return 1
@Command('test-content', @Command('test-content',
description='Run the content tests', description='Run the content tests',
@ -138,10 +139,12 @@ class MachCommands(CommandBase):
description='Run the web platform tests', description='Run the web platform tests',
category='testing', category='testing',
allow_all_args=True) allow_all_args=True)
@CommandArgument('params', default=None, nargs='...', @CommandArgument(
help="Command-line arguments to be passed through to wpt/run.sh") 'params', default=None, nargs='...',
help="Command-line arguments to be passed through to wpt/run.sh")
def test_wpt(self, params=None): def test_wpt(self, params=None):
if params is None: if params is None:
params = [] params = []
return subprocess.call(["bash", path.join("tests", "wpt", "run.sh")] + params, return subprocess.call(
env=self.build_env()) ["bash", path.join("tests", "wpt", "run.sh")] + params,
env=self.build_env())