chore: fix python lint warnings (#14638)

* chore: fix lint warnings

* chore: another try at python import errors

Looks like the problem is that dbus_mock.py is running as
a script but living in the `lib/` directory where it's part of a
module. Moving it up into the `script/` directory seems to
solve the issue.
This commit is contained in:
Charles Kerr 2018-09-16 12:24:07 -05:00 committed by GitHub
parent 6d01952e66
commit a45ded5508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 111 additions and 74 deletions

View file

@ -5,7 +5,7 @@ import os
import subprocess
import sys
import lib.git as git
from lib import git
from lib.patches import PatchesConfig

View file

@ -80,7 +80,7 @@ def main():
else:
raise Exception("Invalid current version: " + curr_version)
if args.new_version == None and args.bump == None and args.stable == False:
if args.new_version is None and args.bump is None and not args.stable:
parser.print_help()
return 1

View file

@ -57,29 +57,28 @@ def getBrokenLinks(filepath):
for link in links:
sections = link.split('#')
if len(sections) > 1:
if str(link).startswith('#'):
if not checkSections(sections, lines):
brokenLinks.append(link)
else:
tempFile = os.path.join(currentDir, sections[0])
if os.path.isfile(tempFile):
try:
newFile = open(tempFile, 'r')
newLines = newFile.readlines()
except KeyboardInterrupt:
print('Keyboard interruption whle parsing. Please try again.')
finally:
newFile.close()
if not checkSections(sections, newLines):
brokenLinks.append(link)
else:
brokenLinks.append(link)
else:
if len(sections) < 2:
if not os.path.isfile(os.path.join(currentDir, link)):
brokenLinks.append(link)
elif str(link).startswith('#'):
if not checkSections(sections, lines):
brokenLinks.append(link)
else:
tempFile = os.path.join(currentDir, sections[0])
if os.path.isfile(tempFile):
try:
newFile = open(tempFile, 'r')
newLines = newFile.readlines()
except KeyboardInterrupt:
print('Keyboard interruption whle parsing. Please try again.')
finally:
newFile.close()
if not checkSections(sections, newLines):
brokenLinks.append(link)
else:
brokenLinks.append(link)
print_errors(filepath, brokenLinks)
return len(brokenLinks)

View file

@ -1,28 +1,31 @@
from config import is_verbose_mode
from dbusmock import DBusTestCase
#!/usr/bin/env python
import atexit
import os
import subprocess
import sys
from dbusmock import DBusTestCase
from lib.config import is_verbose_mode
def stop():
DBusTestCase.stop_dbus(DBusTestCase.system_bus_pid)
DBusTestCase.stop_dbus(DBusTestCase.session_bus_pid)
def start():
dbusmock_log = sys.stdout if is_verbose_mode() else open(os.devnull, 'w')
log = sys.stdout if is_verbose_mode() else open(os.devnull, 'w')
DBusTestCase.start_system_bus()
DBusTestCase.spawn_server_template('logind', None, dbusmock_log)
DBusTestCase.spawn_server_template('logind', None, log)
DBusTestCase.start_session_bus()
DBusTestCase.spawn_server_template('notification_daemon', None, dbusmock_log)
DBusTestCase.spawn_server_template('notification_daemon', None, log)
if __name__ == '__main__':
import subprocess
start()
try:
print(sys.argv)
subprocess.check_call(sys.argv[1:])
finally:
stop()

View file

@ -6,10 +6,13 @@ import platform
import sys
# URL to the mips64el sysroot image.
MIPS64EL_SYSROOT_URL = 'https://github.com/electron/debian-sysroot-image-creator/releases/download/v0.5.0/debian_jessie_mips64-sysroot.tar.bz2'
MIPS64EL_SYSROOT_URL = 'https://github.com/electron' \
+ '/debian-sysroot-image-creator/releases/download' \
+ '/v0.5.0/debian_jessie_mips64-sysroot.tar.bz2'
# URL to the mips64el toolchain.
MIPS64EL_GCC = 'gcc-4.8.3-d197-n64-loongson'
MIPS64EL_GCC_URL = 'http://ftp.loongnix.org/toolchain/gcc/release/' + MIPS64EL_GCC + '.tar.gz'
MIPS64EL_GCC_URL = 'http://ftp.loongnix.org/toolchain/gcc/release/' \
+ MIPS64EL_GCC + '.tar.gz'
BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \
'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent'
@ -89,7 +92,8 @@ def get_zip_name(name, version, suffix=''):
def build_env():
env = os.environ.copy()
if get_target_arch() == "mips64el":
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
SOURCE_ROOT = os.path.abspath(os.path.dirname(
os.path.dirname(os.path.dirname(__file__))))
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
gcc_dir = os.path.join(VENDOR_DIR, MIPS64EL_GCC)
ldlib_dirs = [

View file

@ -16,9 +16,10 @@ def validate_pair(ob):
return True
def consume(iter):
def consume(iterator):
try:
while True: next(iter)
while True:
next(iterator)
except StopIteration:
pass
@ -36,11 +37,11 @@ def get_environment_from_batch_command(env_cmd, initial=None):
if not isinstance(env_cmd, (list, tuple)):
env_cmd = [env_cmd]
# Construct the command that will alter the environment.
env_cmd = subprocess.list2cmdline(env_cmd)
cmd = subprocess.list2cmdline(env_cmd)
# Create a tag so we can tell in the output when the proc is done.
tag = 'END OF BATCH COMMAND'
# Construct a cmd.exe command to do accomplish this.
cmd = 'cmd.exe /s /c "{env_cmd} && echo "{tag}" && set"'.format(**vars())
cmd = 'cmd.exe /s /c "{cmd} && echo "{tag}" && set"'.format(**locals())
# Launch the process.
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial)
# Parse the output sent to stdout.
@ -63,10 +64,11 @@ def get_vs_location(vs_version):
"""
Returns the location of the VS building environment.
The vs_version can be strings like "[15.0,16.0)", meaning 2017, but not the next version.
The vs_version can be strings like "[15.0,16.0)", meaning 2017,
but not the next version.
"""
# vswhere can't handle spaces, like "[15.0, 16.0)" should become "[15.0,16.0)"
# vswhere can't handle spaces. "[15.0, 16.0)" should become "[15.0,16.0)"
vs_version = vs_version.replace(" ", "")
program_files = os.environ.get('ProgramFiles(x86)')
@ -86,10 +88,10 @@ def get_vs_env(vs_version, arch):
"""
Returns the env object for VS building environment.
vs_version is the version of Visual Studio to use. See get_vs_location for
more details.
The arch has to be one of "x86", "amd64", "arm", "x86_amd64", "x86_arm", "amd64_x86",
"amd64_arm", i.e. the args passed to vcvarsall.bat.
vs_version is the version of Visual Studio to use.
See get_vs_location for more details.
The arch must be one of "x86", "amd64", "arm", "x86_amd64", "x86_arm",
"amd64_x86", "amd64_arm", i.e. the args passed to vcvarsall.bat.
"""
location = get_vs_location(vs_version)

View file

@ -1,13 +1,15 @@
#!/usr/bin/env python
"""Git helper functions.
Everything in here should be project agnostic, shouldn't rely on project's structure,
and make any assumptions about the passed arguments or calls outcomes.
Everything here should be project agnostic: it shouldn't rely on project's
structure, or make assumptions about the passed arguments or calls' outcomes.
"""
import os
import subprocess
from util import scoped_cwd
from lib.util import scoped_cwd
def is_repo_root(path):
@ -40,7 +42,7 @@ def get_repo_root(path):
return get_repo_root(parent_path)
def apply(repo, patch_path, directory=None, index=False, reverse=False):
def apply_patch(repo, patch_path, directory=None, index=False, reverse=False):
args = ['git', 'apply',
'--ignore-space-change',
'--ignore-whitespace',
@ -64,7 +66,7 @@ def get_patch(repo, commit_hash):
args = ['git', 'diff-tree',
'-p',
commit_hash,
'--' # Explicitly tell Git that `commit_hash` is a revision, not a path.
'--' # Explicitly tell Git `commit_hash` is a revision, not a path.
]
with scoped_cwd(repo):

View file

@ -3,7 +3,7 @@
import subprocess
import sys
from util import scoped_cwd
from lib.util import scoped_cwd
class GNProject:
@ -18,7 +18,8 @@ class GNProject:
def run(self, command_name, command_args):
with scoped_cwd(self.out_dir):
complete_args = [self._get_executable_name(), command_name, '.'] + command_args
complete_args = [self._get_executable_name(), command_name, '.'] + \
command_args
return subprocess.check_output(complete_args)
def args(self):

View file

@ -1,17 +1,20 @@
#!/usr/bin/env python
import os
import sys
import git
from lib import git
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
SOURCE_ROOT = os.path.abspath(os.path.dirname(
os.path.dirname(os.path.dirname(__file__))))
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
PYYAML_LIB_DIR = os.path.join(VENDOR_DIR, 'pyyaml', 'lib')
sys.path.append(PYYAML_LIB_DIR)
import yaml
import yaml #pylint: disable=wrong-import-position,wrong-import-order
class Patch:
def __init__(self, file_path, repo_path, paths_prefix=None, author='Anonymous <anonymous@electronjs.org>', description=None):
def __init__(self, file_path, repo_path, paths_prefix=None,
author='Anonymous <anonymous@electronjs.org>', description=None):
self.author = author
self.description = description
self.file_path = file_path
@ -21,14 +24,17 @@ class Patch:
def apply(self, reverse=False, commit=False, index=False):
# Add the change to index only if we're going to commit it later.
add_to_index = index or commit
patch_applied = git.apply(self.repo_path, self.file_path, directory=self.paths_prefix, index=add_to_index, reverse=reverse)
patch_applied = git.apply_patch(self.repo_path, self.file_path,
directory=self.paths_prefix,
index=add_to_index, reverse=reverse)
if not patch_applied:
return False
if commit:
message = self.__get_commit_message(reverse)
patch_committed = git.commit(self.repo_path, author=self.author, message=message)
patch_committed = git.commit(self.repo_path, author=self.author,
message=message)
return patch_committed
return True
@ -72,7 +78,8 @@ class PatchesList:
# Applying all commits takes about 10 minutes (!) on a fast dev machine.
# Instead of it we are going only to add all changes to the index
# and commit them all at once later.
applied_successfully = patch.apply(reverse=reverse, index=commit, commit=False)
applied_successfully = patch.apply(reverse=reverse, index=commit,
commit=False)
if not applied_successfully:
all_patches_applied = False
@ -133,7 +140,8 @@ class PatchesConfig:
if raw_data['description'] is not None:
description += '\n\n' + raw_data['description']
return Patch(absolute_file_path, repo_path, paths_prefix=paths_prefix, author=author, description=description)
return Patch(absolute_file_path, repo_path, paths_prefix=paths_prefix,
author=author, description=description)
def __create_patches_list(self):
config_contents = self.__parse()
@ -154,7 +162,8 @@ class PatchesConfig:
patches_data = config_contents['patches']
base_directory = os.path.abspath(os.path.dirname(self.path))
patches = [self.__create_patch(data, base_directory, absolute_repo_path, paths_prefix) for data in patches_data]
patches = [self.__create_patch(data, base_directory, absolute_repo_path,
paths_prefix) for data in patches_data]
patches_list = PatchesList(repo_path=absolute_repo_path, patches=patches)
return patches_list

View file

@ -17,8 +17,8 @@ import urllib2
import os
import zipfile
from config import is_verbose_mode, PLATFORM
from env_util import get_vs_env
from lib.config import is_verbose_mode, PLATFORM
from lib.env_util import get_vs_env
BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor',
'boto'))
@ -142,11 +142,14 @@ def safe_mkdir(path):
raise
def execute(argv, env=os.environ, cwd=None):
def execute(argv, env=None, cwd=None):
if env is None:
env = os.environ
if is_verbose_mode():
print ' '.join(argv)
try:
output = subprocess.check_output(argv, stderr=subprocess.STDOUT, env=env, cwd=cwd)
output = subprocess.check_output(argv, stderr=subprocess.STDOUT,
env=env, cwd=cwd)
if is_verbose_mode():
print output
return output
@ -155,7 +158,9 @@ def execute(argv, env=os.environ, cwd=None):
raise e
def execute_stdout(argv, env=os.environ, cwd=None):
def execute_stdout(argv, env=None, cwd=None):
if env is None:
env = os.environ
if is_verbose_mode():
print ' '.join(argv)
try:
@ -210,6 +215,16 @@ def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
def add_exec_bit(filename):
os.chmod(filename, os.stat(filename).st_mode | stat.S_IEXEC)
def parse_version(version):
if version[0] == 'v':
version = version[1:]
vs = version.split('.')
if len(vs) > 4:
return vs[0:4]
else:
return vs + ['0'] * (4 - len(vs))
def clean_parse_version(v):
return parse_version(v.split("-")[0])
@ -230,7 +245,7 @@ def get_last_major():
def get_next_nightly(v):
pv = clean_parse_version(v)
major = pv[0]; minor = pv[1]; patch = pv[2]
(major, minor, patch) = pv[0:3]
if (is_stable(v)):
patch = str(int(pv[2]) + 1)
@ -266,15 +281,16 @@ def get_next_beta(v):
def get_next_stable_from_pre(v):
pv = clean_parse_version(v)
major = pv[0]; minor = pv[1]; patch = pv[2]
(major, minor, patch) = pv[0:3]
return make_version(major, minor, patch)
def get_next_stable_from_stable(v):
pv = clean_parse_version(v)
major = pv[0]; minor = pv[1]; patch = pv[2]
(major, minor, patch) = pv[0:3]
return make_version(major, minor, str(int(patch) + 1))
def make_version(major, minor, patch, pre = None):
if pre is None:
return major + '.' + minor + '.' + patch
return major + "." + minor + "." + patch + '-' + pre

