Skip to content

Commit dbac83a

Browse files
committed
Fixes
1 parent 961420b commit dbac83a

File tree

17 files changed

+113
-85
lines changed

17 files changed

+113
-85
lines changed

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ exclude = [
88
'.*/rez/data/.*',
99
'.*/rez/vendor/.*',
1010
'.*/rez/tests/.*',
11+
'.*/rez/utils/lint_helper.py',
1112
]
1213
disable_error_code = ["var-annotated", "import-not-found"]
1314
check_untyped_defs = true
1415
# allow this for now:
15-
allow_redefinition = true
16+
allow_redefinition = true
17+
18+
[[tool.mypy.overrides]]
19+
module = 'rez.utils.lint_helper'
20+
follow_imports = "skip"

src/rez/cli/benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def load_packages():
4949
"""
5050
from rez.packages import iter_package_families
5151

52+
assert pkg_repo_dir is not None
53+
5254
print("Warming package cache...")
5355
fams = list(iter_package_families(paths=[pkg_repo_dir]))
5456

src/rez/cli/interpret.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def command(opts, parser, extra_arg_groups=None):
4747
with open(opts.FILE) as f:
4848
code = f.read()
4949

50-
interp = None
5150
if opts.format is None:
5251
interp = create_shell()
5352
elif opts.format in ('dict', 'table'):

src/rez/developer_package.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright Contributors to the Rez Project
33

44

5+
from __future__ import annotations
6+
57
from rez.config import config
68
from rez.packages import Package, create_package
79
from rez.serialise import load_from_file, FileFormat, set_objects
@@ -44,7 +46,7 @@ def root(self):
4446
return None
4547

4648
@classmethod
47-
def from_path(cls, path, format=None):
49+
def from_path(cls, path, format: FileFormat | None = None):
4850
"""Load a developer package.
4951
5052
A developer package may for example be a package.yaml or package.py in a

src/rez/packages.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
if TYPE_CHECKING:
2929
from typing import Literal # not available in typing module until 3.8
30+
from rez.config import Config
3031
from rez.developer_package import DeveloperPackage
3132
from rez.version import Requirement
3233
from rez.package_repository import PackageRepository
@@ -104,7 +105,7 @@ def uri(self):
104105
return self.resource.uri
105106

106107
@property
107-
def config(self):
108+
def config(self) -> Config:
108109
"""Returns the config for this package.
109110
110111
Defaults to global config if this package did not provide a 'config'
@@ -685,12 +686,12 @@ def get_package_from_string(txt: str, paths: list[str] | None = None):
685686
return get_package(o.name, o.version, paths=paths)
686687

687688

688-
def get_developer_package(path: str, format: str | None = None) -> DeveloperPackage:
689+
def get_developer_package(path: str, format: FileFormat | None = None) -> DeveloperPackage:
689690
"""Create a developer package.
690691
691692
Args:
692693
path (str): Path to dir containing package definition file.
693-
format (str): Package definition file format, detected if None.
694+
format (FileFormat): Package definition file format, detected if None.
694695
695696
Returns:
696697
`DeveloperPackage`.

src/rez/resolved_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class ResolvedContext(object):
155155
"""
156156
serialize_version = (4, 7)
157157
tmpdir_manager = TempDirs(config.context_tmpdir, prefix="rez_context_")
158-
context_tracking_payload = None
158+
context_tracking_payload: dict[str, Any] | None = None
159159
context_tracking_lock = threading.Lock()
160160
package_cache_present = True
161161
local = threading.local()
@@ -312,7 +312,7 @@ def __init__(self,
312312

313313
# the pre-resolve bindings. We store these because @late package.py
314314
# functions need them, and we cache them to avoid cost
315-
self.pre_resolve_bindings = None
315+
self.pre_resolve_bindings: dict[str, Any] | None = None
316316

317317
# suite information
318318
self.parent_suite_path = None
@@ -1145,7 +1145,7 @@ def get_environ(self, parent_environ=None) -> dict[str, str]:
11451145
return executor.get_output()
11461146

11471147
@_on_success
1148-
def get_key(self, key, request_only=False):
1148+
def get_key(self, key: str, request_only=False) -> dict[str, tuple[Variant, Any]]:
11491149
"""Get a data key value for each resolved package.
11501150
11511151
Args:
@@ -1169,7 +1169,7 @@ def get_key(self, key, request_only=False):
11691169
return values
11701170

