diff --git a/alibuild_helpers/analytics.py b/alibuild_helpers/analytics.py index cf0656cf..8a736bd2 100644 --- a/alibuild_helpers/analytics.py +++ b/alibuild_helpers/analytics.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 -import os, subprocess, sys +import os +import subprocess +import sys from os.path import exists, expanduser from os import unlink diff --git a/alibuild_helpers/build.py b/alibuild_helpers/build.py index 807ee162..2be491e4 100644 --- a/alibuild_helpers/build.py +++ b/alibuild_helpers/build.py @@ -11,7 +11,6 @@ from alibuild_helpers.utilities import getPackageList, asList from alibuild_helpers.utilities import validateDefaults from alibuild_helpers.utilities import Hasher -from alibuild_helpers.utilities import yamlDump from alibuild_helpers.utilities import resolve_tag, resolve_version, short_commit_hash from alibuild_helpers.git import Git, git from alibuild_helpers.sl import Sapling @@ -31,7 +30,6 @@ import os import re import shutil -import sys import time @@ -476,7 +474,7 @@ def doBuild(args, parser): checkedOutCommitName = scm.checkedOutCommitName(directory=args.configDir) except SCMError: dieOnError(True, "Cannot find SCM directory in %s." % args.configDir) - os.environ["ALIBUILD_ALIDIST_HASH"] = checkedOutCommitName # type: ignore + os.environ["ALIBUILD_ALIDIST_HASH"] = checkedOutCommitName debug("Building for architecture %s", args.architecture) debug("Number of parallel builds: %d", args.jobs) @@ -512,9 +510,9 @@ def doBuild(args, parser): ("\n- ".join(sorted(failed)), args.defaults, " ".join(args.pkgname))) for x in specs.values(): - x["requires"] = [r for r in x["requires"] if not r in args.disable] - x["build_requires"] = [r for r in x["build_requires"] if not r in args.disable] - x["runtime_requires"] = [r for r in x["runtime_requires"] if not r in args.disable] + x["requires"] = [r for r in x["requires"] if r not in args.disable] + x["build_requires"] = [r for r in x["build_requires"] if r not in args.disable] + x["runtime_requires"] = [r for r in x["runtime_requires"] if r not in args.disable] if systemPackages: banner("aliBuild can take the following packages from the system and will not build them:\n %s", diff --git a/alibuild_helpers/clean.py b/alibuild_helpers/clean.py index 1404ebaa..65808d99 100644 --- a/alibuild_helpers/clean.py +++ b/alibuild_helpers/clean.py @@ -47,14 +47,14 @@ def decideClean(workDir, architecture, aggressiveCleanup): "%s/SOURCES" % (workDir)] allBuildStuff = glob.glob("%s/BUILD/*" % workDir) toDelete += [x for x in allBuildStuff - if not path.islink(x) and not basename(x) in symlinksBuild] + if not path.islink(x) and basename(x) not in symlinksBuild] installGlob ="%s/%s/*/" % (workDir, architecture) installedPackages = set([dirname(x) for x in glob.glob(installGlob)]) symlinksInstall = [] for x in installedPackages: symlinksInstall += [path.realpath(y) for y in glob.glob(x + "/latest*")] toDelete += [x for x in glob.glob(installGlob+ "*") - if not path.islink(x) and not path.realpath(x) in symlinksInstall] + if not path.islink(x) and path.realpath(x) not in symlinksInstall] toDelete = [x for x in toDelete if path.exists(x)] return toDelete diff --git a/alibuild_helpers/deps.py b/alibuild_helpers/deps.py index 2364a141..95be94ee 100644 --- a/alibuild_helpers/deps.py +++ b/alibuild_helpers/deps.py @@ -41,9 +41,9 @@ def doDeps(args, parser): for s in specs.values(): # Remove disabled packages - s["requires"] = [r for r in s["requires"] if not r in args.disable and r != "defaults-release"] - s["build_requires"] = [r for r in s["build_requires"] if not r in args.disable and r != "defaults-release"] - s["runtime_requires"] = [r for r in s["runtime_requires"] if not r in args.disable and r != "defaults-release"] + s["requires"] = [r for r in s["requires"] if r not in args.disable and r != "defaults-release"] + s["build_requires"] = [r for r in s["build_requires"] if r not in args.disable and r != "defaults-release"] + s["runtime_requires"] = [r for r in s["runtime_requires"] if r not in args.disable and r != "defaults-release"] # Determine which pacakages are only build/runtime dependencies all_build = set() @@ -97,7 +97,7 @@ def doDeps(args, parser): # Check if we have dot in PATH try: execute(["dot", "-V"]) - except Exception as e: + except Exception: dieOnError(True, "Could not find dot in PATH. Please install graphviz and add it to PATH.") try: if args.neat: diff --git a/alibuild_helpers/doctor.py b/alibuild_helpers/doctor.py index 8a7952b2..faecc580 100644 --- a/alibuild_helpers/doctor.py +++ b/alibuild_helpers/doctor.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 -import os, re, sys +import os +import re +import sys from os.path import exists, abspath, expanduser import logging from alibuild_helpers.log import debug, error, banner, info, success, warning @@ -9,7 +11,7 @@ def prunePaths(workDir) -> None: for x in ["PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"]: - if not x in os.environ: + if x not in os.environ: continue workDirEscaped = re.escape("%s" % workDir) + "[^:]*:?" os.environ[x] = re.sub(workDirEscaped, "", os.environ[x]) diff --git a/alibuild_helpers/git.py b/alibuild_helpers/git.py index 4bf5c34a..80eb8e35 100644 --- a/alibuild_helpers/git.py +++ b/alibuild_helpers/git.py @@ -96,7 +96,7 @@ def git(args, directory=".", check=True, prompt=True): directory=quote(directory), args=" ".join(map(quote, args)), # GIT_TERMINAL_PROMPT is only supported in git 2.3+. - prompt_var=f"GIT_TERMINAL_PROMPT=0" if not prompt else "", + prompt_var="GIT_TERMINAL_PROMPT=0" if not prompt else "", 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 "", ), timeout=GIT_CMD_TIMEOUTS.get(args[0] if len(args) else "*", GIT_COMMAND_TIMEOUT_SEC)) if check and err != 0: diff --git a/alibuild_helpers/init.py b/alibuild_helpers/init.py index d9d3b04e..9ea4cce2 100644 --- a/alibuild_helpers/init.py +++ b/alibuild_helpers/init.py @@ -2,11 +2,12 @@ from alibuild_helpers.utilities import getPackageList, parseDefaults, readDefaults, validateDefaults from alibuild_helpers.log import debug, error, warning, banner, info from alibuild_helpers.log import dieOnError -from alibuild_helpers.workarea import cleanup_git_log, updateReferenceRepoSpec +from alibuild_helpers.workarea import updateReferenceRepoSpec from os.path import join import os.path as path -import os, sys +import os +import sys def parsePackagesDefinition(pkgname): return [ dict(zip(["name","ver"], y.split("@")[0:2])) diff --git a/alibuild_helpers/sync.py b/alibuild_helpers/sync.py index 5791fa9e..692f0366 100644 --- a/alibuild_helpers/sync.py +++ b/alibuild_helpers/sync.py @@ -364,7 +364,6 @@ def fetch_symlinks(self, spec) -> None: done """.format( workDir=self.workdir, - b=self.remoteStore, architecture=self.architecture, cvmfs_architecture=cvmfs_architecture, package=spec["package"], diff --git a/alibuild_helpers/utilities.py b/alibuild_helpers/utilities.py index 5ed97b0c..c972595e 100644 --- a/alibuild_helpers/utilities.py +++ b/alibuild_helpers/utilities.py @@ -150,7 +150,7 @@ def normalise_multiple_options(option, sep=","): def prunePaths(workDir): for x in ["PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"]: - if not x in os.environ: + if x not in os.environ: continue workDirEscaped = re.escape("%s" % workDir) + "[^:]*:?" os.environ[x] = re.sub(workDirEscaped, "", os.environ[x]) @@ -163,12 +163,12 @@ def validateSpec(spec): raise SpecError("Empty recipe.") if type(spec) != OrderedDict: raise SpecError("Not a YAML key / value.") - if not "package" in spec: + if "package" not in spec: raise SpecError("Missing package field in header.") # Use this to check if a given spec is compatible with the given default def validateDefaults(finalPkgSpec, defaults): - if not "valid_defaults" in finalPkgSpec: + if "valid_defaults" not in finalPkgSpec: return (True, "", []) validDefaults = asList(finalPkgSpec["valid_defaults"]) nonStringDefaults = [x for x in validDefaults if not type(x) == str] @@ -378,7 +378,7 @@ def parseRecipe(reader): err = "Unable to parse %s\n%s" % (reader.url, str(e)) except yaml.parser.ParserError as e: err = "Unable to parse %s\n%s" % (reader.url, str(e)) - except ValueError as e: + except ValueError: err = "Unable to parse %s. Header missing." % reader.url return err, spec, recipe @@ -496,7 +496,7 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem, systemRE = spec.get("prefer_system", "(?!.*)") try: systemREMatches = re.match(systemRE, architecture) - except TypeError as e: + except TypeError: dieOnError(True, "Malformed entry prefer_system: %s in %s" % (systemRE, spec["package"])) if not noSystem and (preferSystem or systemREMatches): requested_version = resolve_version(spec, defaults, "unavailable", "unavailable") @@ -553,7 +553,7 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem, "System requirements %s cannot have a recipe" % spec["package"]) if re.match(spec.get("system_requirement", "(?!.*)"), architecture): cmd = spec.get("system_requirement_check", "false") - if not spec["package"] in requirementsCache: + if spec["package"] not in requirementsCache: requirementsCache[spec["package"]] = performRequirementCheck(spec, cmd.strip()) err, output = requirementsCache[spec["package"]] @@ -580,8 +580,8 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem, spec["disabled"] += [x for x in fn("requires")] spec["disabled"] += [x for x in fn("build_requires")] fn = lambda what: filterByArchitectureDefaults(architecture, defaults, spec.get(what, [])) - spec["requires"] = [x for x in fn("requires") if not x in disable] - spec["build_requires"] = [x for x in fn("build_requires") if not x in disable] + spec["requires"] = [x for x in fn("requires") if x not in disable] + spec["build_requires"] = [x for x in fn("build_requires") if x not in disable] if spec["package"] != "defaults-release": spec["build_requires"].append("defaults-release") spec["runtime_requires"] = spec["requires"] diff --git a/tests/test_args.py b/tests/test_args.py index d0d6b61d..95d6d1e4 100644 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -1,10 +1,10 @@ from __future__ import print_function # Assuming you are using the mock library to ... mock things from unittest import mock -from unittest.mock import patch, call +from unittest.mock import patch import alibuild_helpers.args -from alibuild_helpers.args import doParseArgs, matchValidArch, finaliseArgs, DEFAULT_WORK_DIR, DEFAULT_CHDIR, ARCHITECTURE_TABLE +from alibuild_helpers.args import doParseArgs, matchValidArch import sys import os import os.path diff --git a/tests/test_build.py b/tests/test_build.py index f34b3839..13bd8f3e 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -203,7 +203,6 @@ class BuildTestCase(unittest.TestCase): @patch("alibuild_helpers.git.git") @patch("alibuild_helpers.build.exists", new=MagicMock(side_effect=dummy_exists)) @patch("os.path.exists", new=MagicMock(side_effect=dummy_exists)) - @patch("alibuild_helpers.build.sys") @patch("alibuild_helpers.build.dieOnError", new=MagicMock()) @patch("alibuild_helpers.utilities.dieOnError", new=MagicMock()) @patch("alibuild_helpers.utilities.warning") @@ -240,7 +239,7 @@ class BuildTestCase(unittest.TestCase): @patch("alibuild_helpers.workarea.is_writeable", new=MagicMock(return_value=True)) @patch("alibuild_helpers.build.basename", new=MagicMock(return_value="aliBuild")) @patch("alibuild_helpers.build.install_wrapper_script", new=MagicMock()) - def test_coverDoBuild(self, mock_debug, mock_listdir, mock_warning, mock_sys, mock_git_git) -> None: + def test_coverDoBuild(self, mock_debug, mock_listdir, mock_warning, mock_git_git) -> None: mock_git_git.side_effect = dummy_git mock_debug.side_effect = lambda *args: None mock_warning.side_effect = lambda *args: None @@ -281,7 +280,6 @@ def test_coverDoBuild(self, mock_debug, mock_listdir, mock_warning, mock_sys, mo forceTracked=False, plugin="legacy" ) - mock_sys.version_info = sys.version_info def mkcall(args): cmd, directory, check = args diff --git a/tests/test_clean.py b/tests/test_clean.py index 2738ed4b..1c21b82b 100644 --- a/tests/test_clean.py +++ b/tests/test_clean.py @@ -1,5 +1,4 @@ from __future__ import print_function -from textwrap import dedent # Assuming you are using the mock library to ... mock things from unittest.mock import patch, call diff --git a/tests/test_utilities.py b/tests/test_utilities.py index c5a365ce..5fa0417e 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -212,7 +212,7 @@ def test_prunePaths(self) -> None: } with patch.object(os, "environ", fake_env): prunePaths("/sw") - self.assertTrue(not "ROOT_VERSION" in fake_env) + self.assertTrue("ROOT_VERSION" not in fake_env) self.assertTrue(fake_env["PATH"] == "/usr/local/bin") self.assertTrue(fake_env["LD_LIBRARY_PATH"] == "") self.assertTrue(fake_env["DYLD_LIBRARY_PATH"] == "") @@ -220,7 +220,7 @@ def test_prunePaths(self) -> None: with patch.object(os, "environ", fake_env_copy): prunePaths("/foo") - self.assertTrue(not "ROOT_VERSION" in fake_env_copy) + self.assertTrue("ROOT_VERSION" not in fake_env_copy) self.assertTrue(fake_env_copy["PATH"] == "/sw/bin:/usr/local/bin") self.assertTrue(fake_env_copy["LD_LIBRARY_PATH"] == "/sw/lib") self.assertTrue(fake_env_copy["DYLD_LIBRARY_PATH"] == "/sw/lib")