Skip to content

Commit

Permalink
chore: fix python lint warnings (electron#14638)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ckerr authored Sep 16, 2018
1 parent 6d01952 commit a45ded5
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 73 deletions.
2 changes: 1 addition & 1 deletion script/apply-patches
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os
import subprocess
import sys

import lib.git as git
from lib import git
from lib.patches import PatchesConfig


Expand Down
2 changes: 1 addition & 1 deletion script/bump-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 19 additions & 20 deletions script/check-relative-doc-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,29 @@ def getBrokenLinks(filepath):

for link in links:
sections = link.split('#')
if len(sections) > 1:
if str(link).startswith('#'):
if not checkSections(sections, lines):
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:
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 not os.path.isfile(os.path.join(currentDir, link)):
brokenLinks.append(link)


print_errors(filepath, brokenLinks)
return len(brokenLinks)

Expand Down
15 changes: 9 additions & 6 deletions script/lib/dbus_mock.py → script/dbus_mock.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 7 additions & 3 deletions script/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
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'
Expand Down Expand Up @@ -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 = [
Expand Down
22 changes: 12 additions & 10 deletions script/lib/env_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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)')
Expand All @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions script/lib/git.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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',
Expand All @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions script/lib/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import sys

from util import scoped_cwd
from lib.util import scoped_cwd


class GNProject:
Expand All @@ -18,7 +18,8 @@ def _get_executable_name(self):

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):
Expand Down
29 changes: 19 additions & 10 deletions script/lib/patches.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>', description=None):
def __init__(self, file_path, repo_path, paths_prefix=None,
author='Anonymous <[email protected]>', description=None):
self.author = author
self.description = description
self.file_path = file_path
Expand All @@ -21,14 +24,17 @@ def __init__(self, file_path, repo_path, paths_prefix=None, author='Anonymous <a
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
Expand Down Expand Up @@ -72,7 +78,8 @@ def apply(self, reverse=False, stop_on_error=True, commit=False):
# 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
Expand Down Expand Up @@ -133,7 +140,8 @@ def __create_patch(self, raw_data, base_directory, repo_path, paths_prefix):
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()
Expand All @@ -154,7 +162,8 @@ def __create_patches_list(self):
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

Expand Down
Loading

0 comments on commit a45ded5

Please sign in to comment.