Skip to content

Commit 7224a69

Browse files
authored
Fix comparisons and clean imports (alisw#907)
Round two of dividing alisw#882 into several smaller changes
1 parent 1227c30 commit 7224a69

File tree

13 files changed

+34
-35
lines changed

13 files changed

+34
-35
lines changed

alibuild_helpers/analytics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
2-
import os, subprocess, sys
2+
import os
3+
import subprocess
4+
import sys
35
from os.path import exists, expanduser
46
from os import unlink
57

alibuild_helpers/build.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from alibuild_helpers.utilities import getPackageList, asList
1212
from alibuild_helpers.utilities import validateDefaults
1313
from alibuild_helpers.utilities import Hasher
14-
from alibuild_helpers.utilities import yamlDump
1514
from alibuild_helpers.utilities import resolve_tag, resolve_version, short_commit_hash
1615
from alibuild_helpers.git import Git, git
1716
from alibuild_helpers.sl import Sapling
@@ -31,7 +30,6 @@
3130
import os
3231
import re
3332
import shutil
34-
import sys
3533
import time
3634

3735

@@ -476,7 +474,7 @@ def doBuild(args, parser):
476474
checkedOutCommitName = scm.checkedOutCommitName(directory=args.configDir)
477475
except SCMError:
478476
dieOnError(True, "Cannot find SCM directory in %s." % args.configDir)
479-
os.environ["ALIBUILD_ALIDIST_HASH"] = checkedOutCommitName # type: ignore
477+
os.environ["ALIBUILD_ALIDIST_HASH"] = checkedOutCommitName
480478

481479
debug("Building for architecture %s", args.architecture)
482480
debug("Number of parallel builds: %d", args.jobs)
@@ -512,9 +510,9 @@ def doBuild(args, parser):
512510
("\n- ".join(sorted(failed)), args.defaults, " ".join(args.pkgname)))
513511

514512
for x in specs.values():
515-
x["requires"] = [r for r in x["requires"] if not r in args.disable]
516-
x["build_requires"] = [r for r in x["build_requires"] if not r in args.disable]
517-
x["runtime_requires"] = [r for r in x["runtime_requires"] if not r in args.disable]
513+
x["requires"] = [r for r in x["requires"] if r not in args.disable]
514+
x["build_requires"] = [r for r in x["build_requires"] if r not in args.disable]
515+
x["runtime_requires"] = [r for r in x["runtime_requires"] if r not in args.disable]
518516

519517
if systemPackages:
520518
banner("aliBuild can take the following packages from the system and will not build them:\n %s",

alibuild_helpers/clean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def decideClean(workDir, architecture, aggressiveCleanup):
4747
"%s/SOURCES" % (workDir)]
4848
allBuildStuff = glob.glob("%s/BUILD/*" % workDir)
4949
toDelete += [x for x in allBuildStuff
50-
if not path.islink(x) and not basename(x) in symlinksBuild]
50+
if not path.islink(x) and basename(x) not in symlinksBuild]
5151
installGlob ="%s/%s/*/" % (workDir, architecture)
5252
installedPackages = set([dirname(x) for x in glob.glob(installGlob)])
5353
symlinksInstall = []
5454
for x in installedPackages:
5555
symlinksInstall += [path.realpath(y) for y in glob.glob(x + "/latest*")]
5656
toDelete += [x for x in glob.glob(installGlob+ "*")
57-
if not path.islink(x) and not path.realpath(x) in symlinksInstall]
57+
if not path.islink(x) and path.realpath(x) not in symlinksInstall]
5858
toDelete = [x for x in toDelete if path.exists(x)]
5959
return toDelete
6060

alibuild_helpers/deps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def doDeps(args, parser):
4141

4242
for s in specs.values():
4343
# Remove disabled packages
44-
s["requires"] = [r for r in s["requires"] if not r in args.disable and r != "defaults-release"]
45-
s["build_requires"] = [r for r in s["build_requires"] if not r in args.disable and r != "defaults-release"]
46-
s["runtime_requires"] = [r for r in s["runtime_requires"] if not r in args.disable and r != "defaults-release"]
44+
s["requires"] = [r for r in s["requires"] if r not in args.disable and r != "defaults-release"]
45+
s["build_requires"] = [r for r in s["build_requires"] if r not in args.disable and r != "defaults-release"]
46+
s["runtime_requires"] = [r for r in s["runtime_requires"] if r not in args.disable and r != "defaults-release"]
4747

4848
# Determine which pacakages are only build/runtime dependencies
4949
all_build = set()
@@ -97,7 +97,7 @@ def doDeps(args, parser):
9797
# Check if we have dot in PATH
9898
try:
9999
execute(["dot", "-V"])
100-
except Exception as e:
100+
except Exception:
101101
dieOnError(True, "Could not find dot in PATH. Please install graphviz and add it to PATH.")
102102
try:
103103
if args.neat:

alibuild_helpers/doctor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
2-
import os, re, sys
2+
import os
3+
import re
4+
import sys
35
from os.path import exists, abspath, expanduser
46
import logging
57
from alibuild_helpers.log import debug, error, banner, info, success, warning
@@ -9,7 +11,7 @@
911

1012
def prunePaths(workDir) -> None:
1113
for x in ["PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"]:
12-
if not x in os.environ:
14+
if x not in os.environ:
1315
continue
1416
workDirEscaped = re.escape("%s" % workDir) + "[^:]*:?"
1517
os.environ[x] = re.sub(workDirEscaped, "", os.environ[x])

