diff --git a/.github/workflows/ruff.yaml b/.github/workflows/ruff.yaml index 5b490af52..b3adbf418 100644 --- a/.github/workflows/ruff.yaml +++ b/.github/workflows/ruff.yaml @@ -13,6 +13,7 @@ on: - '!src/rez/utils/_version.py' - '!src/rez/vendor/**' - '!src/rez/data/**' + - '!src/support/**' push: paths: - '.github/workflows/ruff.yaml' @@ -26,6 +27,7 @@ on: - '!src/rez/utils/_version.py' - '!src/rez/vendor/**' - '!src/rez/data/**' + - '!src/support/**' permissions: contents: read diff --git a/install.py b/install.py index f6ded0c9b..6f065b963 100644 --- a/install.py +++ b/install.py @@ -18,7 +18,6 @@ import venv except ImportError: USE_VIRTUALENV = True - import virtualenv source_path = os.path.dirname(os.path.realpath(__file__)) @@ -29,7 +28,7 @@ # though rez is not yet built. # from rez.utils._version import _rez_version # noqa: E402 -from rez.utils.filesystem import safe_rmtree +from rez.utils.filesystem import safe_rmtree # noqa: E402 from rez.utils.which import which # noqa: E402 from rez.cli._entry_points import get_specifications # noqa: E402 from rez.vendor.distlib.scripts import ScriptMaker # noqa: E402 diff --git a/release-rez.py b/release-rez.py index 89826215f..9cb153b6c 100644 --- a/release-rez.py +++ b/release-rez.py @@ -24,7 +24,7 @@ src_path = os.path.join(source_path, "src") sys.path.insert(0, src_path) -from rez.utils._version import _rez_version +from rez.utils._version import _rez_version # noqa: E402 def get_github_repo_owner(): @@ -212,7 +212,7 @@ def generate_changelog_entry(issue_nums): ) # print title section - today = date.today() + today = date.today() # noqa: DTZ011 print( "## v%s (%d-%02d-%02d)" % (_rez_version, today.year, today.month, today.day) diff --git a/ruff.toml b/ruff.toml index d38b079c4..134a64f4b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -21,6 +21,7 @@ include = [ extend-exclude = [ "src/rez/vendor", "src/rez/data", + "src/support" ] # Match flake8 linter defaults @@ -108,59 +109,11 @@ ignore = [ ] [lint.per-file-ignores] -"__init__.py" = [ - "D104" # undocumented-public-package -] -"src/rez/tests/*.py" = [ - "F821" # Undefined name -] -"src/rez/bind/_pymodule.py" = [ - "F821" # Undefined name -] -"src/rez/utils/filesystem.py" = [ - "F821" # Undefined name -] -"src/rez/resolver.py" = [ - "F821" # Undefined name -] -"src/rez/cli/_main.py" = [ - "ISC002" # Implicitly concatenated string literals over multiple lines -] -"src/rez/cli/release.py" = [ - "F821" # Undefined name -] -"src/rez/package_order.py" = [ - "E721" # Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks -] -"src/rez/tests/test_formatter.py" = [ - "E742" # Ambiguous class name: `I` -] -"src/rezgui/objects/Config.py" = [ - "E721" # Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks -] -"src/rezgui/widgets/ContextToolsWidget.py" = [ - "F401" # "rezgui.objects.App.app" imported but unused -] -"src/rezgui/widgets/TimestampWidget.py" = [ - "E731" # Do not assign a `lambda` expression, use a `def` -] +# Bug in the following. Uses the git python package, which is not installed, in the +# export # class method. rez-diff calls the method. "src/rezplugins/release_vcs/git.py" = [ "F821" # Undefined name ] -"src/support/package_utils/set_authors.py" = [ - "INP001" # part of an implicit namespace package -] -"./release-rez.py" = [ - "E402", # Module level import not at top of file - "DTZ011" # `datetime.date.today()` used -] -"./install.py" = [ - "E402", # Module level import not at top of file - "F401" # "virtualenv" imported but unused -] -"./setup.py" = [ - "E402" # Module level import not at top of file -] [lint.flake8-annotations] # Allow "Any" for dynamically typed *args and **kwargs arguments diff --git a/setup.py b/setup.py index 58aeacca8..0b81051ae 100644 --- a/setup.py +++ b/setup.py @@ -19,8 +19,8 @@ src_path = os.path.join(source_path, "src") sys.path.insert(0, src_path) -from rez.utils._version import _rez_version -from rez.cli._entry_points import get_specifications +from rez.utils._version import _rez_version # noqa: E402 +from rez.cli._entry_points import get_specifications # noqa: E402 def find_files(pattern, path=None, root="rez"): diff --git a/src/rez/bind/_pymodule.py b/src/rez/bind/_pymodule.py index 74d6c0171..ad0f9dc2b 100644 --- a/src/rez/bind/_pymodule.py +++ b/src/rez/bind/_pymodule.py @@ -21,12 +21,12 @@ def commands() -> None: - env.PYTHONPATH.append('{this.root}/python') + env.PYTHONPATH.append('{this.root}/python') # noqa: F821 def commands_with_bin() -> None: - env.PYTHONPATH.append('{this.root}/python') - env.PATH.append('{this.root}/bin') + env.PYTHONPATH.append('{this.root}/python') # noqa: F821 + env.PATH.append('{this.root}/bin') # noqa: F821 def copy_module(name, destpath): diff --git a/src/rez/cli/_main.py b/src/rez/cli/_main.py index c5733a1ce..9a2be6bf5 100644 --- a/src/rez/cli/_main.py +++ b/src/rez/cli/_main.py @@ -35,14 +35,14 @@ def __call__(self, parser_name, parser): error_msg = None if not mod.__doc__: - error_msg = "command module %s must have a module-level " \ - "docstring (used as the command help)" % self.module_name + error_msg = ( + f"command module {self.module_name} must have a module-level docstring " + "(used as the command help)" + ) if not hasattr(mod, 'command'): - error_msg = "command module %s must provide a command() " \ - "function" % self.module_name + error_msg = f"command module {self.module_name} must provide a command() function" if not hasattr(mod, 'setup_parser'): - error_msg = "command module %s must provide a setup_parser() " \ - "function" % self.module_name + error_msg = f"command module {self.module_name} must provide a setup_parser() function" if error_msg: print(error_msg, file=sys.stderr) return SUPPRESS diff --git a/src/rez/config.py b/src/rez/config.py index b1c5f67d6..74a4b1f76 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -659,7 +659,7 @@ def sourced_filepaths(self) -> list[str]: Returns: List of str: The sourced files. """ - _ = self._data # noqa; force a config load + _ = self._data # force a config load # noqa return self._sourced_filepaths or [] @cached_property diff --git a/src/rez/package_order.py b/src/rez/package_order.py index d8c755575..df813ae19 100644 --- a/src/rez/package_order.py +++ b/src/rez/package_order.py @@ -193,7 +193,9 @@ def __str__(self) -> str: raise NotImplementedError def __eq__(self, other): - return type(self) == type(other) and str(self) == str(other) # noqa: E721 + if isinstance(other, type(self)): + return str(self) == str(other) + return NotImplemented def __ne__(self, other) -> bool: return not self == other @@ -220,7 +222,7 @@ def __str__(self) -> str: return "{}" def __eq__(self, other): - return type(self) == type(other) # noqa: E721 + return type(self) is type(other) def to_pod(self) -> dict[str, Any]: """ @@ -266,10 +268,7 @@ def __str__(self) -> str: return str(self.descending) def __eq__(self, other): - return ( # noqa: E721 - type(self) == type(other) - and self.descending == other.descending - ) + return type(self) is type(other) and self.descending == other.descending def to_pod(self) -> dict[str, Any]: """ @@ -345,8 +344,8 @@ def __str__(self) -> str: return str((items, str(self.default_order))) def __eq__(self, other): - return ( # noqa: E721 - type(other) == type(self) + return ( + type(other) is type(self) and self.order_dict == other.order_dict and self.default_order == other.default_order ) @@ -437,10 +436,7 @@ def __str__(self) -> str: return str(self.first_version) def __eq__(self, other): - return ( # noqa: E721 - type(other) == type(self) - and self.first_version == other.first_version - ) + return type(other) is type(self) and self.first_version == other.first_version def to_pod(self) -> dict[str, Any]: """ @@ -601,7 +597,7 @@ def __str__(self) -> str: def __eq__(self, other): return ( # noqa: E721 - type(other) == type(self) + type(other) is type(self) and self.timestamp == other.timestamp and self.rank == other.rank ) diff --git a/src/rez/resolver.py b/src/rez/resolver.py index 162bdb525..1da2a4137 100644 --- a/src/rez/resolver.py +++ b/src/rez/resolver.py @@ -20,7 +20,9 @@ if TYPE_CHECKING: from rez.package_order import PackageOrderList from rez.resolved_context import ResolvedContext + from rez.utils.resources import ResourceHandle from rez.utils.typing import SupportsWrite + from rez.vendor.pygraph.classes.digraph import digraph class SolverDict(TypedDict): diff --git a/src/rez/tests/ruff.toml b/src/rez/tests/ruff.toml new file mode 100644 index 000000000..7531e3c35 --- /dev/null +++ b/src/rez/tests/ruff.toml @@ -0,0 +1,20 @@ +extend = "../../../ruff.toml" + +# Treat rex as builtin +builtins = [ + "alias", + "appendenv", + "command", + "comment", + "defined", + "env", + "error", + "getenv", + "info", + "prependenv", + "setenv", + "shebang", + "source", + "undefined", + "unsetenv", +] diff --git a/src/rez/tests/test_formatter.py b/src/rez/tests/test_formatter.py index 792ff8f4a..0f2199103 100644 --- a/src/rez/tests/test_formatter.py +++ b/src/rez/tests/test_formatter.py @@ -100,7 +100,7 @@ class H(object): def __format__(self, format_spec) -> str: return 1.0 - class I(datetime.date): + class I(datetime.date): # noqa: E742 def __format__(self, format_spec) -> str: return self.strftime(format_spec) diff --git a/src/rezgui/objects/Config.py b/src/rezgui/objects/Config.py index bd3b7b6aa..bd3a0a68b 100644 --- a/src/rezgui/objects/Config.py +++ b/src/rezgui/objects/Config.py @@ -26,7 +26,7 @@ def value(self, key, type_=None): if type_ is None: default = self._default_value(key) val = self._value(key, default) - if type(val) == type(default): + if type(val) is type(default): return val else: return self._convert_value(val, type(default)) diff --git a/src/rezgui/widgets/ContextToolsWidget.py b/src/rezgui/widgets/ContextToolsWidget.py index 8d573dffe..4d71ca1dc 100644 --- a/src/rezgui/widgets/ContextToolsWidget.py +++ b/src/rezgui/widgets/ContextToolsWidget.py @@ -7,7 +7,6 @@ from rezgui.models.ContextModel import ContextModel from rezgui.mixins.ContextViewMixin import ContextViewMixin from rezgui.util import get_icon -from rezgui.objects.App import app class _TreeNode(QtWidgets.QLabel): diff --git a/src/rezgui/widgets/TimestampWidget.py b/src/rezgui/widgets/TimestampWidget.py index 698afe903..b5ea15fa9 100644 --- a/src/rezgui/widgets/TimestampWidget.py +++ b/src/rezgui/widgets/TimestampWidget.py @@ -63,10 +63,9 @@ def _stateChanged(self, state) -> None: self.refresh() def _selectPackage(self) -> None: - fn = lambda x: bool(x.timestamp) dlg = BrowsePackageDialog(context_model=self.context_model, parent=self.parentWidget(), - package_selectable_callback=fn) + package_selectable_callback=lambda x: bool(x.timestamp)) dlg.exec_() if dlg.package: self.set_time(dlg.package.timestamp) diff --git a/src/rezplugins/release_vcs/git.py b/src/rezplugins/release_vcs/git.py index aad9bce6b..2543d1428 100644 --- a/src/rezplugins/release_vcs/git.py +++ b/src/rezplugins/release_vcs/git.py @@ -6,6 +6,7 @@ Git version control """ from rez.release_vcs import ReleaseVCS +from rez.utils.filesystem import retain_cwd from rez.utils.logging_ import print_error, print_debug from rez.exceptions import ReleaseVCSError from shutil import rmtree