From 0a93d3ede7955095adb24b27a8d973a143d2c8c2 Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 30 Mar 2021 15:41:24 +1100 Subject: [PATCH 1/9] -added flake8 workflow -fixed unused imports --- .github/workflows/benchmark.yaml | 6 ++--- .github/workflows/flake8.yaml | 44 ++++++++++++++++++++++++++++++++ .github/workflows/sphinx.yaml | 6 ++--- .github/workflows/wiki.yaml | 8 +++--- src/rez/__init__.py | 6 ++--- src/rez/build_process_.py | 2 +- src/rez/package_bind.py | 1 - src/rez/package_help.py | 2 -- src/rez/package_maker.py | 2 +- src/rez/package_maker__.py | 2 +- src/rez/package_resources_.py | 2 +- src/rez/package_serialise.py | 1 - src/rez/package_test.py | 5 ++-- src/rez/packages_.py | 2 +- src/rez/pip.py | 8 ++---- src/rez/release_vcs.py | 6 +++-- src/rez/resolver.py | 3 +-- src/rez/shells.py | 2 -- src/rez/status.py | 2 +- src/rez/system.py | 2 -- src/rez/tests/test_formatter.py | 1 - src/rez/tests/test_schema.py | 2 +- src/rez/tests/test_shells.py | 5 +--- src/rez/util.py | 2 -- src/rez/utils/__init__.py | 1 - src/rez/utils/backcompat.py | 19 ++++++-------- src/rez/utils/colorize.py | 1 - src/rez/utils/data_utils.py | 1 - src/rez/utils/execution.py | 1 + src/rez/utils/graph_utils.py | 2 -- src/rez/utils/installer.py | 2 +- src/rez/utils/memcached.py | 1 + src/rez/utils/patching.py | 6 ++--- src/rez/utils/pip.py | 3 --- src/rez/utils/schema.py | 2 +- src/rez/utils/yaml.py | 1 - 36 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/flake8.yaml diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 6104bccb9..50432e3c2 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -97,7 +97,7 @@ jobs: run: | git add --all git commit \ - -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ - && git push origin master \ - || echo "Nothing new to commit" + -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ + && git push origin master \ + || echo "Nothing new to commit" working-directory: src diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml new file mode 100644 index 000000000..f20953826 --- /dev/null +++ b/.github/workflows/flake8.yaml @@ -0,0 +1,44 @@ +name: pypi +on: + pull_request: + paths-ignore: + - '.github/docker/**' + - '.github/workflows/windows-docker-image.yaml' + - 'src/rez/utils/_version.py' + - 'wiki/**' + - 'metrics/**' + - 'data/**' + - '**.md' + push: + paths-ignore: + - '.github/docker/**' + - '.github/workflows/windows-docker-image.yaml' + - 'src/rez/utils/_version.py' + - 'wiki/**' + - 'metrics/**' + - 'data/**' + - '**.md' + +jobs: + lint: + name: Run Linter + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + + - name: Install Dependencies + run: | + pip install flake8 + + - name: Run flake8 + run: | + ls *.py utils/*.py cli/*.py tests/*.py \ + xargs flake8 + working-directory: src/rez diff --git a/.github/workflows/sphinx.yaml b/.github/workflows/sphinx.yaml index e7e57e297..12084c5f1 100644 --- a/.github/workflows/sphinx.yaml +++ b/.github/workflows/sphinx.yaml @@ -48,6 +48,6 @@ jobs: run: | git add . git commit \ - -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ - && git push --force origin gh-pages \ - || echo "Nothing new to commit" + -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ + && git push --force origin gh-pages \ + || echo "Nothing new to commit" diff --git a/.github/workflows/wiki.yaml b/.github/workflows/wiki.yaml index dea15a633..a683aa8a7 100644 --- a/.github/workflows/wiki.yaml +++ b/.github/workflows/wiki.yaml @@ -63,7 +63,7 @@ jobs: - name: Git commit and push run: | git commit \ - -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ - && git remote set-url origin "${{ env.CLONE_URL }}" \ - && git push origin master \ - || echo "Nothing new to commit" + -m "Generated from GitHub "${{ github.workflow }}" Workflow" \ + && git remote set-url origin "${{ env.CLONE_URL }}" \ + && git push origin master \ + || echo "Nothing new to commit" diff --git a/src/rez/__init__.py b/src/rez/__init__.py index 5c24c22d9..5754ace3f 100644 --- a/src/rez/__init__.py +++ b/src/rez/__init__.py @@ -1,7 +1,6 @@ from __future__ import print_function from rez.utils._version import _rez_version -import atexit import sys import os @@ -11,7 +10,7 @@ __license__ = "LGPL" -module_root_path = __path__[0] +module_root_path = __path__[0] # noqa # TODO: Revamp logging. For now, this is here for backwards compatibility @@ -43,7 +42,8 @@ def _init_logging(): # actions registered on SIGUSR1 action = os.getenv("REZ_SIGUSR1_ACTION") if action: - import signal, traceback + import signal + import traceback if action == "print_stack": def callback(sig, frame): diff --git a/src/rez/build_process_.py b/src/rez/build_process_.py index 028e6b9f2..f787f5ba0 100644 --- a/src/rez/build_process_.py +++ b/src/rez/build_process_.py @@ -1,5 +1,5 @@ import warnings -from rez.build_process import * +from rez.build_process import * # noqa warnings.warn( diff --git a/src/rez/package_bind.py b/src/rez/package_bind.py index e261e3ab3..8dc00520d 100644 --- a/src/rez/package_bind.py +++ b/src/rez/package_bind.py @@ -9,7 +9,6 @@ import argparse import os.path import os -import sys def get_bind_modules(verbose=False): diff --git a/src/rez/package_help.py b/src/rez/package_help.py index 0723fb515..4d9f05620 100644 --- a/src/rez/package_help.py +++ b/src/rez/package_help.py @@ -8,9 +8,7 @@ from rez.utils.scope import scoped_formatter from rez.vendor.six import six from rez.system import system -import subprocess import webbrowser -import os.path import sys diff --git a/src/rez/package_maker.py b/src/rez/package_maker.py index 0bfacadf9..76b81da40 100644 --- a/src/rez/package_maker.py +++ b/src/rez/package_maker.py @@ -1,5 +1,5 @@ from rez.utils._version import _rez_version -from rez.utils.schema import Required, schema_keys, extensible_schema_dict +from rez.utils.schema import Required, extensible_schema_dict from rez.utils.filesystem import retain_cwd from rez.utils.formatting import PackageRequest from rez.utils.data_utils import AttrDictWrapper diff --git a/src/rez/package_maker__.py b/src/rez/package_maker__.py index e6de7747e..129c355f3 100644 --- a/src/rez/package_maker__.py +++ b/src/rez/package_maker__.py @@ -1,5 +1,5 @@ import warnings -from rez.package_maker import * +from rez.package_maker import * # noqa warnings.warn( diff --git a/src/rez/package_resources_.py b/src/rez/package_resources_.py index 773f7da8a..ccbf5e91d 100644 --- a/src/rez/package_resources_.py +++ b/src/rez/package_resources_.py @@ -1,5 +1,5 @@ import warnings -from rez.package_resources import * +from rez.package_resources import * # noqa warnings.warn( diff --git a/src/rez/package_serialise.py b/src/rez/package_serialise.py index 156bcc31a..9fa61a7a9 100644 --- a/src/rez/package_serialise.py +++ b/src/rez/package_serialise.py @@ -1,6 +1,5 @@ from __future__ import print_function -from rez.vendor import yaml from rez.serialise import FileFormat from rez.package_resources import help_schema, late_bound from rez.vendor.schema.schema import Schema, Optional, And, Or, Use diff --git a/src/rez/package_test.py b/src/rez/package_test.py index 93d9738d6..88d4516d4 100644 --- a/src/rez/package_test.py +++ b/src/rez/package_test.py @@ -1,14 +1,13 @@ from rez.config import config from rez.resolved_context import ResolvedContext -from rez.packages import get_latest_package_from_string, Variant +from rez.packages import get_latest_package_from_string from rez.exceptions import RezError, PackageNotFoundError, PackageTestError from rez.utils.data_utils import RO_AttrDictWrapper from rez.utils.colorize import heading, Printer -from rez.utils.logging_ import print_info, print_warning, print_error, print_debug +from rez.utils.logging_ import print_info, print_warning, print_error from rez.vendor.six import six from rez.vendor.version.requirement import Requirement, RequirementList from pipes import quote -import subprocess import time import sys import os diff --git a/src/rez/packages_.py b/src/rez/packages_.py index 41d2878fe..1d5e0fbcf 100644 --- a/src/rez/packages_.py +++ b/src/rez/packages_.py @@ -1,5 +1,5 @@ import warnings -from rez.packages import * +from rez.packages import * # noqa warnings.warn( diff --git a/src/rez/pip.py b/src/rez/pip.py index 1b269d446..b7ecbd934 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -1,11 +1,8 @@ from __future__ import print_function, absolute_import from rez.packages import get_latest_package -from rez.vendor.version.version import Version, VersionError -from rez.vendor.distlib import DistlibException +from rez.vendor.version.version import Version from rez.vendor.distlib.database import DistributionPath -from rez.vendor.distlib.markers import interpret -from rez.vendor.distlib.util import parse_name_and_version from rez.vendor.enum.enum import Enum from rez.vendor.packaging.version import Version as PackagingVersion from rez.vendor.packaging.specifiers import Specifier @@ -17,10 +14,9 @@ from rez.utils.logging_ import print_debug, print_info, print_error, \ print_warning from rez.exceptions import BuildError, PackageFamilyNotFoundError, \ - PackageNotFoundError, RezSystemError, convert_errors + PackageNotFoundError, RezSystemError from rez.package_maker import make_package from rez.config import config -from rez.utils.platform_ import platform_ import os from pipes import quote diff --git a/src/rez/release_vcs.py b/src/rez/release_vcs.py index 18d5950df..877e6c019 100644 --- a/src/rez/release_vcs.py +++ b/src/rez/release_vcs.py @@ -34,8 +34,10 @@ def create_release_vcs(path, vcs_name=None): classes_by_level.setdefault(levels_up, []).append((cls, vcs_path)) if not classes_by_level: - raise ReleaseVCSError("No version control system for package " - "releasing is associated with the path %s" % path) + raise ReleaseVCSError( + "No version control system for package " + "releasing is associated with the path %s" % path + ) # it's ok to have multiple results, as long as there is only one at the # "closest" directory up from this dir - ie, if we start at: diff --git a/src/rez/resolver.py b/src/rez/resolver.py index 398a77bc5..6689b8977 100644 --- a/src/rez/resolver.py +++ b/src/rez/resolver.py @@ -1,4 +1,4 @@ -from rez.solver import Solver, SolverStatus, PackageVariantCache +from rez.solver import Solver, SolverStatus from rez.package_repository import package_repository_manager from rez.packages import get_variant, get_last_release_time from rez.package_filter import PackageFilterList, TimestampRule @@ -9,7 +9,6 @@ from rez.vendor.version.requirement import Requirement from contextlib import contextmanager from hashlib import sha1 -import os class ResolverStatus(Enum): diff --git a/src/rez/shells.py b/src/rez/shells.py index 188dafb59..9d6052563 100644 --- a/src/rez/shells.py +++ b/src/rez/shells.py @@ -11,11 +11,9 @@ from rez.rex import EscapedString from rez.config import config from rez.vendor.six import six -import subprocess import os import os.path import pipes -import re basestring = six.string_types[0] diff --git a/src/rez/status.py b/src/rez/status.py index 99d3b19b8..70ecb9584 100644 --- a/src/rez/status.py +++ b/src/rez/status.py @@ -10,7 +10,7 @@ from rez.packages import iter_packages, Package from rez.suite import Suite from rez.wrapper import Wrapper -from rez.utils.colorize import local, warning, critical, Printer +from rez.utils.colorize import warning, critical, Printer from rez.utils.formatting import print_colored_columns, PackageRequest from rez.backport.shutilwhich import which diff --git a/src/rez/system.py b/src/rez/system.py index 95d78e34b..c6c33470f 100644 --- a/src/rez/system.py +++ b/src/rez/system.py @@ -1,13 +1,11 @@ import os import os.path import re -import sys import platform from rez import __version__ from rez.utils.platform_ import platform_ from rez.exceptions import RezSystemError -from rez.util import which from rez.utils.data_utils import cached_property diff --git a/src/rez/tests/test_formatter.py b/src/rez/tests/test_formatter.py index 18c1abff7..d14da1717 100644 --- a/src/rez/tests/test_formatter.py +++ b/src/rez/tests/test_formatter.py @@ -5,7 +5,6 @@ from rez.tests.util import TestBase from rez.rex import NamespaceFormatter from rez.vendor.six import six -import sys class TestFormatter(TestBase): diff --git a/src/rez/tests/test_schema.py b/src/rez/tests/test_schema.py index 25e0b08f5..3ae4f9fc6 100644 --- a/src/rez/tests/test_schema.py +++ b/src/rez/tests/test_schema.py @@ -2,7 +2,7 @@ unit tests for 'schema' module """ import unittest -from rez.vendor.schema.test_schema import TestSchema +from rez.vendor.schema.test_schema import TestSchema # noqa if __name__ == '__main__': diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py index 9773c4e5b..58592c062 100644 --- a/src/rez/tests/test_shells.py +++ b/src/rez/tests/test_shells.py @@ -7,13 +7,10 @@ from rez.shells import create_shell from rez.resolved_context import ResolvedContext from rez.rex import literal, expandable -from rez.utils.execution import create_executable_script, ExecutableScriptMode, \ - _get_python_script_files +from rez.utils.execution import ExecutableScriptMode, _get_python_script_files from rez.tests.util import TestBase, TempdirMixin, per_available_shell, \ install_dependent -from rez.util import which from rez.bind import hello_world -from rez.vendor.six import six import unittest import subprocess import tempfile diff --git a/src/rez/util.py b/src/rez/util.py index 61c50af50..f37996fe2 100644 --- a/src/rez/util.py +++ b/src/rez/util.py @@ -2,7 +2,6 @@ Misc useful stuff. TODO: Move this into rez.utils.? """ -import sys import collections import atexit import os @@ -12,7 +11,6 @@ from rez.vendor.six import six - class ProgressBar(Bar): def __init__(self, label, max): from rez.config import config diff --git a/src/rez/utils/__init__.py b/src/rez/utils/__init__.py index 4f60dad7f..b165d767a 100644 --- a/src/rez/utils/__init__.py +++ b/src/rez/utils/__init__.py @@ -1,4 +1,3 @@ -import re import sys from rez.vendor.six import six from contextlib import contextmanager diff --git a/src/rez/utils/backcompat.py b/src/rez/utils/backcompat.py index 0023fa12c..ff9e18694 100644 --- a/src/rez/utils/backcompat.py +++ b/src/rez/utils/backcompat.py @@ -1,8 +1,6 @@ """ Utility code for supporting earlier Rez data in later Rez releases. """ -from rez.config import config -from rez.utils.logging_ import print_debug import re import os import os.path @@ -10,10 +8,10 @@ variant_key_conversions = { - "name": "name", - "version": "version", - "index": "index", - "search_path": "location" + "name": "name", + "version": "version", + "index": "index", + "search_path": "location" } @@ -24,7 +22,6 @@ def convert_old_variant_handle(handle_dict): for old_key, key in variant_key_conversions.items(): value = old_variables.get(old_key) - #if value is not None: variables[key] = value path = handle_dict["path"] @@ -39,12 +36,12 @@ def convert_old_variant_handle(handle_dict): def convert_old_command_expansions(command): """Convert expansions from !OLD! style to {new}.""" - command = command.replace("!VERSION!", "{version}") + command = command.replace("!VERSION!", "{version}") command = command.replace("!MAJOR_VERSION!", "{version.major}") command = command.replace("!MINOR_VERSION!", "{version.minor}") - command = command.replace("!BASE!", "{base}") - command = command.replace("!ROOT!", "{root}") - command = command.replace("!USER!", "{system.user}") + command = command.replace("!BASE!", "{base}") + command = command.replace("!ROOT!", "{root}") + command = command.replace("!USER!", "{system.user}") return command diff --git a/src/rez/utils/colorize.py b/src/rez/utils/colorize.py index 0f1f4191e..b97cc305f 100644 --- a/src/rez/utils/colorize.py +++ b/src/rez/utils/colorize.py @@ -4,7 +4,6 @@ import logging from rez.vendor import colorama from rez.config import config -from rez.utils.platform_ import platform_ _initialised = False diff --git a/src/rez/utils/data_utils.py b/src/rez/utils/data_utils.py index 3adf806aa..f1913e613 100644 --- a/src/rez/utils/data_utils.py +++ b/src/rez/utils/data_utils.py @@ -4,7 +4,6 @@ import os.path from rez.vendor.schema.schema import Schema, Optional -from rez.exceptions import RexError from threading import Lock from rez.vendor.six import six diff --git a/src/rez/utils/execution.py b/src/rez/utils/execution.py index 93279377d..53fe540de 100644 --- a/src/rez/utils/execution.py +++ b/src/rez/utils/execution.py @@ -30,6 +30,7 @@ def add_sys_paths(paths): class _PopenBase(subprocess.Popen): def __enter__(self): return self + def __exit__(self, exc_type, value, traceback): self.wait() diff --git a/src/rez/utils/graph_utils.py b/src/rez/utils/graph_utils.py index 612bd9784..92639fa1a 100644 --- a/src/rez/utils/graph_utils.py +++ b/src/rez/utils/graph_utils.py @@ -3,9 +3,7 @@ """ from __future__ import print_function -import re import os.path -import subprocess import sys import tempfile from ast import literal_eval diff --git a/src/rez/utils/installer.py b/src/rez/utils/installer.py index a4837b24f..dd2dd3002 100644 --- a/src/rez/utils/installer.py +++ b/src/rez/utils/installer.py @@ -18,7 +18,7 @@ def install_as_rez_package(repo_path): repo_path (str): Repository to install the rez package into. """ def commands(): - env.PYTHONPATH.append('{this.root}') + env.PYTHONPATH.append('{this.root}') # noqa def make_root(variant, root): # copy source diff --git a/src/rez/utils/memcached.py b/src/rez/utils/memcached.py index fa09fc849..911232db9 100644 --- a/src/rez/utils/memcached.py +++ b/src/rez/utils/memcached.py @@ -12,6 +12,7 @@ from uuid import uuid4 from rez.vendor.six import six + basestring = six.string_types[0] diff --git a/src/rez/utils/patching.py b/src/rez/utils/patching.py index dc5d06405..61c567017 100644 --- a/src/rez/utils/patching.py +++ b/src/rez/utils/patching.py @@ -32,10 +32,10 @@ def get_patched_request(requires, patchlist): # rules from table in docstring above rules = { - '': (True, True, True ), + '': (True, True, True), '!': (False, False, False), - '~': (False, False, True ), - '^': (True, True, True ) + '~': (False, False, True), + '^': (True, True, True) } requires = [Requirement(x) if not isinstance(x, Requirement) else x diff --git a/src/rez/utils/pip.py b/src/rez/utils/pip.py index 271b1483b..83b59d5cd 100644 --- a/src/rez/utils/pip.py +++ b/src/rez/utils/pip.py @@ -2,13 +2,10 @@ Python packaging related utilities. """ import os.path -import sys from email.parser import Parser -import platform import pkg_resources -from rez.vendor.distlib.util import parse_name_and_version from rez.vendor.packaging.version import ( parse as packaging_parse, LegacyVersion as packaging_LegacyVersion, diff --git a/src/rez/utils/schema.py b/src/rez/utils/schema.py index 286066659..1bf5ce862 100644 --- a/src/rez/utils/schema.py +++ b/src/rez/utils/schema.py @@ -2,7 +2,7 @@ Utilities for working with dict-based schemas. """ from rez.vendor.six import six -from rez.vendor.schema.schema import Schema, Optional, Use, And, Optional +from rez.vendor.schema.schema import Schema, Optional, Use, And basestring = six.string_types[0] diff --git a/src/rez/utils/yaml.py b/src/rez/utils/yaml.py index 85e650cdf..60e2ad7cb 100644 --- a/src/rez/utils/yaml.py +++ b/src/rez/utils/yaml.py @@ -1,7 +1,6 @@ from rez.utils.sourcecode import SourceCode from rez.vendor import yaml from rez.vendor.yaml.dumper import SafeDumper -from rez.vendor.yaml.nodes import ScalarNode, MappingNode from rez.vendor.version.version import Version from rez.vendor.version.requirement import Requirement from types import FunctionType, BuiltinFunctionType From b312a86f4a001d9e98e0166d24673e5f624ce543 Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 30 Mar 2021 15:54:18 +1100 Subject: [PATCH 2/9] fixed unused variable bugs --- .github/workflows/flake8.yaml | 5 ++++- src/rez/developer_package.py | 2 -- src/rez/package_bind.py | 2 -- src/rez/package_maker.py | 1 - src/rez/rex.py | 2 +- src/rez/solver.py | 1 - src/rez/tests/test_config.py | 4 +--- src/rez/tests/test_packages.py | 4 +--- src/rez/tests/test_shells.py | 2 -- src/rez/utils/_version.py | 2 +- src/rez/utils/memcached.py | 7 +++++-- src/rez/utils/pip.py | 1 - src/rez/utils/scope.py | 1 - 13 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index f20953826..4939bc610 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -40,5 +40,8 @@ jobs: - name: Run flake8 run: | ls *.py utils/*.py cli/*.py tests/*.py \ - xargs flake8 + xargs flake8 --select \ + F401 `# unused import` \ + F841 `# unused variable` + working-directory: src/rez diff --git a/src/rez/developer_package.py b/src/rez/developer_package.py index 17c9f38c7..9e1ad1e58 100644 --- a/src/rez/developer_package.py +++ b/src/rez/developer_package.py @@ -183,8 +183,6 @@ def _get_preprocessed(self, data): from rez.utils.data_utils import get_dict_diff_str from copy import deepcopy - package_preprocess_mode = self.config.package_preprocess_mode - def _get_package_level(): return getattr(self, "preprocess", None) diff --git a/src/rez/package_bind.py b/src/rez/package_bind.py index 8dc00520d..2c126f8fa 100644 --- a/src/rez/package_bind.py +++ b/src/rez/package_bind.py @@ -94,7 +94,6 @@ def bind_package(name, path=None, version_range=None, no_deps=False, pending = set([name]) installed_variants = [] installed_package_names = set() - primary = True # bind package and possibly dependencies while pending: @@ -129,7 +128,6 @@ def bind_package(name, path=None, version_range=None, no_deps=False, pending.add(requirement.name) # non-primary packages are treated a little differently - primary = False version_range = None bind_args = None exc_type = RezBindError diff --git a/src/rez/package_maker.py b/src/rez/package_maker.py index 76b81da40..9d6c154d2 100644 --- a/src/rez/package_maker.py +++ b/src/rez/package_maker.py @@ -197,7 +197,6 @@ def make_package(name, path, make_base=None, make_root=None, skip_existing=True, # package = maker.get_package() - cwd = os.getcwd() src_variants = [] # skip those variants that already exist diff --git a/src/rez/rex.py b/src/rez/rex.py index 87054a27f..2e6cb82ad 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -1380,7 +1380,7 @@ def execute_function(self, func, *nargs, **kwargs): return fn(*nargs, **kwargs) except RexError: raise - except exc_type as e: + except exc_type: from inspect import getfile stack = traceback.format_exc() diff --git a/src/rez/solver.py b/src/rez/solver.py index 882a84e95..e3e0b3dab 100644 --- a/src/rez/solver.py +++ b/src/rez/solver.py @@ -990,7 +990,6 @@ def intersect(self, range_): # ephemerals are just a range intersection if self.is_ephemeral: - inter_range = None if self.is_conflict: intersect_range = range_ - self.package_request.range else: diff --git a/src/rez/tests/test_config.py b/src/rez/tests/test_config.py index dddf3d8bb..f5513327d 100644 --- a/src/rez/tests/test_config.py +++ b/src/rez/tests/test_config.py @@ -188,8 +188,7 @@ def test_5(self): c = Config([conf], locked=True) with self.assertRaises(ConfigurationError): - _ = c.debug_all - + _ = c.debug_all # noqa def test_6(self): """Test setting of dict values from environ""" @@ -209,7 +208,6 @@ class TestConfig(Config): def _data(self): return {'dumb_dict': self.DEFAULT_DUMB_DICT} - # need to NOT use locked, because we want to test setting from env # vars, but don't want values from "real" os.environ to pollute our # test... diff --git a/src/rez/tests/test_packages.py b/src/rez/tests/test_packages.py index e9be06e9a..a191a6393 100644 --- a/src/rez/tests/test_packages.py +++ b/src/rez/tests/test_packages.py @@ -316,8 +316,6 @@ def test_6(self): requires=[PackageRequest("python-2.7")], commands=SourceCode('env.PATH.append("{root}/bin")')) - requires_ = ["platform-linux", "platform-osx"] - package = get_package("variants_py", "2.0") for i, variant in enumerate(package.iter_variants()): data = variant.validated_data() @@ -437,7 +435,7 @@ def test_1_memory_variant_parent(self): self.assertEqual(package.description, desc) variant = next(package.iter_variants()) parent_package = variant.parent - self.assertEqual(package.description, desc) + self.assertEqual(parent_package.description, desc) if __name__ == '__main__': diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py index 58592c062..f50a1f28d 100644 --- a/src/rez/tests/test_shells.py +++ b/src/rez/tests/test_shells.py @@ -224,9 +224,7 @@ def _execute_code(func, expected_output): out, _ = p.communicate() self.assertEqual(p.returncode, 0) - sh = create_shell() output = out.strip().split("\n") - self.assertEqual(output, expected_output) def _rex_assigning(): diff --git a/src/rez/utils/_version.py b/src/rez/utils/_version.py index 858ad315d..dc3b661e2 100644 --- a/src/rez/utils/_version.py +++ b/src/rez/utils/_version.py @@ -1,7 +1,7 @@ # Update this value to version up Rez. Do not place anything else in this file. -_rez_version = "2.80.0" +_rez_version = "2.81.0" # Copyright 2013-2016 Allan Johns. diff --git a/src/rez/utils/memcached.py b/src/rez/utils/memcached.py index 911232db9..9f40f8d3a 100644 --- a/src/rez/utils/memcached.py +++ b/src/rez/utils/memcached.py @@ -321,7 +321,7 @@ def _listdir(path): """ def default_key(func, *nargs, **kwargs): parts = [func.__module__] - argnames = py23.get_function_arg_names(func) + argnames = py23.get_function_arg_names(func) if argnames: if argnames[0] == "cls": @@ -336,11 +336,14 @@ def default_key(func, *nargs, **kwargs): parts.append(func.__name__) value = ('.'.join(parts), nargs, tuple(sorted(kwargs.items()))) + # make sure key is hashable. We don't strictly need it to be, but this # is a way of hopefully avoiding object types that are not ordered (these # would give an unreliable key). If you need to key on unhashable args, # you should provide your own `key` functor. - _ = hash(value) + # + _ = hash(value) # noqa + return repr(value) def identity(value, *nargs, **kwargs): diff --git a/src/rez/utils/pip.py b/src/rez/utils/pip.py index 83b59d5cd..5d8d6cb3f 100644 --- a/src/rez/utils/pip.py +++ b/src/rez/utils/pip.py @@ -518,7 +518,6 @@ def get_marker_sys_requirements(marker): _py = "python" _plat = "platform" _arch = "arch" - _os = "os" sys_requires_lookup = { # TODO There is no way to associate a python version with its implementation diff --git a/src/rez/utils/scope.py b/src/rez/utils/scope.py index cde3a46d9..a51674276 100644 --- a/src/rez/utils/scope.py +++ b/src/rez/utils/scope.py @@ -257,7 +257,6 @@ def scoped_format(txt, **objects): """ pretty = objects.pop("pretty", RecursiveAttribute.format_pretty) expand = objects.pop("expand", RecursiveAttribute.format_expand) - attr = RecursiveAttribute(objects, read_only=True) formatter = scoped_formatter(**objects) return formatter.format(txt, pretty=pretty, expand=expand) From d16dceee0693ee492acb6a63391f547741966f9f Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 30 Mar 2021 16:34:12 +1100 Subject: [PATCH 3/9] lots of lint fixes --- .github/workflows/flake8.yaml | 15 +++- src/rez/config.py | 6 +- src/rez/package_py_utils.py | 6 +- src/rez/package_resources.py | 4 +- src/rez/pip.py | 4 +- src/rez/plugin_managers.py | 2 +- src/rez/rex.py | 41 +++++----- src/rez/solver.py | 16 ++-- src/rez/suite.py | 6 +- src/rez/tests/test_release.py | 1 + src/rez/tests/test_rex.py | 75 +++++++++---------- src/rez/util.py | 4 +- src/rez/utils/colorize.py | 6 +- src/rez/utils/execution.py | 19 +++-- src/rez/utils/formatting.py | 6 +- src/rez/utils/resources.py | 6 +- src/rez/utils/sourcecode.py | 16 ++-- .../shell/_utils/powershell_base.py | 5 +- 18 files changed, 139 insertions(+), 99 deletions(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index 4939bc610..fc247b15c 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -39,9 +39,16 @@ jobs: - name: Run flake8 run: | - ls *.py utils/*.py cli/*.py tests/*.py \ - xargs flake8 --select \ - F401 `# unused import` \ - F841 `# unused variable` + find -name '*.py' \ + -not -path './build_utils/*' \ + -not -path './rez/vendor/*' \ + -not -path './rez/data/*' \ + -not -path './support/*' \ + -not -path './rez/backport/*' \ + -not -path './rezgui/*' \ + | xargs flake8 --select \ + E122 E127 E225 E251 E305 E711 \ + F401 F841 \ + W503 working-directory: src/rez diff --git a/src/rez/config.py b/src/rez/config.py index 3f76f46cc..5081be930 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -633,8 +633,10 @@ def _get_plugin_completions(prefix_): return _get_plugin_completions(prefix_) return [] else: - keys = ([x for x in self._schema_keys if isinstance(x, basestring)] - + ["plugins"]) + keys = ( + [x for x in self._schema_keys if isinstance(x, basestring)] + + ["plugins"] + ) keys = [x for x in keys if x.startswith(prefix)] if keys == ["plugins"]: keys += _get_plugin_completions('') diff --git a/src/rez/package_py_utils.py b/src/rez/package_py_utils.py index 4b25628e9..3594a4a0b 100644 --- a/src/rez/package_py_utils.py +++ b/src/rez/package_py_utils.py @@ -236,8 +236,10 @@ def find_site_python(module_name, paths=None): py_cmd = 'import {x}; print({x}.__path__)'.format(x=module_name) - p = Popen(["python", "-c", py_cmd], stdout=subprocess.PIPE, - stderr=subprocess.PIPE, text=True) + p = Popen( + ["python", "-c", py_cmd], stdout=subprocess.PIPE, + stderr=subprocess.PIPE, text=True + ) out, err = p.communicate() if p.returncode: diff --git a/src/rez/package_resources.py b/src/rez/package_resources.py index 51a3b2fac..004a310b5 100644 --- a/src/rez/package_resources.py +++ b/src/rez/package_resources.py @@ -58,9 +58,11 @@ _is_late = And(SourceCode, lambda x: hasattr(x, "_late")) + def late_bound(schema): return Or(SourceCode, schema) + # used when 'requires' is late bound late_requires_schema = Schema([ Or(PackageRequest, And(basestring, Use(PackageRequest))) @@ -75,7 +77,7 @@ def late_bound(schema): # base_resource_schema_dict = { - Required("name"): basestring + Required("name"): basestring } diff --git a/src/rez/pip.py b/src/rez/pip.py index b7ecbd934..d742607b3 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -352,8 +352,8 @@ def log_append_pkg_variants(pkg_maker): "run_requires": map(str, distribution.run_requires) }, "rez": rez_requires - } - )) + }) + ) # determine where pip files need to be copied into rez package src_dst_lut = _get_distribution_files_mapping(distribution, targetpath) diff --git a/src/rez/plugin_managers.py b/src/rez/plugin_managers.py index f6cc3f073..d787dbac6 100644 --- a/src/rez/plugin_managers.py +++ b/src/rez/plugin_managers.py @@ -141,7 +141,7 @@ def load_plugins(self): if hasattr(module, 'register_plugin') and \ hasattr(module.register_plugin, '__call__'): plugin_class = module.register_plugin() - if plugin_class != None: + if plugin_class is not None: self.register_plugin(plugin_name, plugin_class, module) else: if config.debug("plugins"): diff --git a/src/rez/rex.py b/src/rez/rex.py index 2e6cb82ad..5fe48402e 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -74,7 +74,6 @@ def value(self): class Unsetenv(EnvAction): name = 'unsetenv' -Unsetenv.register() class Setenv(EnvAction): @@ -89,7 +88,6 @@ def pre_exec(self, interpreter): def post_exec(self, interpreter, result): interpreter._environ.add(self.key) return result -Setenv.register() class Resetenv(EnvAction): @@ -109,56 +107,60 @@ def pre_exec(self, interpreter): def post_exec(self, interpreter, result): interpreter._environ.add(self.key) return result -Resetenv.register() class Prependenv(Setenv): name = 'prependenv' -Prependenv.register() class Appendenv(Setenv): name = 'appendenv' -Appendenv.register() class Alias(Action): name = 'alias' -Alias.register() class Info(Action): name = 'info' -Info.register() class Error(Action): name = 'error' -Error.register() class Stop(Action): name = 'stop' -Stop.register() class Command(Action): name = 'command' -Command.register() class Comment(Action): name = 'comment' -Comment.register() class Source(Action): name = 'source' -Source.register() class Shebang(Action): name = 'shebang' + + +Unsetenv.register() +Setenv.register() +Resetenv.register() +Prependenv.register() +Appendenv.register() +Alias.register() +Info.register() +Error.register() +Stop.register() +Command.register() +Comment.register() +Source.register() Shebang.register() @@ -276,8 +278,10 @@ def get_output(self, style=OutputStyle.file): def undefined(self, key): _, expanded_key = self._key(key) - return (expanded_key not in self.environ - and expanded_key not in self.parent_environ) + return ( + expanded_key not in self.environ and + expanded_key not in self.parent_environ + ) def defined(self, key): return not self.undefined(key) @@ -474,7 +478,6 @@ class ActionInterpreter(object): ]) ) - def get_output(self, style=OutputStyle.file): """Returns any implementation specific data. @@ -794,7 +797,7 @@ def expandable(self, value): self._add(value, False) return self - def l(self, value): + def l(self, value): # noqa return self.literal(value) def e(self, value): @@ -818,8 +821,10 @@ def __eq__(self, other): if isinstance(other, basestring): return (str(self) == str(other)) else: - return (isinstance(other, EscapedString) - and other.strings == self.strings) + return ( + isinstance(other, EscapedString) and + other.strings == self.strings + ) def __ne__(self, other): return not (self == other) diff --git a/src/rez/solver.py b/src/rez/solver.py index e3e0b3dab..d0b355906 100644 --- a/src/rez/solver.py +++ b/src/rez/solver.py @@ -347,14 +347,18 @@ def get(self, pkg_name): return self.requires_list.get(pkg_name) def __eq__(self, other): - return (self.name == other.name - and self.version == other.version - and self.index == other.index) + return ( + self.name == other.name and + self.version == other.version and + self.index == other.index + ) def __lt__(self, other): - return (self.name < other.name - and self.version < other.version - and self.index < other.index) + return ( + self.name < other.name and + self.version < other.version and + self.index < other.index + ) def __str__(self): stmt = VersionedObject.construct(self.name, self.version) diff --git a/src/rez/suite.py b/src/rez/suite.py index f8de429a3..157a3f5a9 100644 --- a/src/rez/suite.py +++ b/src/rez/suite.py @@ -158,8 +158,10 @@ def _in_resolve(name): variant = context.get_resolved_package(in_resolve.name) if variant: overlap = (variant.version in in_resolve.range) - return ((in_resolve.conflict and not overlap) - or (overlap and not in_resolve.conflict)) + return ( + (in_resolve.conflict and not overlap) or + (overlap and not in_resolve.conflict) + ) else: return in_resolve.conflict diff --git a/src/rez/tests/test_release.py b/src/rez/tests/test_release.py index 6143282e2..61240abe4 100644 --- a/src/rez/tests/test_release.py +++ b/src/rez/tests/test_release.py @@ -231,6 +231,7 @@ def test_2_variant_add(self): # ...but that the description was updated self.assertEqual(rel_package.description, third_desc) + if __name__ == '__main__': unittest.main() diff --git a/src/rez/tests/test_rex.py b/src/rez/tests/test_rex.py index b2712da4b..a48899771 100644 --- a/src/rez/tests/test_rex.py +++ b/src/rez/tests/test_rex.py @@ -77,7 +77,7 @@ def _rex(): self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Shebang(), Setenv('FOO', 'foo'), Setenv('BAH', 'bah'), @@ -92,10 +92,10 @@ def _rex(): Error('oh noes'), Command('runme --with --args'), Source('./script.src')], - expected_output = { + expected_output={ 'FOO': 'foo', - 'A': os.pathsep.join(["/data","/tmp"]), - 'B': os.pathsep.join(["/tmp","/data"])}) + 'A': os.pathsep.join(["/data", "/tmp"]), + 'B': os.pathsep.join(["/tmp", "/data"])}) def test_2(self): """Test simple setenvs and assignments.""" @@ -106,11 +106,11 @@ def _rex(): self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'foo'), Setenv('BAH', 'bah'), Setenv('EEK', 'foo')], - expected_output = { + expected_output={ 'FOO': 'foo', 'EEK': 'foo', 'BAH': 'bah'}) @@ -129,16 +129,16 @@ def _rex(): # no parent variables enabled self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'test1'), Appendenv('FOO', 'test2'), Appendenv('FOO', 'test3'), Setenv('BAH', 'A'), Prependenv('BAH', 'B'), Appendenv('BAH', 'C')], - expected_output = { - 'FOO': os.pathsep.join(["test1","test2","test3"]), - 'BAH': os.pathsep.join(["B","A","C"])}) + expected_output={ + 'FOO': os.pathsep.join(["test1", "test2", "test3"]), + 'BAH': os.pathsep.join(["B", "A", "C"])}) # FOO and BAH enabled as parent variables, but not present expected_actions = [Appendenv('FOO', 'test1'), @@ -151,20 +151,20 @@ def _rex(): self._test(func=_rex, env={}, expected_actions=expected_actions, - expected_output = { - 'FOO': os.pathsep.join(["", "test1","test2","test3"]), - 'BAH': os.pathsep.join(["B","A", "","C"])}, - parent_variables=["FOO","BAH"]) + expected_output={ + 'FOO': os.pathsep.join(["", "test1", "test2", "test3"]), + 'BAH': os.pathsep.join(["B", "A", "", "C"])}, + parent_variables=["FOO", "BAH"]) # FOO and BAH enabled as parent variables, and present self._test(func=_rex, env={"FOO": "tmp", "BAH": "Z"}, expected_actions=expected_actions, - expected_output = { - 'FOO': os.pathsep.join(["tmp", "test1","test2","test3"]), - 'BAH': os.pathsep.join(["B","A", "Z","C"])}, - parent_variables=["FOO","BAH"]) + expected_output={ + 'FOO': os.pathsep.join(["tmp", "test1", "test2", "test3"]), + 'BAH': os.pathsep.join(["B", "A", "Z", "C"])}, + parent_variables=["FOO", "BAH"]) def test_4(self): """Test control flow using internally-set env vars.""" @@ -182,14 +182,14 @@ def _rex(): self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'foo'), Setenv('BAH', 'bah'), Setenv('EEK', 'foo'), Setenv('FOO_VALID', '1'), Info('FOO validated'), Comment('comparison ok')], - expected_output = { + expected_output={ 'FOO': 'foo', 'BAH': 'bah', 'EEK': 'foo', @@ -209,18 +209,18 @@ def _rex(): # with EXT undefined self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('EXT_FOUND', '0'), Info("undefined working as expected")], - expected_output = {'EXT_FOUND': '0'}) + expected_output={'EXT_FOUND': '0'}) # with EXT defined self._test(func=_rex, env={"EXT": "alpha"}, - expected_actions = [ + expected_actions=[ Setenv('EXT_FOUND', '1'), Setenv('EXT', 'beta')], - expected_output = { + expected_output={ 'EXT_FOUND': '1', 'EXT': 'beta'}) @@ -240,13 +240,13 @@ def _rex(): # with EXT undefined self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'foo'), Setenv('DOG', '${FOO}'), Setenv('BAH', '${FOO}'), Setenv('EEK', '${BAH}'), Info('expansions visible in control flow')], - expected_output = { + expected_output={ 'FOO': 'foo', 'DOG': 'foo', 'BAH': 'foo', @@ -255,17 +255,16 @@ def _rex(): # with EXT defined self._test(func=_rex, env={"EXT": "alpha"}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'foo'), Setenv('DOG', '${FOO}'), Setenv('BAH', '${FOO}'), Setenv('EEK', '${BAH}'), Info('expansions visible in control flow'), Setenv('FEE', '${EXT}')], - expected_output = { + expected_output={ 'FOO': 'foo', 'DOG': 'foo', - 'FEE': 'foo', 'BAH': 'foo', 'EEK': 'foo', 'FEE': 'alpha'}) @@ -299,7 +298,7 @@ def _rex3(): def test_8(self): """Custom environment variable separators.""" - config.override("env_var_separators", {"FOO":",", "BAH":" "}) + config.override("env_var_separators", {"FOO": ",", "BAH": " "}) def _rex(): appendenv("FOO", "test1") @@ -312,16 +311,16 @@ def _rex(): self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('FOO', 'test1'), Appendenv('FOO', 'test2'), Appendenv('FOO', 'test3'), Setenv('BAH', 'A'), Prependenv('BAH', 'B'), Appendenv('BAH', 'C')], - expected_output = { - 'FOO': ",".join(["test1","test2","test3"]), - 'BAH': " ".join(["B","A","C"])}) + expected_output={ + 'FOO': ",".join(["test1", "test2", "test3"]), + 'BAH': " ".join(["B", "A", "C"])}) def test_9(self): """Test literal and expandable strings.""" @@ -339,12 +338,12 @@ def _rex2(): self._test(func=_rex, env={}, - expected_actions = [ + expected_actions=[ Setenv('A', 'hello'), Setenv('FOO', '${A}'), Setenv('BAH', '${A}'), Setenv('EEK', '$A')], - expected_output = { + expected_output={ 'A': 'hello', 'FOO': 'hello', 'BAH': 'hello', @@ -352,12 +351,12 @@ def _rex2(): self._test(func=_rex2, env={}, - expected_actions = [ + expected_actions=[ Setenv('BAH', 'omg'), Setenv('FOO', '${BAH}'), Appendenv('FOO', '${BAH}'), Appendenv('FOO', 'like, $SHE said, ${BAH}')], - expected_output = { + expected_output={ 'BAH': 'omg', 'FOO': os.pathsep.join(['omg', '${BAH}', 'like']) + ', $SHE said, omg'}) diff --git a/src/rez/util.py b/src/rez/util.py index f37996fe2..701338360 100644 --- a/src/rez/util.py +++ b/src/rez/util.py @@ -135,8 +135,8 @@ def is_non_string_iterable(arg): iterable_class = collections.abc.Iterable return ( - isinstance(arg, iterable_class) - and not isinstance(arg, six.string_types) + isinstance(arg, iterable_class) and + not isinstance(arg, six.string_types) ) # Copyright 2013-2016 Allan Johns. diff --git a/src/rez/utils/colorize.py b/src/rez/utils/colorize.py index b97cc305f..077901ef9 100644 --- a/src/rez/utils/colorize.py +++ b/src/rez/utils/colorize.py @@ -312,8 +312,10 @@ def emit(self, record): class Printer(object): def __init__(self, buf=sys.stdout): self.buf = buf - self.colorize = (config.get("color_enabled", False) == "force") \ - or stream_is_tty(buf) + self.colorize = ( + config.get("color_enabled", False) == "force" or + stream_is_tty(buf) + ) def __call__(self, msg='', style=None): print(self.get(msg, style), file=self.buf) diff --git a/src/rez/utils/execution.py b/src/rez/utils/execution.py index 53fe540de..03f84259b 100644 --- a/src/rez/utils/execution.py +++ b/src/rez/utils/execution.py @@ -135,9 +135,11 @@ def create_executable_script(filepath, body, program=None, py_script_mode=None): py_script_mode = py_script_mode or config.create_executable_script_mode # https://github.com/nerdvegas/rez/pull/968 - is_forwarding_script_on_windows = (program == "_rez_fwd" - and platform_.name == "windows" - and filepath.lower().endswith(".cmd")) + is_forwarding_script_on_windows = ( + program == "_rez_fwd" and + platform_.name == "windows" and + filepath.lower().endswith(".cmd") + ) if callable(body): from rez.utils.sourcecode import SourceCode @@ -181,8 +183,11 @@ def create_executable_script(filepath, body, program=None, py_script_mode=None): # clean up the files once the test has run. Temporarily we don't bother # setting the permissions, but this will need to change. if os.name == "posix": - os.chmod(current_filepath, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH - | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + os.chmod( + current_filepath, + stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | + stat.S_IXGRP | stat.S_IXOTH + ) return script_filepaths @@ -234,8 +239,8 @@ def create_forwarding_script(filepath, module, func_name, *nargs, **kwargs): """ from rez.utils.platform_ import platform_ - if (platform_.name == "windows" - and os.path.splitext(filepath)[-1].lower() != ".cmd"): + if platform_.name == "windows" and \ + os.path.splitext(filepath)[-1].lower() != ".cmd": filepath += ".cmd" doc = dict( diff --git a/src/rez/utils/formatting.py b/src/rez/utils/formatting.py index 23ea188ba..ef52ab0e2 100644 --- a/src/rez/utils/formatting.py +++ b/src/rez/utils/formatting.py @@ -459,8 +459,10 @@ def positional_number_string(n): # regex used to expand user; set here to avoid recompile on every call EXPANDUSER_RE = re.compile( r'(\A|\s|[{pathseps}])~([{seps}]|[{pathseps}]|\s|\Z)'.format( - seps = re.escape(''.join(set([os.sep + (getattr(os, 'altsep') or os.sep)]))), - pathseps = re.escape(''.join(set([os.pathsep + ';']))))) + seps=re.escape(''.join(set([os.sep + (getattr(os, 'altsep') or os.sep)]))), + pathseps=re.escape(''.join(set([os.pathsep + ';']))) + ) +) def expanduser(path): diff --git a/src/rez/utils/resources.py b/src/rez/utils/resources.py index 95d1238fd..bf19bf081 100644 --- a/src/rez/utils/resources.py +++ b/src/rez/utils/resources.py @@ -271,8 +271,10 @@ def validate_data(self): self.resource.validate_data() def __eq__(self, other): - return (self.__class__ == other.__class__ - and self.resource == other.resource) + return ( + self.__class__ == other.__class__ and + self.resource == other.resource + ) def __str__(self): return "%s(%s)" % (self.__class__.__name__, str(self.resource)) diff --git a/src/rez/utils/sourcecode.py b/src/rez/utils/sourcecode.py index c474d110f..01455f899 100644 --- a/src/rez/utils/sourcecode.py +++ b/src/rez/utils/sourcecode.py @@ -109,7 +109,7 @@ def copy(self): other.func = self.func other.filepath = self.filepath other.eval_as_function = self.eval_as_function - other.package =self.package + other.package = self.package other.funcname = self.funcname other.decorators = self.decorators @@ -165,9 +165,11 @@ def evaluated_code(self): funcname = self.funcname or "_unnamed" code = indent(self.source) - code = ("def %s():\n" % funcname - + code - + "\n_result = %s()" % funcname) + code = ( + "def %s():\n" % funcname + + code + + "\n_result = %s()" % funcname + ) else: code = "if True:\n" + indent(self.source) @@ -266,8 +268,10 @@ def __setstate__(self, state): self.package = None def __eq__(self, other): - return (isinstance(other, SourceCode) - and other.source == self.source) + return ( + isinstance(other, SourceCode) and + other.source == self.source + ) def __ne__(self, other): return not (other == self) diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index 9af2c412c..b9e50ef48 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -136,8 +136,9 @@ def _additional_commands(self, executor): # Ensures that the PATHEXT does not append duplicates. executor.command( '$Env:PATHEXT = ((($Env:PATHEXT + ";{}") -split ";") | Select-Object -Unique) -join ";"'.format( - ";".join(self.settings.additional_pathext) - )) + ";".join(self.settings.additional_pathext) + ) + ) def spawn_shell(self, context_file, From 1ed07cec4e68d9488e1558b02852ba86501cf3c3 Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 30 Mar 2021 16:36:40 +1100 Subject: [PATCH 4/9] workflow fix --- .github/workflows/flake8.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index fc247b15c..e4bd93eef 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -51,4 +51,4 @@ jobs: F401 F841 \ W503 - working-directory: src/rez + working-directory: src From 7b6b088973487e2cd9992431ac2388a2d021f615 Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 30 Mar 2021 16:37:31 +1100 Subject: [PATCH 5/9] workspace rename --- .github/workflows/flake8.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index e4bd93eef..afe48ef88 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -1,4 +1,4 @@ -name: pypi +name: flake8 on: pull_request: paths-ignore: From 922588a80447218e13a19a3cbf733235ecaa2d3f Mon Sep 17 00:00:00 2001 From: ajohns Date: Wed, 31 Mar 2021 14:55:30 +1100 Subject: [PATCH 6/9] more linting; fixed syntax error in flake8 cmd in workflow --- .github/workflows/flake8.yaml | 23 ++++++++----------- src/rez/bind/_pymodule.py | 1 - src/rez/bind/os.py | 6 +++-- src/rez/bind/python.py | 6 ++--- src/rez/cli/_complete_util.py | 10 ++++---- src/rez/cli/context.py | 7 +++--- src/rez/cli/cp.py | 3 +-- src/rez/cli/pip.py | 4 ++-- src/rez/cli/selftest.py | 1 + src/rez/cli/yaml2py.py | 4 ++-- src/rez/config.py | 2 ++ src/rez/package_cache.py | 1 + src/rez/package_resources.py | 2 ++ src/rez/packages.py | 1 + src/rez/rezconfig.py | 5 +++- src/rez/solver.py | 2 +- src/rez/tests/test_formatter.py | 13 +++++++---- src/rez/tests/test_packages.py | 5 ++-- src/rez/tests/test_resources_.py | 2 ++ src/rezplugins/build_process/remote.py | 1 - .../package_repository/filesystem.py | 3 +-- src/rezplugins/package_repository/memory.py | 14 +++++------ src/rezplugins/release_hook/command.py | 6 +++-- src/rezplugins/release_hook/emailer.py | 14 +++++------ src/rezplugins/release_vcs/git.py | 8 +++---- src/rezplugins/release_vcs/hg.py | 6 +++-- src/rezplugins/release_vcs/svn.py | 1 + .../shell/_utils/powershell_base.py | 1 - src/rezplugins/shell/bash.py | 1 - src/rezplugins/shell/cmd.py | 11 +++++---- src/rezplugins/shell/csh.py | 2 +- src/rezplugins/shell/powershell.py | 1 - src/rezplugins/shell/pwsh.py | 1 - src/rezplugins/shell/sh.py | 2 +- src/rezplugins/shell/tcsh.py | 1 - src/rezplugins/shell/zsh.py | 1 - 36 files changed, 95 insertions(+), 77 deletions(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index afe48ef88..a1fd41479 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -38,17 +38,14 @@ jobs: pip install flake8 - name: Run flake8 - run: | - find -name '*.py' \ - -not -path './build_utils/*' \ - -not -path './rez/vendor/*' \ - -not -path './rez/data/*' \ - -not -path './support/*' \ - -not -path './rez/backport/*' \ - -not -path './rezgui/*' \ - | xargs flake8 --select \ - E122 E127 E225 E251 E305 E711 \ - F401 F841 \ - W503 - + run: >- + find -name '*.py' + -not -path './build_utils/*' + -not -path './rez/vendor/*' + -not -path './rez/data/*' + -not -path './support/*' + -not -path './rez/backport/*' + -not -path './rezgui/*' + | xargs flake8 --ignore + E241,E265,E266,E741,E742,E722,F821 working-directory: src diff --git a/src/rez/bind/_pymodule.py b/src/rez/bind/_pymodule.py index b3af38de3..edddb69f0 100644 --- a/src/rez/bind/_pymodule.py +++ b/src/rez/bind/_pymodule.py @@ -13,7 +13,6 @@ from rez.exceptions import RezBindError from rez.system import system from rez.utils.logging_ import print_warning -import subprocess import shutil import sys import os.path diff --git a/src/rez/bind/os.py b/src/rez/bind/os.py index 8ddb98ecc..53b390f87 100644 --- a/src/rez/bind/os.py +++ b/src/rez/bind/os.py @@ -14,8 +14,10 @@ def bind(path, version_range=None, opts=None, parser=None): with make_package("os", path) as pkg: pkg.version = version - pkg.requires = ["platform-%s" % system.platform, - "arch-%s" % system.arch] + pkg.requires = [ + "platform-%s" % system.platform, + "arch-%s" % system.arch + ] return pkg.installed_variants diff --git a/src/rez/bind/python.py b/src/rez/bind/python.py index b2107f941..b6bc776b8 100644 --- a/src/rez/bind/python.py +++ b/src/rez/bind/python.py @@ -8,7 +8,6 @@ from rez.system import system from rez.utils.lint_helper import env from rez.utils.platform_ import platform_ -from rez.vendor.version.version import Version import shutil import os.path @@ -26,9 +25,10 @@ def commands(): def post_commands(): # these are the builtin modules for this python executable. If we don't # include these, some python behavior can be incorrect. - import os, os.path + import os + import os.path - path = os.path.join(this.root, "python") + path = os.path.join(this.root, "python") # noqa for dirname in os.listdir(path): path_ = os.path.join(path, dirname) env.PYTHONPATH.append(path_) diff --git a/src/rez/cli/_complete_util.py b/src/rez/cli/_complete_util.py index 9f2ba7d6b..b70eb0d2d 100644 --- a/src/rez/cli/_complete_util.py +++ b/src/rez/cli/_complete_util.py @@ -12,7 +12,7 @@ def __init__(self, parser, comp_line, comp_point): self.exclude = None self.validator = default_validator self.wordbreaks = " \t\"'@><=;|&(:" # TODO: might need to be configurable/OS specific - + if USING_PYTHON2: comp_line = comp_line.decode(sys_encoding) comp_point = len(comp_line[:comp_point].decode(sys_encoding)) @@ -22,9 +22,11 @@ def __init__(self, parser, comp_line, comp_point): cword_prequote, cword_prefix, cword_suffix, comp_words, \ first_colon_pos = split_line(comp_line, comp_point) - debug("\nLINE: '{l}'\nPREQUOTE: '{pq}'\nPREFIX: '{p}'".format(l=comp_line, pq=cword_prequote, p=cword_prefix), - "\nSUFFIX: '{s}'".format(s=cword_suffix), - "\nWORDS:", comp_words) + debug( + "\nLINE: '{l}'\nPREQUOTE: '{pq}'\nPREFIX: '{p}'".format(l=comp_line, pq=cword_prequote, p=cword_prefix), + "\nSUFFIX: '{s}'".format(s=cword_suffix), + "\nWORDS:", comp_words + ) completions = self._get_completions(comp_words, cword_prefix, cword_prequote, first_colon_pos) diff --git a/src/rez/cli/context.py b/src/rez/cli/context.py index fa8dd7276..c2c2d29ef 100644 --- a/src/rez/cli/context.py +++ b/src/rez/cli/context.py @@ -12,14 +12,15 @@ # disable them in this tool. # import os +import json +import sys + os.environ.update({ "REZ_CONTEXT_TRACKING_HOST": '', "REZ_WRITE_PACKAGE_CACHE": "False" }) -import json -import sys -from rez.rex import OutputStyle +from rez.rex import OutputStyle # noqa def setup_parser(parser, completions=False): diff --git a/src/rez/cli/cp.py b/src/rez/cli/cp.py index 7eaaeec98..05c323bbf 100644 --- a/src/rez/cli/cp.py +++ b/src/rez/cli/cp.py @@ -51,8 +51,7 @@ def setup_parser(parser, completions=False): help="select variants to copy (zero-indexed).") parser.add_argument( "--variant-uri", metavar="URI", - help="copy variant with the given URI. Ignores --variants." - ) + help="copy variant with the given URI. Ignores --variants.") pkg_action = parser.add_argument( "PKG", nargs='?', help="package to copy") diff --git a/src/rez/cli/pip.py b/src/rez/cli/pip.py index 040b6bc6b..19802853e 100644 --- a/src/rez/cli/pip.py +++ b/src/rez/cli/pip.py @@ -27,8 +27,8 @@ def setup_parser(parser, completions=False): help="install as released package; if not set, package is installed " "locally only") parser.add_argument( - "-p", "--prefix", type=str, metavar='PATH', - help="install to a custom package repository path.") + "-p", "--prefix", type=str, metavar='PATH', + help="install to a custom package repository path.") parser.add_argument( "PACKAGE", help="package to install or archive/url to install from") diff --git a/src/rez/cli/selftest.py b/src/rez/cli/selftest.py index 895ce601b..01bcb35d6 100644 --- a/src/rez/cli/selftest.py +++ b/src/rez/cli/selftest.py @@ -13,6 +13,7 @@ all_module_tests = [] + def setup_parser(parser, completions=False): parser.add_argument( "tests", metavar="NAMED_TEST", default=[], nargs="*", diff --git a/src/rez/cli/yaml2py.py b/src/rez/cli/yaml2py.py index 79154c259..f1b0d1c03 100644 --- a/src/rez/cli/yaml2py.py +++ b/src/rez/cli/yaml2py.py @@ -5,10 +5,10 @@ def setup_parser(parser, completions=False): - PKG_action = parser.add_argument( + parser.add_argument( "PATH", type=str, nargs='?', help="path to yaml to convert, or directory to search for package.yaml;" - " cwd if not provided") + " cwd if not provided") def command(opts, parser, extra_arg_groups=None): diff --git a/src/rez/config.py b/src/rez/config.py index 5081be930..fe856aa1d 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -122,6 +122,7 @@ def _parse_env_var(self, value): value = value.replace(self.sep, ' ').split() return [x for x in value if x] + class PipInstallRemaps(Setting): """Ordered, pip install remappings.""" PARDIR, SEP = map(re.escape, (os.pardir, os.sep)) @@ -143,6 +144,7 @@ def validate(self, data): for remap in super(PipInstallRemaps, self).validate(data) ] + class OptionalStrList(StrList): schema = Or(And(None, Use(lambda x: [])), [basestring]) diff --git a/src/rez/package_cache.py b/src/rez/package_cache.py index 0e750a5cb..3747fd39b 100644 --- a/src/rez/package_cache.py +++ b/src/rez/package_cache.py @@ -276,6 +276,7 @@ def add_variant(self, variant, force=False): # copies, and report them as VARIANT_COPY_STALLED status. # still_copying = True + def _while_copying(): while still_copying: time.sleep(self._COPYING_TIME_INC) diff --git a/src/rez/package_resources.py b/src/rez/package_resources.py index 004a310b5..ec24112d1 100644 --- a/src/rez/package_resources.py +++ b/src/rez/package_resources.py @@ -434,9 +434,11 @@ def _convert_to_rex(self, commands): else: return commands + class _Metas(AttributeForwardMeta, LazyAttributeMeta): pass + class VariantResourceHelper(six.with_metaclass(_Metas, VariantResource)): """Helper class for implementing variants that inherit properties from their parent package. diff --git a/src/rez/packages.py b/src/rez/packages.py index 190eac988..132e7ebbc 100644 --- a/src/rez/packages.py +++ b/src/rez/packages.py @@ -26,6 +26,7 @@ # package-related classes # ------------------------------------------------------------------------------ + class PackageRepositoryResourceWrapper(ResourceWrapper, StringFormatMixin): format_expand = StringFormatType.unchanged diff --git a/src/rez/rezconfig.py b/src/rez/rezconfig.py index ad82bcd0a..0fd999828 100644 --- a/src/rez/rezconfig.py +++ b/src/rez/rezconfig.py @@ -1,4 +1,4 @@ -r""" +""" Rez configuration settings. Do not change this file. Settings are determined in the following way (higher number means higher @@ -38,6 +38,9 @@ Note: The comments in this file are extracted and turned into Wiki content. Pay attention to the comment formatting and follow the existing style closely. """ + +# flake8: noqa + import os diff --git a/src/rez/solver.py b/src/rez/solver.py index d0b355906..c308689ff 100644 --- a/src/rez/solver.py +++ b/src/rez/solver.py @@ -2390,7 +2390,7 @@ def _depth_label(self, depth=None): if depth is None: depth = len(self.phase_stack) - 1 count = self.depth_counts[depth] - return "{%d,%d}" % (depth,count) + return "{%d,%d}" % (depth, count) def __str__(self): return "%s %s %s" % (self.status, diff --git a/src/rez/tests/test_formatter.py b/src/rez/tests/test_formatter.py index d14da1717..92dc3e8f6 100644 --- a/src/rez/tests/test_formatter.py +++ b/src/rez/tests/test_formatter.py @@ -52,12 +52,14 @@ def test_formatter_stdlib(self): class C(object): def __init__(self, x=100): self._x = x + def __format__(self, spec): return spec class D(object): def __init__(self, x): self.x = x + def __format__(self, spec): return str(self.x) @@ -65,6 +67,7 @@ def __format__(self, spec): class E(object): def __init__(self, x): self.x = x + def __str__(self): return 'E(' + self.x + ')' @@ -72,6 +75,7 @@ def __str__(self): class F(object): def __init__(self, x): self.x = x + def __repr__(self): return 'F(' + self.x + ')' @@ -79,8 +83,10 @@ def __repr__(self): class G(object): def __init__(self, x): self.x = x + def __str__(self): return "string is " + self.x + def __format__(self, format_spec): if format_spec == 'd': return 'G(' + self.x + ')' @@ -123,9 +129,9 @@ def __format__(self, format_spec): self.assert_formatter_equal('}}x{{', '}x{') # weird field names - self.assert_formatter_equal("{0[foo-bar]}", 'baz', {'foo-bar':'baz'}) - self.assert_formatter_equal("{0[foo bar]}", 'baz', {'foo bar':'baz'}) - self.assert_formatter_equal("{0[ ]}", '3', {' ':3}) + self.assert_formatter_equal("{0[foo-bar]}", 'baz', {'foo-bar': 'baz'}) + self.assert_formatter_equal("{0[foo bar]}", 'baz', {'foo bar': 'baz'}) + self.assert_formatter_equal("{0[ ]}", '3', {' ': 3}) self.assert_formatter_equal('{foo._x}', '20', foo=C(20)) self.assert_formatter_equal('{1}{0}', '2010', D(10), D(20)) @@ -287,7 +293,6 @@ def test_formatter_recurse(self): 'Hello Timmy the Trex!') - if __name__ == '__main__': unittest.main() diff --git a/src/rez/tests/test_packages.py b/src/rez/tests/test_packages.py index a191a6393..374fcaba7 100644 --- a/src/rez/tests/test_packages.py +++ b/src/rez/tests/test_packages.py @@ -130,8 +130,9 @@ def test_3(self): # a yaml-based package package = get_package("versioned", "2.0") - expected_uri = canonical_path(os.path.join(self.yaml_packages_path, - "versioned", "2.0", "package.yaml")) + expected_uri = canonical_path( + os.path.join(self.yaml_packages_path, "versioned", "2.0", "package.yaml") + ) self.assertEqual(package.uri, expected_uri) # a py-based package with late binding attribute functions diff --git a/src/rez/tests/test_resources_.py b/src/rez/tests/test_resources_.py index 9ab28b3eb..ee706fed3 100644 --- a/src/rez/tests/test_resources_.py +++ b/src/rez/tests/test_resources_.py @@ -88,6 +88,7 @@ class KittenResource(PetResource): class PuppyResource(PetResource): key = "puppy" + class PetPool(ResourcePool): # don't want to define get_resource on normal pool object anymore, # because it's dangerous, since we always want ResourceHandle creation to @@ -98,6 +99,7 @@ def get_resource(self, resource_key, variables=None): handle = ResourceHandle(resource_key, variables) return self.get_resource_from_handle(handle) + class PetRepository(PackageRepository): def __init__(self, pool): self.pool = pool diff --git a/src/rezplugins/build_process/remote.py b/src/rezplugins/build_process/remote.py index f459e04c3..adcb7b2d3 100644 --- a/src/rezplugins/build_process/remote.py +++ b/src/rezplugins/build_process/remote.py @@ -2,7 +2,6 @@ Builds packages on remote hosts """ from rez.build_process import BuildProcessHelper -from rez.exceptions import BuildError class RemoteBuildProcess(BuildProcessHelper): diff --git a/src/rezplugins/package_repository/filesystem.py b/src/rezplugins/package_repository/filesystem.py index bf3871097..98641fbe8 100644 --- a/src/rezplugins/package_repository/filesystem.py +++ b/src/rezplugins/package_repository/filesystem.py @@ -1248,8 +1248,7 @@ def _remove_build_keys(obj): package_data["format_version"] = format_version # Stop if package is unversioned and config does not allow that - if (not package_data["version"] - and not config.allow_unversioned_packages): + if not package_data["version"] and not config.allow_unversioned_packages: raise PackageMetadataError("Unversioned package is not allowed " "in current configuration.") diff --git a/src/rezplugins/package_repository/memory.py b/src/rezplugins/package_repository/memory.py index 080f2748c..4a18ce1ce 100644 --- a/src/rezplugins/package_repository/memory.py +++ b/src/rezplugins/package_repository/memory.py @@ -2,11 +2,10 @@ In-memory package repository """ from rez.package_repository import PackageRepository -from rez.package_resources import PackageFamilyResource, PackageResource, \ - VariantResourceHelper, PackageResourceHelper, package_pod_schema -from rez.exceptions import PackageMetadataError -from rez.utils.formatting import is_valid_package_name, PackageRequest -from rez.utils.resources import ResourceHandle, ResourcePool, cached_property +from rez.package_resources import PackageFamilyResource, VariantResourceHelper, \ + PackageResourceHelper, package_pod_schema +from rez.utils.formatting import is_valid_package_name +from rez.utils.resources import ResourcePool, cached_property from rez.vendor.version.requirement import VersionedObject @@ -91,8 +90,9 @@ def parent(self): package = self._repository.get_resource( MemoryPackageResource.key, location=self.location, - name=self.name, - version=self.get("version")) + name=self.name, + version=self.get("version") + ) return package diff --git a/src/rezplugins/release_hook/command.py b/src/rezplugins/release_hook/command.py index f62e49f9f..af667e4cf 100644 --- a/src/rezplugins/release_hook/command.py +++ b/src/rezplugins/release_hook/command.py @@ -133,8 +133,10 @@ def post_release(self, user, install_path, variants, **kwargs): errors=errors, variants=variants) if errors: - print_debug("The following post-release commands failed:\n" - + '\n\n'.join(errors)) + print_debug( + "The following post-release commands failed:\n" + + '\n\n'.join(errors) + ) def _execute_commands(self, commands, install_path, package, errors=None, variants=None): diff --git a/src/rezplugins/release_hook/emailer.py b/src/rezplugins/release_hook/emailer.py index 3dacc0dc9..bd669e7c1 100644 --- a/src/rezplugins/release_hook/emailer.py +++ b/src/rezplugins/release_hook/emailer.py @@ -13,7 +13,6 @@ from rez.vendor.six import six import os.path import smtplib -import sys basestring = six.string_types[0] @@ -22,12 +21,13 @@ class EmailReleaseHook(ReleaseHook): schema_dict = { - "subject": basestring, - "body": basestring, - "smtp_host": basestring, - "smtp_port": int, - "sender": basestring, - "recipients": Or(basestring, [basestring])} + "subject": basestring, + "body": basestring, + "smtp_host": basestring, + "smtp_port": int, + "sender": basestring, + "recipients": Or(basestring, [basestring]) + } @classmethod def name(cls): diff --git a/src/rezplugins/release_vcs/git.py b/src/rezplugins/release_vcs/git.py index ccbb9e85f..3d86b698f 100644 --- a/src/rezplugins/release_vcs/git.py +++ b/src/rezplugins/release_vcs/git.py @@ -4,7 +4,7 @@ from __future__ import print_function from rez.release_vcs import ReleaseVCS -from rez.utils.logging_ import print_error, print_warning, print_debug +from rez.utils.logging_ import print_error, print_debug from rez.exceptions import ReleaseVCSError from shutil import rmtree import functools @@ -82,9 +82,9 @@ def get_tracking_branch(self): # capitalization of message changed sometime between git 1.8.3 # and 2.12 - used to be "No upstream", now "no upstream".. errmsg = str(e).lower() - if ("no upstream branch" not in errmsg - and "no upstream configured" not in errmsg - and "does not point to a branch" not in errmsg): + if "no upstream branch" not in errmsg and \ + "no upstream configured" not in errmsg and \ + "does not point to a branch" not in errmsg: raise e return (None, None) diff --git a/src/rezplugins/release_vcs/hg.py b/src/rezplugins/release_vcs/hg.py index 7f6ece969..3ef681552 100644 --- a/src/rezplugins/release_vcs/hg.py +++ b/src/rezplugins/release_vcs/hg.py @@ -49,9 +49,11 @@ def search_parents_for_root(cls): def hg(self, *nargs, **kwargs): if kwargs.pop('patch', False): nargs += ('--mq',) - if ('-R' not in nargs and '--repository' not in nargs - and not any(x.startswith(('-R', '--repository=')) for x in nargs)): + if '-R' not in nargs and \ + '--repository' not in nargs and \ + not any(x.startswith(('-R', '--repository=')) for x in nargs): nargs += ('--repository', self.vcs_root) + if kwargs: raise HgReleaseVCSError("Unrecognized keyword args to hg command:" " %s" % ", ".join(kwargs)) diff --git a/src/rezplugins/release_vcs/svn.py b/src/rezplugins/release_vcs/svn.py index 59c3cfac8..3759b7823 100644 --- a/src/rezplugins/release_vcs/svn.py +++ b/src/rezplugins/release_vcs/svn.py @@ -132,6 +132,7 @@ def create_release_tag(self, tag_name, message=None): self.svnc.callback_get_log_message = lambda: (True, message) self.svnc.copy(self.pkg_root, self.get_tag_url(tag_name)) + def register_plugin(): return SvnReleaseVCS diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index b9e50ef48..45c4b336c 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -2,7 +2,6 @@ import re from subprocess import PIPE, list2cmdline -from rez.backport.shutilwhich import which from rez.config import config from rez.rex import RexExecutor, OutputStyle, EscapedString from rez.shells import Shell diff --git a/src/rezplugins/shell/bash.py b/src/rezplugins/shell/bash.py index aeaad342e..d6b89a20b 100644 --- a/src/rezplugins/shell/bash.py +++ b/src/rezplugins/shell/bash.py @@ -3,7 +3,6 @@ """ import os import os.path -from rez.shells import Shell from rez.utils.platform_ import platform_ from rezplugins.shell.sh import SH from rez import module_root_path diff --git a/src/rezplugins/shell/cmd.py b/src/rezplugins/shell/cmd.py index 9354b4562..d33fba288 100644 --- a/src/rezplugins/shell/cmd.py +++ b/src/rezplugins/shell/cmd.py @@ -2,7 +2,7 @@ Windows Command Prompt (DOS) shell. """ from rez.config import config -from rez.rex import RexExecutor, expandable, literal, OutputStyle, EscapedString +from rez.rex import RexExecutor, expandable, OutputStyle, EscapedString from rez.shells import Shell from rez.system import system from rez.utils.execution import Popen @@ -192,10 +192,13 @@ def _create_ex(): # Make .py launch within cmd without extension. if self.settings.additional_pathext: # Ensure that the PATHEXT does not append duplicates. + fmt = ( + 'echo %PATHEXT%|C:\\Windows\\System32\\findstr.exe /i /c:"{0}">nul ' + '|| set PATHEXT=%PATHEXT%;{0}' + ) + for pathext in self.settings.additional_pathext: - executor.command('echo %PATHEXT%|C:\\Windows\\System32\\findstr.exe /i /c:"{0}">nul || set PATHEXT=%PATHEXT%;{0}'.format( - pathext - )) + executor.command(fmt.format(pathext)) # This resets the errorcode, which is tainted by the code above executor.command("(call )") diff --git a/src/rezplugins/shell/csh.py b/src/rezplugins/shell/csh.py index a2077e814..a6524476d 100644 --- a/src/rezplugins/shell/csh.py +++ b/src/rezplugins/shell/csh.py @@ -7,7 +7,7 @@ from rez.config import config from rez.utils.execution import Popen from rez.utils.platform_ import platform_ -from rez.shells import Shell, UnixShell +from rez.shells import UnixShell from rez.rex import EscapedString diff --git a/src/rezplugins/shell/powershell.py b/src/rezplugins/shell/powershell.py index 906a1d8ac..5430df75c 100644 --- a/src/rezplugins/shell/powershell.py +++ b/src/rezplugins/shell/powershell.py @@ -1,6 +1,5 @@ """Windows PowerShell 5""" -from rez.shells import Shell from rez.utils.platform_ import platform_ from ._utils.powershell_base import PowerShellBase diff --git a/src/rezplugins/shell/pwsh.py b/src/rezplugins/shell/pwsh.py index fb6e37a34..1181dff6f 100644 --- a/src/rezplugins/shell/pwsh.py +++ b/src/rezplugins/shell/pwsh.py @@ -1,6 +1,5 @@ """PowerShell Core 6+""" -from rez.shells import Shell from rez.utils.platform_ import platform_ from ._utils.powershell_base import PowerShellBase diff --git a/src/rezplugins/shell/sh.py b/src/rezplugins/shell/sh.py index 4c0bef712..c5cbe8796 100644 --- a/src/rezplugins/shell/sh.py +++ b/src/rezplugins/shell/sh.py @@ -8,7 +8,7 @@ from rez.config import config from rez.utils.execution import Popen from rez.utils.platform_ import platform_ -from rez.shells import Shell, UnixShell +from rez.shells import UnixShell from rez.rex import EscapedString diff --git a/src/rezplugins/shell/tcsh.py b/src/rezplugins/shell/tcsh.py index ae6be500c..aaf6fbfb6 100644 --- a/src/rezplugins/shell/tcsh.py +++ b/src/rezplugins/shell/tcsh.py @@ -1,7 +1,6 @@ """ TCSH shell """ -from rez.shells import Shell from rez.utils.platform_ import platform_ from rezplugins.shell.csh import CSH from rez import module_root_path diff --git a/src/rezplugins/shell/zsh.py b/src/rezplugins/shell/zsh.py index d921499b4..4f489684a 100644 --- a/src/rezplugins/shell/zsh.py +++ b/src/rezplugins/shell/zsh.py @@ -3,7 +3,6 @@ """ import os import os.path -from rez.shells import Shell from rez.utils.platform_ import platform_ from rezplugins.shell.sh import SH from rez import module_root_path From 420c5cd7369e57b5d59e6cad63cbba426ceb5cbb Mon Sep 17 00:00:00 2001 From: ajohns Date: Wed, 31 Mar 2021 15:29:40 +1100 Subject: [PATCH 7/9] lint fixes, newer flake8 version --- .github/workflows/flake8.yaml | 2 +- src/rez/cli/complete.py | 2 +- src/rez/package_copy.py | 262 +++++++++++++++--------------- src/rez/rex.py | 2 +- src/rez/system.py | 2 +- src/rez/utils/formatting.py | 8 +- src/rez/utils/platform_.py | 2 +- src/rez/utils/platform_mapped.py | 2 +- src/rezplugins/release_vcs/git.py | 2 +- 9 files changed, 142 insertions(+), 142 deletions(-) diff --git a/.github/workflows/flake8.yaml b/.github/workflows/flake8.yaml index a1fd41479..d409e194b 100644 --- a/.github/workflows/flake8.yaml +++ b/.github/workflows/flake8.yaml @@ -47,5 +47,5 @@ jobs: -not -path './rez/backport/*' -not -path './rezgui/*' | xargs flake8 --ignore - E241,E265,E266,E741,E742,E722,F821 + E241,E265,E266,E741,E742,E722,F821,W503 working-directory: src diff --git a/src/rez/cli/complete.py b/src/rez/cli/complete.py index 90b369da3..521fe2570 100644 --- a/src/rez/cli/complete.py +++ b/src/rez/cli/complete.py @@ -66,7 +66,7 @@ def _pop_arg(l, p): # replace '--' with special '--N#' flag so that subcommands can specify # custom completions. - regex = re.compile("\s--\s") + regex = re.compile(r"\s--\s") ddashes = regex.findall(comp_line) for i, ddash in enumerate(ddashes): j = comp_line.find(ddash) diff --git a/src/rez/package_copy.py b/src/rez/package_copy.py index e020c3af2..c0dd1a5b5 100644 --- a/src/rez/package_copy.py +++ b/src/rez/package_copy.py @@ -222,159 +222,159 @@ def finalize(): def _copy_variant_payload(src_variant, dest_pkg_repo, shallow=False, follow_symlinks=False, overrides=None, verbose=False): - # Get payload path of source variant. For some types (eg from a "memory" - # type repo) there may not be a root. - # - variant_root = getattr(src_variant, "root", None) - - if not variant_root: - raise PackageCopyError( - "Cannot copy source variant %s - it is a type of variant that " - "does not have a root." % src_variant.uri - ) - - if not os.path.isdir(variant_root): - raise PackageCopyError( - "Cannot copy source variant %s - its root does not appear to " - "be present on disk (%s)." % src_variant.uri, variant_root - ) + # Get payload path of source variant. For some types (eg from a "memory" + # type repo) there may not be a root. + # + variant_root = getattr(src_variant, "root", None) - dest_variant_name = overrides.get("name") or src_variant.name - dest_variant_version = overrides.get("version") or src_variant.version + if not variant_root: + raise PackageCopyError( + "Cannot copy source variant %s - it is a type of variant that " + "does not have a root." % src_variant.uri + ) - # determine variant installation path - dest_pkg_payload_path = dest_pkg_repo.get_package_payload_path( - package_name=dest_variant_name, - package_version=dest_variant_version + if not os.path.isdir(variant_root): + raise PackageCopyError( + "Cannot copy source variant %s - its root does not appear to " + "be present on disk (%s)." % src_variant.uri, variant_root ) - is_varianted = (src_variant.index is not None) - src_variant_subpath = None + dest_variant_name = overrides.get("name") or src_variant.name + dest_variant_version = overrides.get("version") or src_variant.version - if is_varianted: - src_variant_subpath = src_variant._non_shortlinked_subpath + # determine variant installation path + dest_pkg_payload_path = dest_pkg_repo.get_package_payload_path( + package_name=dest_variant_name, + package_version=dest_variant_version + ) - variant_install_path = os.path.join( - dest_pkg_payload_path, src_variant_subpath) - else: - variant_install_path = dest_pkg_payload_path + is_varianted = (src_variant.index is not None) + src_variant_subpath = None - # get ready for copy/symlinking - copy_func = partial(replacing_copy, - follow_symlinks=follow_symlinks) + if is_varianted: + src_variant_subpath = src_variant._non_shortlinked_subpath - if shallow: - maybe_symlink = replacing_symlink - else: - maybe_symlink = copy_func + variant_install_path = os.path.join( + dest_pkg_payload_path, src_variant_subpath) + else: + variant_install_path = dest_pkg_payload_path + + # get ready for copy/symlinking + copy_func = partial(replacing_copy, + follow_symlinks=follow_symlinks) + + if shallow: + maybe_symlink = replacing_symlink + else: + maybe_symlink = copy_func - # possibly make install path temporarily writable - last_dir = get_existing_path( - variant_install_path, - topmost_path=os.path.dirname(dest_pkg_payload_path)) + # possibly make install path temporarily writable + last_dir = get_existing_path( + variant_install_path, + topmost_path=os.path.dirname(dest_pkg_payload_path)) - if last_dir: - ctxt = make_path_writable(last_dir) + if last_dir: + ctxt = make_path_writable(last_dir) + else: + ctxt = with_noop() + + # copy the variant payload + with ctxt: + safe_makedirs(variant_install_path) + + # determine files not to copy + skip_files = [] + + if is_varianted and not src_variant.parent.hashed_variants: + # Detect overlapped variants. This is the case where one variant subpath + # might be A, and another is A/B. We must ensure that A/B is not created + # as a symlink during shallow install of variant A - that would then + # cause A/B payload to be installed back into original package, possibly + # corrupting it. + # + # Here we detect this case, and create a list of dirs not to copy/link, + # because they are in fact a subpath dir for another variant. + # + # Note that for hashed variants, we don't do this check because overlapped + # variants are not possible. + # + skip_files.extend(_get_overlapped_variant_dirs(src_variant)) else: - ctxt = with_noop() + # just skip package definition file + for name in config.plugins.package_repository.filesystem.package_filenames: + for fmt in (FileFormat.py, FileFormat.yaml): + filename = name + '.' + fmt.extension + skip_files.append(filename) - # copy the variant payload - with ctxt: - safe_makedirs(variant_install_path) + # copy/link all topmost files within the variant root + for name in os.listdir(variant_root): + if name in skip_files: + filepath = os.path.join(variant_root, name) - # determine files not to copy - skip_files = [] + if verbose: + if is_varianted: + msg = ("Did not copy %s - this is part of an " + "overlapping variant's root path.") + else: + msg = "Did not copy package definition file %s" - if is_varianted and not src_variant.parent.hashed_variants: - # Detect overlapped variants. This is the case where one variant subpath - # might be A, and another is A/B. We must ensure that A/B is not created - # as a symlink during shallow install of variant A - that would then - # cause A/B payload to be installed back into original package, possibly - # corrupting it. - # - # Here we detect this case, and create a list of dirs not to copy/link, - # because they are in fact a subpath dir for another variant. - # - # Note that for hashed variants, we don't do this check because overlapped - # variants are not possible. - # - skip_files.extend(_get_overlapped_variant_dirs(src_variant)) + print_info(msg, filepath) + + continue + + src_path = os.path.join(variant_root, name) + dest_path = os.path.join(variant_install_path, name) + + if os.path.islink(src_path): + copy_func(src_path, dest_path) else: - # just skip package definition file - for name in config.plugins.package_repository.filesystem.package_filenames: - for fmt in (FileFormat.py, FileFormat.yaml): - filename = name + '.' + fmt.extension - skip_files.append(filename) - - # copy/link all topmost files within the variant root - for name in os.listdir(variant_root): - if name in skip_files: - filepath = os.path.join(variant_root, name) - - if verbose: - if is_varianted: - msg = ("Did not copy %s - this is part of an " - "overlapping variant's root path.") - else: - msg = "Did not copy package definition file %s" - - print_info(msg, filepath) - - continue - - src_path = os.path.join(variant_root, name) - dest_path = os.path.join(variant_install_path, name) - - if os.path.islink(src_path): - copy_func(src_path, dest_path) - else: - maybe_symlink(src_path, dest_path) - - # copy permissions of source variant dirs onto dest - src_package = src_variant.parent - src_pkg_repo = src_package.repository - - src_pkg_payload_path = src_pkg_repo.get_package_payload_path( - package_name=src_package.name, - package_version=src_package.version - ) + maybe_symlink(src_path, dest_path) - shutil.copystat(src_pkg_payload_path, dest_pkg_payload_path) + # copy permissions of source variant dirs onto dest + src_package = src_variant.parent + src_pkg_repo = src_package.repository - subpath = src_variant_subpath + src_pkg_payload_path = src_pkg_repo.get_package_payload_path( + package_name=src_package.name, + package_version=src_package.version + ) - while subpath: - src_path = os.path.join(src_pkg_payload_path, subpath) - dest_path = os.path.join(dest_pkg_payload_path, subpath) - shutil.copystat(src_path, dest_path) - subpath = os.path.dirname(subpath) + shutil.copystat(src_pkg_payload_path, dest_pkg_payload_path) - # create the variant shortlink - if src_variant.parent.hashed_variants: - try: - # base _v dir - base_shortlinks_path = os.path.join( - dest_pkg_payload_path, - src_package.config.variant_shortlinks_dirname - ) + subpath = src_variant_subpath - safe_makedirs(base_shortlinks_path) + while subpath: + src_path = os.path.join(src_pkg_payload_path, subpath) + dest_path = os.path.join(dest_pkg_payload_path, subpath) + shutil.copystat(src_path, dest_path) + subpath = os.path.dirname(subpath) - # shortlink - rel_variant_path = os.path.relpath( - variant_install_path, base_shortlinks_path) - create_unique_base26_symlink( - base_shortlinks_path, rel_variant_path) + # create the variant shortlink + if src_variant.parent.hashed_variants: + try: + # base _v dir + base_shortlinks_path = os.path.join( + dest_pkg_payload_path, + src_package.config.variant_shortlinks_dirname + ) - except Exception as e: - # Treat any error as warning - lack of shortlink is not - # a breaking issue, it just means the variant root path - # will be long. - # - print_warning( - "Error creating variant shortlink for %s: %s: %s", - variant_install_path, e.__class__.__name__, e - ) + safe_makedirs(base_shortlinks_path) + + # shortlink + rel_variant_path = os.path.relpath( + variant_install_path, base_shortlinks_path) + create_unique_base26_symlink( + base_shortlinks_path, rel_variant_path) + + except Exception as e: + # Treat any error as warning - lack of shortlink is not + # a breaking issue, it just means the variant root path + # will be long. + # + print_warning( + "Error creating variant shortlink for %s: %s: %s", + variant_install_path, e.__class__.__name__, e + ) def _get_overlapped_variant_dirs(src_variant): diff --git a/src/rez/rex.py b/src/rez/rex.py index 5fe48402e..091d84b14 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -708,7 +708,7 @@ def adjust_env_for_platform(self, env): self._add_systemroot_to_env_win32(env) def _add_systemroot_to_env_win32(self, env): - """ Sets ``%SYSTEMROOT%`` environment variable, if not present + r""" Sets ``%SYSTEMROOT%`` environment variable, if not present in :py:attr:`target_environ` . Args: diff --git a/src/rez/system.py b/src/rez/system.py index c6c33470f..3bc6b438d 100644 --- a/src/rez/system.py +++ b/src/rez/system.py @@ -283,7 +283,7 @@ def clear_caches(self, hard=False): @classmethod def _make_safe_version_string(cls, s): - sep_regex = re.compile("[\.\-]") + sep_regex = re.compile(r"[\.\-]") char_regex = re.compile("[a-zA-Z0-9_]") s = s.strip('.').strip('-') diff --git a/src/rez/utils/formatting.py b/src/rez/utils/formatting.py index ef52ab0e2..c920d4cbe 100644 --- a/src/rez/utils/formatting.py +++ b/src/rez/utils/formatting.py @@ -15,7 +15,7 @@ import time -PACKAGE_NAME_REGSTR = "[a-zA-Z_0-9](\.?[a-zA-Z0-9_]+)*" +PACKAGE_NAME_REGSTR = r"[a-zA-Z_0-9](\.?[a-zA-Z0-9_]+)*" PACKAGE_NAME_REGEX = re.compile(r"^%s\Z" % PACKAGE_NAME_REGSTR) ENV_VAR_REGSTR = r'\$(\w+|\{[^}]*\})' @@ -43,8 +43,8 @@ def is_valid_package_name(name, raise_error=False): bool. """ is_valid = ( - PACKAGE_NAME_REGEX.match(name) and - name not in invalid_package_names + PACKAGE_NAME_REGEX.match(name) + and name not in invalid_package_names ) if raise_error and not is_valid: @@ -132,7 +132,7 @@ def get_field(self, field_name, args, kwargs): try: return Formatter.get_field(self, field_name, args, kwargs) except (AttributeError, KeyError, TypeError): - reg = re.compile("[^\.\[]+") + reg = re.compile(r"[^\.\[]+") try: key = reg.match(field_name).group() except: diff --git a/src/rez/utils/platform_.py b/src/rez/utils/platform_.py index eb953ece5..3f35aa50a 100644 --- a/src/rez/utils/platform_.py +++ b/src/rez/utils/platform_.py @@ -326,7 +326,7 @@ def _physical_cores_from_cpuinfo(self): known_ids = set() - proc_re = re.compile('^processor\s*:\s+[0-9]+\s*$', re.MULTILINE) + proc_re = re.compile(r'^processor\s*:\s+[0-9]+\s*$', re.MULTILINE) procsplit = proc_re.split(contents) if len(procsplit) <= 1: diff --git a/src/rez/utils/platform_mapped.py b/src/rez/utils/platform_mapped.py index b63c7b182..e06e78896 100644 --- a/src/rez/utils/platform_mapped.py +++ b/src/rez/utils/platform_mapped.py @@ -2,7 +2,7 @@ def platform_mapped(func): - """Decorates functions for lookups within a config.platform_map dictionary. + r"""Decorates functions for lookups within a config.platform_map dictionary. The first level key is mapped to the func.__name__ of the decorated function. Regular expressions are used on the second level key, values. diff --git a/src/rezplugins/release_vcs/git.py b/src/rezplugins/release_vcs/git.py index 3d86b698f..201d2eb3d 100644 --- a/src/rezplugins/release_vcs/git.py +++ b/src/rezplugins/release_vcs/git.py @@ -51,7 +51,7 @@ def get_relative_to_remote(self): is behind, positive in front, zero means we are matched to remote. """ s = self.git("status", "--short", "-b")[0] - r = re.compile("\[([^\]]+)\]") + r = re.compile(r"\[([^\]]+)\]") toks = r.findall(s) if toks: try: From 379ed86cbab25e3fda94b050df484516ae889be0 Mon Sep 17 00:00:00 2001 From: ajohns Date: Wed, 31 Mar 2021 15:51:01 +1100 Subject: [PATCH 8/9] lint fixes --- src/rez/config.py | 16 ++++--- src/rez/package_cache.py | 8 ++-- src/rez/package_order.py | 20 ++++----- src/rez/package_repository.py | 6 +-- src/rez/package_test.py | 4 +- src/rez/pip.py | 8 ++-- src/rez/resolved_context.py | 16 +++---- src/rez/rex.py | 8 ++-- src/rez/solver.py | 58 +++++++++++++------------- src/rez/suite.py | 4 +- src/rez/tests/test_solver.py | 8 ++-- src/rez/util.py | 4 +- src/rez/utils/colorize.py | 6 +-- src/rez/utils/execution.py | 37 ++++++++-------- src/rez/utils/resources.py | 4 +- src/rez/utils/sourcecode.py | 10 ++--- src/rezplugins/release_hook/command.py | 42 +++++++++++-------- 17 files changed, 136 insertions(+), 123 deletions(-) diff --git a/src/rez/config.py b/src/rez/config.py index fe856aa1d..71007a980 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -558,13 +558,17 @@ def remove_override(self, key): def warn(self, key): """Returns True if the warning setting is enabled.""" - return (not self.quiet and not self.warn_none and - (self.warn_all or getattr(self, "warn_%s" % key))) + return ( + not self.quiet and not self.warn_none + and (self.warn_all or getattr(self, "warn_%s" % key)) + ) def debug(self, key): """Returns True if the debug setting is enabled.""" - return (not self.quiet and not self.debug_none and - (self.debug_all or getattr(self, "debug_%s" % key))) + return ( + not self.quiet and not self.debug_none + and (self.debug_all or getattr(self, "debug_%s" % key)) + ) def debug_printer(self, key): """Returns a printer object suitably enabled based on the given key.""" @@ -636,8 +640,8 @@ def _get_plugin_completions(prefix_): return [] else: keys = ( - [x for x in self._schema_keys if isinstance(x, basestring)] + - ["plugins"] + [x for x in self._schema_keys if isinstance(x, basestring)] + + ["plugins"] ) keys = [x for x in keys if x.startswith(prefix)] if keys == ["plugins"]: diff --git a/src/rez/package_cache.py b/src/rez/package_cache.py index 3747fd39b..f6747ea2d 100644 --- a/src/rez/package_cache.py +++ b/src/rez/package_cache.py @@ -191,8 +191,8 @@ def add_variant(self, variant, force=False): # support device identification. # dev_stat_not_supported = ( - platform.system() == "Windows" and - sys.version_info[:2] < (3, 4) + platform.system() == "Windows" + and sys.version_info[:2] < (3, 4) ) if not config.package_cache_same_device and not dev_stat_not_supported: @@ -612,8 +612,8 @@ def clean(self, time_limit=None): def should_exit(): return ( - time_limit is not None and - (time.time() - now) > time_limit + time_limit is not None + and (time.time() - now) > time_limit ) # find variants to delete diff --git a/src/rez/package_order.py b/src/rez/package_order.py index f481202e8..dffac0841 100644 --- a/src/rez/package_order.py +++ b/src/rez/package_order.py @@ -104,8 +104,8 @@ def __str__(self): def __eq__(self, other): return ( - type(self) == type(other) and - self.descending == other.descending + type(self) == type(other) + and self.descending == other.descending ) def to_pod(self): @@ -162,9 +162,9 @@ def __str__(self): def __eq__(self, other): return ( - type(other) == type(self) and - self.order_dict == other.order_dict and - self.default_order == other.default_order + type(other) == type(self) + and self.order_dict == other.order_dict + and self.default_order == other.default_order ) def to_pod(self): @@ -269,8 +269,8 @@ def __str__(self): def __eq__(self, other): return ( - type(other) == type(self) and - self.first_version == other.first_version + type(other) == type(self) + and self.first_version == other.first_version ) def to_pod(self): @@ -408,9 +408,9 @@ def __str__(self): def __eq__(self, other): return ( - type(other) == type(self) and - self.timestamp == other.timestamp and - self.rank == other.rank + type(other) == type(self) + and self.timestamp == other.timestamp + and self.rank == other.rank ) def to_pod(self): diff --git a/src/rez/package_repository.py b/src/rez/package_repository.py index 53faa0367..d3f3c4755 100644 --- a/src/rez/package_repository.py +++ b/src/rez/package_repository.py @@ -110,9 +110,9 @@ def uid(self): def __eq__(self, other): return ( - isinstance(other, PackageRepository) and - other.name() == self.name() and - other.uid == self.uid + isinstance(other, PackageRepository) + and other.name() == self.name() + and other.uid == self.uid ) def is_empty(self): diff --git a/src/rez/package_test.py b/src/rez/package_test.py index 88d4516d4..9678ba404 100644 --- a/src/rez/package_test.py +++ b/src/rez/package_test.py @@ -563,8 +563,8 @@ def _get_context(self, requires, quiet=False): current_reqs = current_context.get_resolve_as_exact_requests() meets_requirements = ( - RequirementList(current_reqs) == - RequirementList(current_reqs + reqs) + RequirementList(current_reqs) + == RequirementList(current_reqs + reqs) ) if meets_requirements: diff --git a/src/rez/pip.py b/src/rez/pip.py index d742607b3..b0c85814e 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -344,10 +344,10 @@ def log_append_pkg_variants(pkg_maker): # log the pip -> rez requirements translation, for debugging _log( - "Pip to rez requirements translation information for " + - distribution.name_and_version + - ":\n" + - pformat({ + "Pip to rez requirements translation information for " + + distribution.name_and_version + + ":\n" + + pformat({ "pip": { "run_requires": map(str, distribution.run_requires) }, diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index 8a5d271e0..f945524d1 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -405,9 +405,9 @@ def __eq__(self, other): considered. """ return ( - isinstance(other, ResolvedContext) and - other.requested_packages(True) == self.requested_packages(True) and - other.resolved_packages == self.resolved_packages + isinstance(other, ResolvedContext) + and other.requested_packages(True) == self.requested_packages(True) + and other.resolved_packages == self.resolved_packages ) def __hash__(self): @@ -1805,8 +1805,8 @@ def _init_context_tracking_payload_base(cls): # remove fields with unexpanded env-vars, or empty string def _del(value): return ( - isinstance(value, basestring) and - (not value or ENV_VAR_REGEX.search(value)) + isinstance(value, basestring) + and (not value or ENV_VAR_REGEX.search(value)) ) data = deep_del(data, _del) @@ -1826,8 +1826,10 @@ def _track_context(self, context_data, action): data.update(self.context_tracking_payload) # publish message - routing_key = (config.context_tracking_amqp["exchange_routing_key"] + - '.' + action.upper()) + routing_key = ( + config.context_tracking_amqp["exchange_routing_key"] + + '.' + action.upper() + ) try: from rez.utils.amqp import publish_message diff --git a/src/rez/rex.py b/src/rez/rex.py index 091d84b14..592fac9fc 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -279,8 +279,8 @@ def get_output(self, style=OutputStyle.file): def undefined(self, key): _, expanded_key = self._key(key) return ( - expanded_key not in self.environ and - expanded_key not in self.parent_environ + expanded_key not in self.environ + and expanded_key not in self.parent_environ ) def defined(self, key): @@ -822,8 +822,8 @@ def __eq__(self, other): return (str(self) == str(other)) else: return ( - isinstance(other, EscapedString) and - other.strings == self.strings + isinstance(other, EscapedString) + and other.strings == self.strings ) def __ne__(self, other): diff --git a/src/rez/solver.py b/src/rez/solver.py index c308689ff..373ad2fbb 100644 --- a/src/rez/solver.py +++ b/src/rez/solver.py @@ -181,11 +181,11 @@ def involved_requirements(self): return [req, self.dependency, self.conflicting_request] def __eq__(self, other): - return (self.name == other.name and - self.version == other.version and - self.variant_index == other.variant_index and - self.dependency == other.dependency and - self.conflicting_request == other.conflicting_request) + return (self.name == other.name + and self.version == other.version + and self.variant_index == other.variant_index + and self.dependency == other.dependency + and self.conflicting_request == other.conflicting_request) def __str__(self): return "%s (dep(%s) <--!--> %s)" \ @@ -348,16 +348,16 @@ def get(self, pkg_name): def __eq__(self, other): return ( - self.name == other.name and - self.version == other.version and - self.index == other.index + self.name == other.name + and self.version == other.version + and self.index == other.index ) def __lt__(self, other): return ( - self.name < other.name and - self.version < other.version and - self.index < other.index + self.name < other.name + and self.version < other.version + and self.index < other.index ) def __str__(self): @@ -435,8 +435,7 @@ def key(variant): if not request.conflict and request.name not in names: additional_key.append((request.range, request.name)) - if (VariantSelectMode[config.variant_select_mode] == - VariantSelectMode.version_priority): + if (VariantSelectMode[config.variant_select_mode] == VariantSelectMode.version_priority): k = (requested_key, -len(additional_key), additional_key, @@ -876,8 +875,8 @@ def _update_fam_info(self): for variant in self.iter_variants(): self._common_fams &= variant.request_fams - self._fam_requires |= (variant.request_fams | - variant.conflict_request_fams) + self._fam_requires |= (variant.request_fams + | variant.conflict_request_fams) def __len__(self): if self._len is None: @@ -1131,9 +1130,9 @@ def split(self): not applicable to this scope. """ if ( - self.is_conflict or - self.is_ephemeral or - len(self.variant_slice) == 1 + self.is_conflict + or self.is_ephemeral + or len(self.variant_slice) == 1 ): return None @@ -1154,19 +1153,19 @@ def _copy(self, new_slice): def _is_solved(self): return ( - self.is_conflict or - self.is_ephemeral or - ( - len(self.variant_slice) == 1 and - not self.variant_slice.extractable + self.is_conflict + or self.is_ephemeral + or ( + len(self.variant_slice) == 1 + and not self.variant_slice.extractable ) ) def _get_solved_variant(self): if ( - self.variant_slice is not None and - len(self.variant_slice) == 1 and - not self.variant_slice.extractable + self.variant_slice is not None + and len(self.variant_slice) == 1 + and not self.variant_slice.extractable ): return self.variant_slice.first_variant else: @@ -1363,7 +1362,6 @@ def _create_phase(status=None): if new_extracted_reqs: self.pr.subheader("ADDING:") - #n = len(scopes) for req in new_extracted_reqs: try: @@ -1559,9 +1557,9 @@ def split(self): # because a scope was narrowed by a split, other scopes need to be # reduced against it - #for i in range(len(phase.scopes)): - # if i != split_i: - # phase.pending_reducts.add((i, split_i)) + # for i in range(len(phase.scopes)): + # if i != split_i: + # phase.pending_reducts.add((i, split_i)) next_phase = copy.copy(phase) next_phase.scopes = next_scopes diff --git a/src/rez/suite.py b/src/rez/suite.py index 157a3f5a9..ec435994b 100644 --- a/src/rez/suite.py +++ b/src/rez/suite.py @@ -159,8 +159,8 @@ def _in_resolve(name): if variant: overlap = (variant.version in in_resolve.range) return ( - (in_resolve.conflict and not overlap) or - (overlap and not in_resolve.conflict) + (in_resolve.conflict and not overlap) + or (overlap and not in_resolve.conflict) ) else: return in_resolve.conflict diff --git a/src/rez/tests/test_solver.py b/src/rez/tests/test_solver.py index 3f426e0e7..a35a3cf3d 100644 --- a/src/rez/tests/test_solver.py +++ b/src/rez/tests/test_solver.py @@ -54,8 +54,8 @@ def _solve(self, packages, expected_resolve): # ephemeral order doesn't matter, hence the sort resolve = ( - [str(x) for x in s1.resolved_packages] + - sorted(str(x) for x in s1.resolved_ephemerals) + [str(x) for x in s1.resolved_packages] + + sorted(str(x) for x in s1.resolved_ephemerals) ) print() @@ -68,8 +68,8 @@ def _solve(self, packages, expected_resolve): s2.solve() self.assertEqual(s2.status, SolverStatus.solved) resolve2 = ( - [str(x) for x in s2.resolved_packages] + - sorted(str(x) for x in s2.resolved_ephemerals) + [str(x) for x in s2.resolved_packages] + + sorted(str(x) for x in s2.resolved_ephemerals) ) self.assertEqual(resolve2, resolve) diff --git a/src/rez/util.py b/src/rez/util.py index 701338360..f37996fe2 100644 --- a/src/rez/util.py +++ b/src/rez/util.py @@ -135,8 +135,8 @@ def is_non_string_iterable(arg): iterable_class = collections.abc.Iterable return ( - isinstance(arg, iterable_class) and - not isinstance(arg, six.string_types) + isinstance(arg, iterable_class) + and not isinstance(arg, six.string_types) ) # Copyright 2013-2016 Allan Johns. diff --git a/src/rez/utils/colorize.py b/src/rez/utils/colorize.py index 077901ef9..288ecead2 100644 --- a/src/rez/utils/colorize.py +++ b/src/rez/utils/colorize.py @@ -264,7 +264,7 @@ class ColorizedStreamHandler(logging.StreamHandler): 30: warning, 20: info, 10: debug, - 0: notset, + 0: notset, } @property @@ -313,8 +313,8 @@ class Printer(object): def __init__(self, buf=sys.stdout): self.buf = buf self.colorize = ( - config.get("color_enabled", False) == "force" or - stream_is_tty(buf) + config.get("color_enabled", False) == "force" + or stream_is_tty(buf) ) def __call__(self, msg='', style=None): diff --git a/src/rez/utils/execution.py b/src/rez/utils/execution.py index 03f84259b..f173b8834 100644 --- a/src/rez/utils/execution.py +++ b/src/rez/utils/execution.py @@ -136,9 +136,9 @@ def create_executable_script(filepath, body, program=None, py_script_mode=None): # https://github.com/nerdvegas/rez/pull/968 is_forwarding_script_on_windows = ( - program == "_rez_fwd" and - platform_.name == "windows" and - filepath.lower().endswith(".cmd") + program == "_rez_fwd" + and platform_.name == "windows" + and filepath.lower().endswith(".cmd") ) if callable(body): @@ -185,8 +185,8 @@ def create_executable_script(filepath, body, program=None, py_script_mode=None): if os.name == "posix": os.chmod( current_filepath, - stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | - stat.S_IXGRP | stat.S_IXOTH + stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR + | stat.S_IXGRP | stat.S_IXOTH ) return script_filepaths @@ -211,20 +211,23 @@ def _get_python_script_files(filepath, py_script_mode, platform): has_py_ext = extension == ".py" is_windows = platform == "windows" - if py_script_mode == ExecutableScriptMode.single or \ - py_script_mode == ExecutableScriptMode.both or \ - (py_script_mode == ExecutableScriptMode.py and has_py_ext) or \ - (py_script_mode == ExecutableScriptMode.platform_specific and - not is_windows) or \ - (py_script_mode == ExecutableScriptMode.platform_specific and - is_windows and has_py_ext): + if ( + py_script_mode == ExecutableScriptMode.single + or py_script_mode == ExecutableScriptMode.both + or (py_script_mode == ExecutableScriptMode.py and has_py_ext) + or (py_script_mode == ExecutableScriptMode.platform_specific and not is_windows) + or (py_script_mode == ExecutableScriptMode.platform_specific and is_windows and has_py_ext) + ): script_filepaths.append(filepath) - if not has_py_ext and \ - ((py_script_mode == ExecutableScriptMode.both) or - (py_script_mode == ExecutableScriptMode.py) or - (py_script_mode == ExecutableScriptMode.platform_specific and - is_windows)): + if ( + not has_py_ext + and ( + py_script_mode == ExecutableScriptMode.both + or py_script_mode == ExecutableScriptMode.py + or (py_script_mode == ExecutableScriptMode.platform_specific and is_windows) + ) + ): script_filepaths.append(base_filepath + ".py") return script_filepaths diff --git a/src/rez/utils/resources.py b/src/rez/utils/resources.py index bf19bf081..c38376d7a 100644 --- a/src/rez/utils/resources.py +++ b/src/rez/utils/resources.py @@ -272,8 +272,8 @@ def validate_data(self): def __eq__(self, other): return ( - self.__class__ == other.__class__ and - self.resource == other.resource + self.__class__ == other.__class__ + and self.resource == other.resource ) def __str__(self): diff --git a/src/rez/utils/sourcecode.py b/src/rez/utils/sourcecode.py index 01455f899..65b5d06af 100644 --- a/src/rez/utils/sourcecode.py +++ b/src/rez/utils/sourcecode.py @@ -166,9 +166,9 @@ def evaluated_code(self): code = indent(self.source) code = ( - "def %s():\n" % funcname + - code + - "\n_result = %s()" % funcname + "def %s():\n" % funcname + + code + + "\n_result = %s()" % funcname ) else: code = "if True:\n" + indent(self.source) @@ -269,8 +269,8 @@ def __setstate__(self, state): def __eq__(self, other): return ( - isinstance(other, SourceCode) and - other.source == self.source + isinstance(other, SourceCode) + and other.source == self.source ) def __ne__(self, other): diff --git a/src/rezplugins/release_hook/command.py b/src/rezplugins/release_hook/command.py index af667e4cf..ef392981f 100644 --- a/src/rezplugins/release_hook/command.py +++ b/src/rezplugins/release_hook/command.py @@ -25,24 +25,30 @@ class CommandReleaseHook(ReleaseHook): - commands_schema = Schema( - {"command": basestring, - Optional("args"): Or(And(basestring, - Use(lambda x: x.strip().split())), - [basestring]), - Optional("pretty_args"): bool, - Optional("user"): basestring, - Optional("env"): dict}) + commands_schema = Schema({ + "command": basestring, + Optional("args"): Or( + And( + basestring, + Use(lambda x: x.strip().split()) + ), + [basestring] + ), + Optional("pretty_args"): bool, + Optional("user"): basestring, + Optional("env"): dict + }) schema_dict = { - "print_commands": bool, - "print_output": bool, - "print_error": bool, - "cancel_on_error": bool, - "stop_on_error": bool, - "pre_build_commands": [commands_schema], - "pre_release_commands": [commands_schema], - "post_release_commands": [commands_schema]} + "print_commands": bool, + "print_output": bool, + "print_error": bool, + "cancel_on_error": bool, + "stop_on_error": bool, + "pre_build_commands": [commands_schema], + "pre_release_commands": [commands_schema], + "post_release_commands": [commands_schema] + } @classmethod def name(cls): @@ -134,8 +140,8 @@ def post_release(self, user, install_path, variants, **kwargs): variants=variants) if errors: print_debug( - "The following post-release commands failed:\n" + - '\n\n'.join(errors) + "The following post-release commands failed:\n" + + '\n\n'.join(errors) ) def _execute_commands(self, commands, install_path, package, errors=None, From 0cc0f326b242b7393fbf1e67127922d0ab3d0872 Mon Sep 17 00:00:00 2001 From: ajohns Date: Wed, 31 Mar 2021 15:59:51 +1100 Subject: [PATCH 9/9] more linter fixes --- src/rez/cli/_main.py | 2 +- src/rez/rex.py | 4 ++-- src/rezplugins/build_system/custom.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rez/cli/_main.py b/src/rez/cli/_main.py index ec13215fe..767a030f6 100644 --- a/src/rez/cli/_main.py +++ b/src/rez/cli/_main.py @@ -168,7 +168,7 @@ def run_cmd(): else: try: returncode = run_cmd() - except (NotImplementedError, RezSystemError) as e: + except (NotImplementedError, RezSystemError): raise except exc_type as e: print_error("%s: %s" % (e.__class__.__name__, str(e))) diff --git a/src/rez/rex.py b/src/rez/rex.py index 592fac9fc..0f69cf73b 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -1322,7 +1322,7 @@ def compile_code(cls, code, filename=None, exec_namespace=None): pyc = compile(code, filename, 'exec') except SourceCodeError as e: reraise(e, RexError) - except Exception as e: + except: stack = traceback.format_exc() raise RexError("Failed to compile %s:\n\n%s" % (filename, stack)) @@ -1339,7 +1339,7 @@ def compile_code(cls, code, filename=None, exec_namespace=None): raise except SourceCodeError as e: reraise(e, RexError) - except exc_type as e: + except exc_type: stack = traceback.format_exc() raise RexError("Failed to exec %s:\n\n%s" % (filename, stack)) diff --git a/src/rezplugins/build_system/custom.py b/src/rezplugins/build_system/custom.py index 470021d1b..b372d680c 100644 --- a/src/rezplugins/build_system/custom.py +++ b/src/rezplugins/build_system/custom.py @@ -83,14 +83,14 @@ def bind_cli(cls, parser, group): try: with open("./parse_build_args.py") as f: source = f.read() - except Exception as e: + except: return # detect what extra args have been added before_args = set(x.dest for x in parser._actions) try: - exec (source, {"parser": group}) + exec(source, {"parser": group}) except Exception as e: print_warning("Error in ./parse_build_args.py: %s" % str(e))