Skip to content

Commit

Permalink
chore: fix a bunch of PEP 8 issues (nodejs#21)
Browse files Browse the repository at this point in the history
- E302 expected 2 blank lines, found 1
- E711 comparison to None should be 'if cond is not None:'
- E713 test for membership should be 'not in'
- E721 do not compare types, use 'isinstance()'
- E731 do not assign a lambda expression, use a def
- E741 ambiguous variable name
- F402 import shadowed by loop variable

Co-authored-by: Christian Clauss <cclauss@me.com>
  • Loading branch information
targos and cclauss authored Mar 16, 2020
1 parent 4f60f86 commit 94d082e
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 91 deletions.
3 changes: 2 additions & 1 deletion gyp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

PY3 = bytes != str

# Below IsCygwin() function copied from pylib/gyp/common.py

def IsCygwin():
# Function copied from pylib/gyp/common.py
try:
out = subprocess.Popen(
"uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
Expand Down
4 changes: 2 additions & 2 deletions pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def gyp_main(args):
home_vars.append("USERPROFILE")
for home_var in home_vars:
home = os.getenv(home_var)
if home != None:
if home:
home_dot_gyp = os.path.join(home, ".gyp")
if not os.path.exists(home_dot_gyp):
home_dot_gyp = None
Expand Down Expand Up @@ -604,7 +604,7 @@ def gyp_main(args):

# If ~/.gyp/include.gypi exists, it'll be forcibly included into every
# .gyp file that's loaded, before anything else is included.
if home_dot_gyp != None:
if home_dot_gyp:
default_include = os.path.join(home_dot_gyp, "include.gypi")
if os.path.exists(default_include):
print("Using overrides found in " + default_include)
Expand Down
4 changes: 1 addition & 3 deletions pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ def CopyTool(flavor, out_path, generator_flags={}):
# (Also in the printed Python Cookbook.)


def uniquer(seq, idfun=None):
if idfun is None:
idfun = lambda x: x
def uniquer(seq, idfun=lambda x: x):
seen = {}
result = []
for item in seq:
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _GenerateTargets(data, target_list, target_dicts, toplevel_dir, files, build
)

build_file = gyp.common.ParseQualifiedTarget(target_name)[0]
if not build_file in build_file_in_files:
if build_file not in build_file_in_files:
build_file_in_files[build_file] = _WasBuildFileModified(
build_file, data, files, toplevel_dir
)
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def WriteSources(self, spec, configs, extra_sources):
origin_src_dirs = []
for source in extra_sources:
local_file = source
if not "$(gyp_intermediate_dir)/" in local_file:
if "$(gyp_intermediate_dir)/" not in local_file:
basename = os.path.basename(local_file)
local_file = "$(gyp_intermediate_dir)/" + basename
(root, ext) = os.path.splitext(local_file)
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def GetAllIncludeDirectories(
all_includes_list = list(gyp_includes_set)
all_includes_list.sort()
for compiler_include in compiler_includes_list:
if not compiler_include in gyp_includes_set:
if compiler_include not in gyp_includes_set:
all_includes_list.append(compiler_include)

# All done.
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/generator/gypd.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
input_file_stem = input_file[:-4]
output_file = input_file_stem + params["options"].suffix + ".gypd"

if not output_file in output_files:
output_files[output_file] = input_file
output_files[output_file] = output_files.get(output_file, input_file)

for output_file, input_file in output_files.items():
output = open(output_file, "w")
Expand Down
4 changes: 2 additions & 2 deletions pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ def WriteTarget(
installable_deps = [self.output]
if (
self.flavor == "mac"
and not "product_dir" in spec
and "product_dir" not in spec
and self.toolset == "target"
):
# On mac, products are created in install_path immediately.
Expand Down Expand Up @@ -2176,7 +2176,7 @@ def Objectify(self, path):
"""Convert a path to its output directory form."""
if "$(" in path:
path = path.replace("$(obj)/", "$(obj).%s/$(TARGET)/" % self.toolset)
if not "$(obj)" in path:
if "$(obj)" not in path:
path = "$(obj).%s/$(TARGET)/%s" % (self.toolset, path)
return path

Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@ def _AddSources2(
list_excluded,
)
else:
if not source in sources_handled_by_action:
if source not in sources_handled_by_action:
detail = []
excluded_configurations = exclusions.get(source, [])
if len(excluded_configurations) == len(spec["configurations"]):
Expand Down
6 changes: 3 additions & 3 deletions pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,14 @@ def WriteCopies(self, copies, prebuild, mac_bundle_depends):
env = self.GetToolchainEnv(additional_settings=extra_env)
else:
env = self.GetToolchainEnv()
for copy in copies:
for path in copy["files"]:
for to_copy in copies:
for path in to_copy["files"]:
# Normalize the path so trailing slashes don't confuse us.
path = os.path.normpath(path)
basename = os.path.split(path)[1]
src = self.GypPathToNinja(path, env)
dst = self.GypPathToNinja(
os.path.join(copy["destination"], basename), env
os.path.join(to_copy["destination"], basename), env
)
outputs += self.ninja.build(dst, "copy", src, order_only=prebuild)
if self.is_mac_bundle:
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def ExpandXcodeVariables(string, expansions):
matches.reverse()
for match in matches:
(to_replace, variable) = match
if not variable in expansions:
if variable not in expansions:
continue

replacement = expansions[variable]
Expand Down
49 changes: 25 additions & 24 deletions pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def LoadBuildFileIncludesIntoDict(
subdict, subdict_path, data, aux_data, includes, check
):
includes_list = []
if includes != None:
if includes is not None:
includes_list.extend(includes)
if "includes" in subdict:
for include in subdict["includes"]:
Expand All @@ -300,7 +300,7 @@ def LoadBuildFileIncludesIntoDict(

# Merge in the included files.
for include in includes_list:
if not "included" in aux_data[subdict_path]:
if "included" not in aux_data[subdict_path]:
aux_data[subdict_path]["included"] = []
aux_data[subdict_path]["included"].append(include)

Expand Down Expand Up @@ -963,7 +963,7 @@ def ExpandVariables(input, phase, variables, build_file):
finally:
sys.path.pop()
os.chdir(oldwd)
assert replacement != None
assert replacement is not None
elif command_string:
raise GypError(
"Unknown command string '%s' in '%s'."
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def ExpandVariables(input, phase, variables, build_file):
replacement = cached_value

else:
if not contents in variables:
if contents not in variables:
if contents[-1] in ["!", "/"]:
# In order to allow cross-compiles (nacl) to happen more naturally,
# we will allow references to >(sources/) etc. to resolve to
Expand Down Expand Up @@ -1251,7 +1251,7 @@ def ProcessConditionsInDict(the_dict, phase, variables, build_file):
else:
assert False

if not conditions_key in the_dict:
if conditions_key not in the_dict:
return

conditions_list = the_dict[conditions_key]
Expand All @@ -1263,7 +1263,7 @@ def ProcessConditionsInDict(the_dict, phase, variables, build_file):
condition, conditions_key, phase, variables, build_file
)

if merge_dict != None:
if merge_dict is not None:
# Expand variables and nested conditinals in the merge_dict before
# merging it.
ProcessVariablesAndConditionsInDict(
Expand Down Expand Up @@ -1732,7 +1732,7 @@ def ExtractNodeRef(node):
for node_dependent_dependency in sorted(
node_dependent.dependencies, key=ExtractNodeRef
):
if not node_dependent_dependency.ref in flat_list:
if node_dependent_dependency.ref not in flat_list:
# The dependent one or more dependencies not in flat_list. There
# will be more chances to add it to flat_list when examining
# it again as a dependent of those other dependencies, provided
Expand All @@ -1759,7 +1759,7 @@ def Visit(node, path):
for child in node.dependents:
if child in path:
results.append([child] + path[: path.index(child) + 1])
elif not child in visited:
elif child not in visited:
visited.add(child)
Visit(child, [child] + path)

Expand All @@ -1775,7 +1775,7 @@ def DirectDependencies(self, dependencies=None):

for dependency in self.dependencies:
# Check for None, corresponding to the root node.
if dependency.ref != None and dependency.ref not in dependencies:
if dependency.ref and dependency.ref not in dependencies:
dependencies.append(dependency.ref)

return dependencies
Expand Down Expand Up @@ -2025,7 +2025,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
dependency_nodes = {}
for target in targets:
build_file = gyp.common.BuildFile(target)
if not build_file in dependency_nodes:
if build_file not in dependency_nodes:
dependency_nodes[build_file] = DependencyGraphNode(build_file)

# Set up the dependency links.
Expand Down Expand Up @@ -2103,7 +2103,7 @@ def DoDependentSettings(key, flat_list, targets, dependency_nodes):

for dependency in dependencies:
dependency_dict = targets[dependency]
if not key in dependency_dict:
if key not in dependency_dict:
continue
dependency_build_file = gyp.common.BuildFile(dependency)
MergeDicts(
Expand All @@ -2125,7 +2125,7 @@ def AdjustStaticLibraryDependencies(
target_type = target_dict["type"]

if target_type == "static_library":
if not "dependencies" in target_dict:
if "dependencies" not in target_dict:
continue

target_dict["dependencies_original"] = target_dict.get("dependencies", [])[
Expand Down Expand Up @@ -2155,7 +2155,7 @@ def AdjustStaticLibraryDependencies(
and not dependency_dict.get("hard_dependency", False)
) or (
dependency_dict["type"] != "static_library"
and not dependency in target_dict["dependencies"]
and dependency not in target_dict["dependencies"]
):
# Take the dependency out of the list, and don't increment index
# because the next dependency to analyze will shift into the index
Expand All @@ -2182,9 +2182,9 @@ def AdjustStaticLibraryDependencies(
for dependency in link_dependencies:
if dependency == target:
continue
if not "dependencies" in target_dict:
if "dependencies" not in target_dict:
target_dict["dependencies"] = []
if not dependency in target_dict["dependencies"]:
if dependency not in target_dict["dependencies"]:
target_dict["dependencies"].append(dependency)
# Sort the dependencies list in the order from dependents to dependencies.
# e.g. If A and B depend on C and C depends on D, sort them in A, B, C, D.
Expand Down Expand Up @@ -2242,7 +2242,8 @@ def MakePathRelative(to_file, fro_file, item):
def MergeLists(to, fro, to_file, fro_file, is_paths=False, append=True):
# Python documentation recommends objects which do not support hash
# set this value to None. Python library objects follow this rule.
is_hashable = lambda val: val.__hash__
def is_hashable(val):
return val.__hash__

# If x is hashable, returns whether x is in s. Else returns whether x is in l.
def is_in_set_or_list(x, s, l):
Expand Down Expand Up @@ -2325,7 +2326,7 @@ def MergeDicts(to, fro, to_file, fro_file):
if type(v) in (str, int):
if type(to[k]) not in (str, int):
bad_merge = True
elif type(v) is not type(to[k]):
elif not isinstance(v, type(to[k])):
bad_merge = True

if bad_merge:
Expand All @@ -2346,7 +2347,7 @@ def MergeDicts(to, fro, to_file, fro_file):
to[k] = v
elif type(v) is dict:
# Recurse, guaranteeing copies will be made of objects that require it.
if not k in to:
if k not in to:
to[k] = {}
MergeDicts(to[k], v, to_file, fro_file)
elif type(v) is list:
Expand Down Expand Up @@ -2466,9 +2467,9 @@ def SetUpConfigurations(target, target_dict):
# Provide a single configuration by default if none exists.
# TODO(mark): Signal an error if default_configurations exists but
# configurations does not.
if not "configurations" in target_dict:
if "configurations" not in target_dict:
target_dict["configurations"] = {"Default": {}}
if not "default_configuration" in target_dict:
if "default_configuration" not in target_dict:
concrete = [
i
for (i, config) in target_dict["configurations"].items()
Expand All @@ -2492,7 +2493,7 @@ def SetUpConfigurations(target, target_dict):
key_base = key[:-1]
else:
key_base = key
if not key_base in non_configuration_keys:
if key_base not in non_configuration_keys:
new_configuration_dict[key] = gyp.simple_copy.deepcopy(target_val)

# Merge in configuration (with all its parents first).
Expand Down Expand Up @@ -2524,7 +2525,7 @@ def SetUpConfigurations(target, target_dict):
key_base = key[:-1]
else:
key_base = key
if not key_base in non_configuration_keys:
if key_base not in non_configuration_keys:
delete_keys.append(key)
for key in delete_keys:
del target_dict[key]
Expand Down Expand Up @@ -2603,7 +2604,7 @@ def ProcessListFiltersInDict(name, the_dict):
+ {"!": "exclusion", "/": "regex"}[operation]
)

if not list_key in lists:
if list_key not in lists:
lists.append(list_key)

# Delete the lists that are known to be unneeded at this point.
Expand Down Expand Up @@ -2954,7 +2955,7 @@ def PruneUnwantedTargets(targets, flat_list, dependency_nodes, root_targets, dat

# Prune unwanted targets from each build_file's data dict.
for build_file in data["target_build_files"]:
if not "targets" in data[build_file]:
if "targets" not in data[build_file]:
continue
new_targets = []
for target in data[build_file]["targets"]:
Expand Down
10 changes: 5 additions & 5 deletions pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,13 +1243,13 @@ def AddImplicitPostbuilds(

def _AdjustLibrary(self, library, config_name=None):
if library.endswith(".framework"):
l = "-framework " + os.path.splitext(os.path.basename(library))[0]
l_flag = "-framework " + os.path.splitext(os.path.basename(library))[0]
else:
m = self.library_re.match(library)
if m:
l = "-l" + m.group(1)
l_flag = "-l" + m.group(1)
else:
l = library
l_flag = library

sdk_root = self._SdkPath(config_name)
if not sdk_root:
Expand All @@ -1263,8 +1263,8 @@ def _AdjustLibrary(self, library, config_name=None):
# following conditions are both true:
# - library is referenced in the gyp file as "$(SDKROOT)/**/*.dylib",
# - the ".dylib" file does not exists but a ".tbd" file do.
library = l.replace("$(SDKROOT)", sdk_root)
if l.startswith("$(SDKROOT)"):
library = l_flag.replace("$(SDKROOT)", sdk_root)
if l_flag.startswith("$(SDKROOT)"):
basename, ext = os.path.splitext(library)
if ext == ".dylib" and not os.path.exists(library):
tbd_library = basename + ".tbd"
Expand Down
Loading

0 comments on commit 94d082e

Please sign in to comment.