View file

@ -62,12 +62,12 @@ GRAMMAR:
EXPRESSION has Python syntax.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sys
__author__ = 'wan@google.com (Zhanyong Wan)'
TOKEN_TABLE = [
(re.compile(r'\$var\s+'), '$var'),

4
script/spec-runner.js Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/env node
const cp = require('child_process')
const crypto = require('crypto')
const fs = require('fs')
@ -39,7 +41,7 @@ getSpecHash().then(([currentSpecHash, currentSpecInstallHash]) => {
let exe = path.resolve(BASE, utils.getElectronExec())
const args = process.argv.slice(2)
if (process.platform === 'linux') {
args.unshift(path.resolve(__dirname, 'lib/dbus_mock.py'), exe)
args.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
exe = 'python'
}
const child = cp.spawn(exe, args, {

View file

@ -1,12 +1,14 @@
#!/usr/bin/env python
import argparse
import atexit
import os
import shutil
import subprocess
import sys
from lib.config import enable_verbose_mode
import lib.dbus_mock
from lib.util import electron_gyp, execute_stdout, rm_rf
@ -17,8 +19,6 @@ if sys.platform == 'linux2':
# while also setting DBUS_SYSTEM_BUS_ADDRESS environment variable, which
# will be picked up by electron.
try:
import lib.dbus_mock
import atexit
lib.dbus_mock.start()
atexit.register(lib.dbus_mock.stop)
except ImportError:

View file

@ -4,6 +4,7 @@ import argparse
import hashlib
import os
import shutil
import sys
import tempfile
from lib.config import s3_config
@ -95,5 +96,4 @@ def copy_files(source_files, output_dir):
shutil.copy2(source_file, output_path)
if __name__ == '__main__':
import sys
sys.exit(main())

View file

@ -210,5 +210,4 @@ def get_release(version):
return release
if __name__ == '__main__':
import sys
sys.exit(main())