11711171
@_on_success
1172-
def get_tools(self, request_only=False):
1172+
def get_tools(self, request_only=False) -> dict[str, tuple[Variant, list[str]]]:
11731173
"""Returns the commandline tools available in the context.
11741174
11751175
Args:
@@ -1182,7 +1182,7 @@ def get_tools(self, request_only=False):
11821182
return self.get_key("tools", request_only=request_only)
11831183

11841184
@_on_success
1185-
def get_tool_variants(self, tool_name):
1185+
def get_tool_variants(self, tool_name: str) -> set[Variant]:
11861186
"""Get the variant(s) that provide the named tool.
11871187
11881188
If there are more than one variants, the tool is in conflict, and Rez
@@ -1203,7 +1203,7 @@ def get_tool_variants(self, tool_name):
12031203
return variants
12041204

12051205
@_on_success
1206-
def get_conflicting_tools(self, request_only=False):
1206+
def get_conflicting_tools(self, request_only=False) -> dict[str, set[Variant]]:
12071207
"""Returns tools of the same name provided by more than one package.
12081208
12091209
Args:

src/rez/resolver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from contextlib import contextmanager
1616
from enum import Enum
1717
from hashlib import sha1
18-
from typing import Callable, Sequence, TYPE_CHECKING
18+
from typing import Callable, TYPE_CHECKING
1919

2020
if TYPE_CHECKING:
2121
from rez.package_order import PackageOrder
@@ -44,7 +44,7 @@ class Resolver(object):
4444
"""
4545
def __init__(self,
4646
context: ResolvedContext,
47-
package_requests: Sequence[Requirement],
47+
package_requests: list[Requirement],
4848
package_paths: list[str],
4949
package_filter: PackageFilterList | None = None,
5050
package_orderers: list[PackageOrder] | None = None,

src/rez/rex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,15 @@ def __init__(self, target_environ=None, passive=False):
632632
are skipped.
633633
'''
634634
self.passive = passive
635-
self.manager = None
635+
self.manager: ActionManager | None = None
636636
if (target_environ is None) or (target_environ is os.environ):
637637
self.target_environ = os.environ
638638
self.update_session = True
639639
else:
640640
self.target_environ = target_environ
641641
self.update_session = False
642642

643-
def set_manager(self, manager):
643+
def set_manager(self, manager: ActionManager):
644644
self.manager = manager
645645

646646
def apply_environ(self):

src/rez/shells.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import subprocess
2727

2828

29-
def get_shell_types():
29+
def get_shell_types() -> list[str]:
3030
"""Returns the available shell types: bash, tcsh etc.
3131
3232
Returns:
@@ -36,7 +36,7 @@ def get_shell_types():
3636
return list(plugin_manager.get_plugins('shell'))
3737

3838

39-
def get_shell_class(shell=None):
39+
def get_shell_class(shell=None) -> type[Shell]:
4040
"""Get the plugin class associated with the given or current shell.
4141
4242
Returns:
@@ -49,7 +49,7 @@ def get_shell_class(shell=None):
4949
shell = system.shell
5050

5151
from rez.plugin_managers import plugin_manager
52-
return plugin_manager.get_plugin_class("shell", shell)
52+
return plugin_manager.get_plugin_class("shell", shell, type=Shell)
5353

5454

5555
def create_shell(shell: str | None = None, **kwargs) -> Shell:
@@ -74,29 +74,29 @@ class Shell(ActionInterpreter):
7474
schema_dict = {"prompt": str}
7575

7676
@classmethod
77-
def name(cls):
77+
def name(cls) -> str:
7878
"""Plugin name.
7979
"""
8080
raise NotImplementedError
8181

8282
@classmethod
83-
def executable_name(cls):
83+
def executable_name(cls) -> str:
8484
"""Name of executable to create shell instance.
8585
"""
8686
return cls.name()
8787

8888
@classmethod
89-
def executable_filepath(cls):
89+
def executable_filepath(cls) -> str:
9090
"""Get full filepath to executable, or raise if not found.
9191
"""
9292
return cls.find_executable(cls.executable_name())
9393

9494
@property
95-
def executable(self):
95+
def executable(self) -> str:
9696
return self.__class__.executable_filepath()
9797

9898
@classmethod
99-
def is_available(cls):
99+
def is_available(cls) -> bool:
100100
"""Determine if the shell is available to instantiate.
101101
102102
Returns:
@@ -108,7 +108,7 @@ def is_available(cls):
108108
return False
109109

110110
@classmethod
111-
def file_extension(cls):
111+
def file_extension(cls) -> str:
112112
"""Get the file extension associated with the shell.
113113
114114
Returns:
@@ -139,7 +139,7 @@ def __init__(self):
139139
def _addline(self, line):
140140
self._lines.append(line)
141141

142-
def get_output(self, style=OutputStyle.file):
142+
def get_output(self, style=OutputStyle.file) -> str:
143143
if style == OutputStyle.file:
144144
script = '\n'.join(self._lines) + '\n'
145145
else: # eval style
@@ -240,7 +240,7 @@ def spawn_shell(self, context_file, tmpdir, rcfile=None, norc=False,
240240
raise NotImplementedError
241241

242242
@classmethod
243-
def convert_tokens(cls, value):
243+
def convert_tokens(cls, value) -> str:
244244
"""
245245
Converts any token like ${VAR} and $VAR to shell specific form.
246246
Uses the ENV_VAR_REGEX to correctly parse tokens.
@@ -257,7 +257,7 @@ def convert_tokens(cls, value):
257257
)
258258

259259
@classmethod
260-
def get_key_token(cls, key):
260+
def get_key_token(cls, key) -> str:
261261
"""
262262
Encodes the environment variable into the shell specific form.
263263
Shells might implement multiple forms, but the most common/safest
@@ -272,7 +272,7 @@ def get_key_token(cls, key):
272272
return cls.get_all_key_tokens(key)[0]
273273

274274
@classmethod
275-
def get_all_key_tokens(cls, key):
275+
def get_all_key_tokens(cls, key) -> list[str]:
276276
"""
277277
Encodes the environment variable into the shell specific forms.
278278
Shells might implement multiple forms, but the most common/safest
@@ -287,15 +287,15 @@ def get_all_key_tokens(cls, key):
287287
raise NotImplementedError
288288

289289
@classmethod
290-
def line_terminator(cls):
290+
def line_terminator(cls) -> str:
291291
"""
292292
Returns:
293293
str: default line terminator
294294
"""
295295
raise NotImplementedError
296296

297297
@classmethod
298-
def join(cls, command):
298+
def join(cls, command) -> str:
299299
"""
300300
Note: Default to unix sh/bash- friendly behaviour.
301301
@@ -328,10 +328,10 @@ class UnixShell(Shell):
328328
r"""
329329
A base class for common \*nix shells, such as bash and tcsh.
330330
"""
331-
rcfile_arg = None
332-
norc_arg = None
333-
histfile = None
334-
histvar = None
331+
rcfile_arg: str = None
332+
norc_arg: str = None
333+
histfile: str = None
334+
histvar: str = None
335335
command_arg = '-c'
336336
stdin_arg = '-s'
337337
last_command_status = '$?'
@@ -518,21 +518,21 @@ def _create_ex():
518518
% (cmd_str, str(e)))
519519
return p
520520

521-
def resetenv(self, key, value, friends=None):
521+
def resetenv(self, key, value, friends=None) -> None:
522522
self._addline(self.setenv(key, value))
523523

524-
def info(self, value):
524+
def info(self, value) -> None:
525525
for line in value.split('\n'):
526526
line = self.escape_string(line)
527527
self._addline('echo %s' % line)
528528

529-
def error(self, value):
529+
def error(self, value) -> None:
530530
for line in value.split('\n'):
531531
line = self.escape_string(line)
532532
self._addline('echo %s 1>&2' % line)
533533

534534
# escaping is allowed in args, but not in program string
535-
def command(self, value):
535+
def command(self, value) -> None:
536536
if is_non_string_iterable(value):
537537
it = iter(value)
538538
cmd = EscapedString.disallow(next(it))
@@ -542,18 +542,18 @@ def command(self, value):
542542
value = EscapedString.disallow(value)
543543
self._addline(value)
544544

545-
def comment(self, value):
545+
def comment(self, value) -> None:
546546
value = EscapedString.demote(value)
547547
for line in value.split('\n'):
548548
self._addline('# %s' % line)
549549

550-
def shebang(self):
550+
def shebang(self) -> None:
551551
self._addline("#!%s" % self.executable)
552552

553553
@classmethod
554554
def get_all_key_tokens(cls, key):
555555
return ["${%s}" % key, "$%s" % key]
556556

557557
@classmethod
558-
def line_terminator(cls):
558+
def line_terminator(cls) -> str:
559559
return "\n"

0 commit comments

Comments
 (0)