aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2014-09-26 13:52:53 +0100
committerSimon Sapin <simon.sapin@exyr.org>2014-09-26 23:12:51 +0100
commitcd45258bf387be2c07f35b87737b5e46e27f14b3 (patch)
tree28180c4d0d1767409f474153430e78a11e929a83 /python
parentab17d31bbf8c6884f858381f3d5b7e62c4de87c6 (diff)
downloadservo-cd45258bf387be2c07f35b87737b5e46e27f14b3.tar.gz
servo-cd45258bf387be2c07f35b87737b5e46e27f14b3.zip
Fix /python/servo code formatting.
(My editor screams at me for flake8 lint errors.)
Diffstat (limited to 'python')
-rw-r--r--python/servo/bootstrap_commands.py20
-rw-r--r--python/servo/build_commands.py15
-rw-r--r--python/servo/command_base.py49
-rw-r--r--python/servo/devenv_commands.py20
-rw-r--r--python/servo/post_build_commands.py20
-rw-r--r--python/servo/testing_commands.py37
6 files changed, 85 insertions, 76 deletions
diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py
index bf83803afac..1d682adb7f5 100644
--- a/python/servo/bootstrap_commands.py
+++ b/python/servo/bootstrap_commands.py
@@ -16,6 +16,7 @@ from mach.decorators import (
from servo.command_base import CommandBase, cd
+
def host_triple():
os_type = subprocess.check_output(["uname", "-s"]).strip().lower()
if os_type == "linux":
@@ -39,8 +40,10 @@ def host_triple():
return "%s-%s" % (cpu_type, os_type)
+
def download(desc, src, dst):
recved = [0]
+
def report(count, bsize, fsize):
recved[0] += bsize
pct = recved[0] * 100.0 / fsize
@@ -53,6 +56,7 @@ def download(desc, src, dst):
if not dumb:
print()
+
def extract(src, dst, movedir=None):
tarfile.open(src).extractall(dst)
@@ -65,6 +69,7 @@ def extract(src, dst, movedir=None):
os.remove(src)
+
@CommandProvider
class MachCommands(CommandBase):
@Command('env',
@@ -95,7 +100,8 @@ class MachCommands(CommandBase):
shutil.rmtree(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_url = "https://servo-rust.s3.amazonaws.com/%s" % snapshot_path
tgz_file = path.join(rust_dir, path.basename(snapshot_path))
@@ -147,10 +153,14 @@ class MachCommands(CommandBase):
module_path = components[1]
if path.exists(module_path):
with cd(module_path):
- output = subprocess.check_output(["git", "status", "--porcelain"])
+ output = subprocess.check_output(
+ ["git", "status", "--porcelain"])
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.")
return 1
- subprocess.check_call(["git", "submodule", "--quiet", "sync", "--recursive"])
- subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"])
+ subprocess.check_call(
+ ["git", "submodule", "--quiet", "sync", "--recursive"])
+ subprocess.check_call(
+ ["git", "submodule", "update", "--init", "--recursive"])
diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py
index 3b34e575443..d31b5a64d89 100644
--- a/python/servo/build_commands.py
+++ b/python/servo/build_commands.py
@@ -1,16 +1,9 @@
from __future__ import print_function, unicode_literals
-import json
-import os
import os.path as path
-import shutil
import subprocess
-import sys
-import tarfile
from time import time
-import urllib
-from mach.registrar import Registrar
from mach.decorators import (
CommandArgument,
CommandProvider,
@@ -19,6 +12,7 @@ from mach.decorators import (
from servo.command_base import CommandBase, cd
+
@CommandProvider
class MachCommands(CommandBase):
@Command('build',
@@ -50,7 +44,9 @@ class MachCommands(CommandBase):
opts += ["-v"]
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
print("Build completed in %0.2fs" % elapsed)
@@ -90,7 +86,8 @@ class MachCommands(CommandBase):
opts = []
if jobs is not None:
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',
description='Clean the build directory.',
diff --git a/python/servo/command_base.py b/python/servo/command_base.py
index a5b4a555190..dd02446eb63 100644
--- a/python/servo/command_base.py
+++ b/python/servo/command_base.py
@@ -1,22 +1,23 @@
import os
from os import path
+import contextlib
import subprocess
import sys
import toml
from mach.registrar import Registrar
-class cd:
- """Context manager for changing the current working directory"""
- def __init__(self, newPath):
- self.newPath = newPath
- def __enter__(self):
- self.savedPath = os.getcwd()
- os.chdir(self.newPath)
+@contextlib.contextmanager
+def cd(new_path):
+ """Context manager for changing the current working directory"""
+ previous_path = os.getcwd()
+ try:
+ os.chdir(new_path)
+ yield
+ finally:
+ os.chdir(previous_path)
- def __exit__(self, etype, value, traceback):
- os.chdir(self.savedPath)
class CommandBase(object):
"""Base class for mach command providers.
@@ -42,23 +43,29 @@ class CommandBase(object):
self.config["tools"].setdefault("rust-root", "")
self.config["tools"].setdefault("cargo-root", "")
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"]:
- self.config["tools"]["cargo-root"] = path.join(context.topdir, "cargo")
+ self.config["tools"]["cargo-root"] = path.join(
+ context.topdir, "cargo")
def build_env(self):
"""Return an extended environment dictionary."""
env = os.environ.copy()
extra_path = []
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_lib += [path.join(self.config["tools"]["rust-root"], "lib")]
- if not self.config["tools"]["system-cargo"] or self.config["tools"]["cargo-root"]:
- extra_path += [path.join(self.config["tools"]["cargo-root"], "bin")]
+ if not self.config["tools"]["system-cargo"] \
+ or self.config["tools"]["cargo-root"]:
+ extra_path += [
+ path.join(self.config["tools"]["cargo-root"], "bin")]
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 sys.platform == "darwin":
env["DYLD_LIBRARY_PATH"] = "%s%s%s" % \
@@ -74,7 +81,8 @@ class CommandBase(object):
return env
def ensure_bootstrapped(self):
- if self.context.bootstrapped: return
+ if self.context.bootstrapped:
+ return
submodules = subprocess.check_output(["git", "submodule", "status"])
for line in submodules.split('\n'):
@@ -82,13 +90,16 @@ class CommandBase(object):
if len(components) > 1 and components[0].startswith(('-', '+')):
module_path = components[1]
subprocess.check_call(["git", "submodule", "update",
- "--init", "--recursive", "--", module_path])
+ "--init", "--recursive",
+ "--", module_path])
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)
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)
self.context.bootstrapped = True
diff --git a/python/servo/devenv_commands.py b/python/servo/devenv_commands.py
index 402c18f2767..f186427ba4a 100644
--- a/python/servo/devenv_commands.py
+++ b/python/servo/devenv_commands.py
@@ -1,16 +1,7 @@
from __future__ import print_function, unicode_literals
-import json
-import os
-import os.path as path
-import shutil
import subprocess
-import sys
-import tarfile
-from time import time
-import urllib
-from mach.registrar import Registrar
from mach.decorators import (
CommandArgument,
CommandProvider,
@@ -19,14 +10,16 @@ from mach.decorators import (
from servo.command_base import CommandBase
+
@CommandProvider
class MachCommands(CommandBase):
@Command('cargo',
description='Run Cargo',
category='devenv',
allow_all_args=True)
- @CommandArgument('params', default=None, nargs='...',
- help="Command-line arguments to be passed through to Cargo")
+ @CommandArgument(
+ 'params', default=None, nargs='...',
+ help="Command-line arguments to be passed through to Cargo")
def cargo(self, params):
return subprocess.call(["cargo"] + params,
env=self.build_env())
@@ -35,7 +28,8 @@ class MachCommands(CommandBase):
description='Run the Rust compiler',
category='devenv',
allow_all_args=True)
- @CommandArgument('params', default=None, nargs='...',
- help="Command-line arguments to be passed through to rustc")
+ @CommandArgument(
+ 'params', default=None, nargs='...',
+ help="Command-line arguments to be passed through to rustc")
def rustc(self, params):
return subprocess.call(["rustc"] + params, env=self.build_env())
diff --git a/python/servo/post_build_commands.py b/python/servo/post_build_commands.py
index 276a772c787..b09a3daaa15 100644
--- a/python/servo/post_build_commands.py
+++ b/python/servo/post_build_commands.py
@@ -1,16 +1,8 @@
from __future__ import print_function, unicode_literals
-import json
-import os
import os.path as path
-import shutil
import subprocess
-import sys
-import tarfile
-from time import time
-import urllib
-from mach.registrar import Registrar
from mach.decorators import (
CommandArgument,
CommandProvider,
@@ -19,14 +11,16 @@ from mach.decorators import (
from servo.command_base import CommandBase
+
@CommandProvider
class MachCommands(CommandBase):
@Command('run',
description='Run Servo',
category='post-build',
allow_all_args=True)
- @CommandArgument('params', default=None, nargs='...',
- help="Command-line arguments to be passed through to Servo")
+ @CommandArgument(
+ 'params', default=None, nargs='...',
+ help="Command-line arguments to be passed through to Servo")
def run(self, params):
subprocess.check_call([path.join("target", "servo")] + params,
env=self.build_env())
@@ -35,10 +29,10 @@ class MachCommands(CommandBase):
description='Generate documentation',
category='post-build',
allow_all_args=True)
- @CommandArgument('params', default=None, nargs='...',
- help="Command-line arguments to be passed through to cargo doc")
+ @CommandArgument(
+ 'params', default=None, nargs='...',
+ help="Command-line arguments to be passed through to cargo doc")
def doc(self, params):
self.ensure_bootstrapped()
return subprocess.call(["cargo", "doc"] + params,
env=self.build_env())
-
diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py
index 56eb1377f7b..3d20aeb27da 100644
--- a/python/servo/testing_commands.py
+++ b/python/servo/testing_commands.py
@@ -1,14 +1,9 @@
from __future__ import print_function, unicode_literals
-import json
import os
import os.path as path
-import shutil
import subprocess
-import sys
-import tarfile
from time import time
-import urllib
from mach.registrar import Registrar
from mach.decorators import (
@@ -20,6 +15,7 @@ from mach.decorators import (
from servo.command_base import CommandBase
import tidy
+
@CommandProvider
class MachCommands(CommandBase):
def __init__(self, context):
@@ -28,13 +24,15 @@ class MachCommands(CommandBase):
self.context.built_tests = False
def ensure_built_tests(self):
- if self.context.built_tests: return
+ if self.context.built_tests:
+ return
Registrar.dispatch('build-tests', context=self.context)
self.context.built_tests = True
def find_test(self, prefix):
- candidates = [f for f in os.listdir(path.join(self.context.topdir, "target"))
- if f.startswith(prefix + "-")]
+ candidates = [
+ f for f in os.listdir(path.join(self.context.topdir, "target"))
+ if f.startswith(prefix + "-")]
if candidates:
return path.join(self.context.topdir, "target", candidates[0])
return None
@@ -61,8 +59,9 @@ class MachCommands(CommandBase):
allow_all_args=True)
@CommandArgument('test_name', default=None, nargs="...",
help="Only run tests that match this pattern")
- @CommandArgument('params', default=None, nargs="...",
- help="Command-line arguments to be passed to the test harness")
+ @CommandArgument(
+ 'params', default=None, nargs="...",
+ help="Command-line arguments to be passed to the test harness")
def test_unit(self, test_name=None, params=None):
if params is None:
params = []
@@ -79,8 +78,9 @@ class MachCommands(CommandBase):
help="'cpu' or 'gpu' (default both)")
@CommandArgument('test_name', default=None, nargs="?",
help="Only run tests that match this pattern")
- @CommandArgument('servo_params', default=None, nargs="...",
- help="Command-line arguments to be passed through to Servo")
+ @CommandArgument(
+ '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):
self.ensure_bootstrapped()
self.ensure_built_tests()
@@ -103,7 +103,8 @@ class MachCommands(CommandBase):
print("Reference tests completed in %0.2fs" % elapsed)
- if error: return 1
+ if error:
+ return 1
@Command('test-content',
description='Run the content tests',
@@ -138,10 +139,12 @@ class MachCommands(CommandBase):
description='Run the web platform tests',
category='testing',
allow_all_args=True)
- @CommandArgument('params', default=None, nargs='...',
- help="Command-line arguments to be passed through to wpt/run.sh")
+ @CommandArgument(
+ 'params', default=None, nargs='...',
+ help="Command-line arguments to be passed through to wpt/run.sh")
def test_wpt(self, params=None):
if params is None:
params = []
- return subprocess.call(["bash", path.join("tests", "wpt", "run.sh")] + params,
- env=self.build_env())
+ return subprocess.call(
+ ["bash", path.join("tests", "wpt", "run.sh")] + params,
+ env=self.build_env())