alibuild_helpers/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def git(args, directory=".", check=True, prompt=True):
9696
directory=quote(directory),
9797
args=" ".join(map(quote, args)),
9898
# GIT_TERMINAL_PROMPT is only supported in git 2.3+.
99-
prompt_var=f"GIT_TERMINAL_PROMPT=0" if not prompt else "",
99+
prompt_var="GIT_TERMINAL_PROMPT=0" if not prompt else "",
100100
directory_safe_var=f"GIT_CONFIG_COUNT={lastGitOverride+2} GIT_CONFIG_KEY_{lastGitOverride}=safe.directory GIT_CONFIG_VALUE_{lastGitOverride}=$PWD GIT_CONFIG_KEY_{lastGitOverride+1}=gc.auto GIT_CONFIG_VALUE_{lastGitOverride+1}=0" if directory else "",
101101
), timeout=GIT_CMD_TIMEOUTS.get(args[0] if len(args) else "*", GIT_COMMAND_TIMEOUT_SEC))
102102
if check and err != 0:

alibuild_helpers/init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from alibuild_helpers.utilities import getPackageList, parseDefaults, readDefaults, validateDefaults
33
from alibuild_helpers.log import debug, error, warning, banner, info
44
from alibuild_helpers.log import dieOnError
5-
from alibuild_helpers.workarea import cleanup_git_log, updateReferenceRepoSpec
5+
from alibuild_helpers.workarea import updateReferenceRepoSpec
66

77
from os.path import join
88
import os.path as path
9-
import os, sys
9+
import os
10+
import sys
1011

1112
def parsePackagesDefinition(pkgname):
1213
return [ dict(zip(["name","ver"], y.split("@")[0:2]))

alibuild_helpers/sync.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ def fetch_symlinks(self, spec) -> None:
364364
done
365365
""".format(
366366
workDir=self.workdir,
367-
b=self.remoteStore,
368367
architecture=self.architecture,
369368
cvmfs_architecture=cvmfs_architecture,
370369
package=spec["package"],

alibuild_helpers/utilities.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def normalise_multiple_options(option, sep=","):
150150

151151
def prunePaths(workDir):
152152
for x in ["PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"]:
153-
if not x in os.environ:
153+
if x not in os.environ:
154154
continue
155155
workDirEscaped = re.escape("%s" % workDir) + "[^:]*:?"
156156
os.environ[x] = re.sub(workDirEscaped, "", os.environ[x])
@@ -163,12 +163,12 @@ def validateSpec(spec):
163163
raise SpecError("Empty recipe.")
164164
if type(spec) != OrderedDict:
165165
raise SpecError("Not a YAML key / value.")
166-
if not "package" in spec:
166+
if "package" not in spec:
167167
raise SpecError("Missing package field in header.")
168168

169169
# Use this to check if a given spec is compatible with the given default
170170
def validateDefaults(finalPkgSpec, defaults):
171-
if not "valid_defaults" in finalPkgSpec:
171+
if "valid_defaults" not in finalPkgSpec:
172172
return (True, "", [])
173173
validDefaults = asList(finalPkgSpec["valid_defaults"])
174174
nonStringDefaults = [x for x in validDefaults if not type(x) == str]
@@ -378,7 +378,7 @@ def parseRecipe(reader):
378378
err = "Unable to parse %s\n%s" % (reader.url, str(e))
379379
except yaml.parser.ParserError as e:
380380
err = "Unable to parse %s\n%s" % (reader.url, str(e))
381-
except ValueError as e:
381+
except ValueError:
382382
err = "Unable to parse %s. Header missing." % reader.url
383383
return err, spec, recipe
384384

@@ -496,7 +496,7 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem,
496496
systemRE = spec.get("prefer_system", "(?!.*)")
497497
try:
498498
systemREMatches = re.match(systemRE, architecture)
499-
except TypeError as e:
499+
except TypeError:
500500
dieOnError(True, "Malformed entry prefer_system: %s in %s" % (systemRE, spec["package"]))
501501
if not noSystem and (preferSystem or systemREMatches):
502502
requested_version = resolve_version(spec, defaults, "unavailable", "unavailable")
@@ -553,7 +553,7 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem,
553553
"System requirements %s cannot have a recipe" % spec["package"])
554554
if re.match(spec.get("system_requirement", "(?!.*)"), architecture):
555555
cmd = spec.get("system_requirement_check", "false")
556-
if not spec["package"] in requirementsCache:
556+
if spec["package"] not in requirementsCache:
557557
requirementsCache[spec["package"]] = performRequirementCheck(spec, cmd.strip())
558558

559559
err, output = requirementsCache[spec["package"]]
@@ -580,8 +580,8 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem,
580580
spec["disabled"] += [x for x in fn("requires")]
581581
spec["disabled"] += [x for x in fn("build_requires")]
582582
fn = lambda what: filterByArchitectureDefaults(architecture, defaults, spec.get(what, []))
583-
spec["requires"] = [x for x in fn("requires") if not x in disable]
584-
spec["build_requires"] = [x for x in fn("build_requires") if not x in disable]
583+
spec["requires"] = [x for x in fn("requires") if x not in disable]
584+
spec["build_requires"] = [x for x in fn("build_requires") if x not in disable]
585585
if spec["package"] != "defaults-release":
586586
spec["build_requires"].append("defaults-release")
587587
spec["runtime_requires"] = spec["requires"]

tests/test_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import print_function
22
# Assuming you are using the mock library to ... mock things
33
from unittest import mock
4-
from unittest.mock import patch, call
4+
from unittest.mock import patch
55

66
import alibuild_helpers.args
7-
from alibuild_helpers.args import doParseArgs, matchValidArch, finaliseArgs, DEFAULT_WORK_DIR, DEFAULT_CHDIR, ARCHITECTURE_TABLE
7+
from alibuild_helpers.args import doParseArgs, matchValidArch
88
import sys
99
import os
1010
import os.path

0 commit comments

Comments
 (0)