|  | 
| 23 | 23 | from zipfile import ZIP_DEFLATED, ZIP_STORED | 
| 24 | 24 | 
 | 
| 25 | 25 | from .. import Command, __version__ | 
|  | 26 | +from .egg_info import egg_info as egg_info_cls | 
| 26 | 27 | from ..extern.wheel.metadata import pkginfo_to_metadata | 
| 27 | 28 | from ..extern.packaging import tags | 
| 28 | 29 | from ..extern.packaging import version as _packaging_version | 
| 29 | 30 | from ..extern.wheel.wheelfile import WheelFile | 
| 30 | 31 | 
 | 
| 31 | 32 | if TYPE_CHECKING: | 
| 32 |  | -    import types | 
|  | 33 | +    from _typeshed import ExcInfo | 
| 33 | 34 | 
 | 
| 34 | 35 | 
 | 
| 35 | 36 | def safe_name(name: str) -> str: | 
| @@ -152,12 +153,14 @@ def safer_version(version: str) -> str: | 
| 152 | 153 | def remove_readonly( | 
| 153 | 154 |     func: Callable[..., object], | 
| 154 | 155 |     path: str, | 
| 155 |  | -    excinfo: tuple[type[Exception], Exception, types.TracebackType], | 
|  | 156 | +    excinfo: ExcInfo, | 
| 156 | 157 | ) -> None: | 
| 157 | 158 |     remove_readonly_exc(func, path, excinfo[1]) | 
| 158 | 159 | 
 | 
| 159 | 160 | 
 | 
| 160 |  | -def remove_readonly_exc(func: Callable[..., object], path: str, exc: Exception) -> None: | 
|  | 161 | +def remove_readonly_exc( | 
|  | 162 | +    func: Callable[..., object], path: str, exc: BaseException | 
|  | 163 | +) -> None: | 
| 161 | 164 |     os.chmod(path, stat.S_IWRITE) | 
| 162 | 165 |     func(path) | 
| 163 | 166 | 
 | 
| @@ -232,40 +235,47 @@ class bdist_wheel(Command): | 
| 232 | 235 | 
 | 
| 233 | 236 |     def initialize_options(self) -> None: | 
| 234 | 237 |         self.bdist_dir: str | None = None | 
| 235 |  | -        self.data_dir = None | 
|  | 238 | +        self.data_dir: str | None = None | 
| 236 | 239 |         self.plat_name: str | None = None | 
| 237 |  | -        self.plat_tag = None | 
|  | 240 | +        self.plat_tag: str | None = None | 
| 238 | 241 |         self.format = "zip" | 
| 239 | 242 |         self.keep_temp = False | 
| 240 | 243 |         self.dist_dir: str | None = None | 
| 241 |  | -        self.egginfo_dir = None | 
|  | 244 | +        self.egginfo_dir: str | None = None | 
| 242 | 245 |         self.root_is_pure: bool | None = None | 
| 243 |  | -        self.skip_build = None | 
|  | 246 | +        self.skip_build = False | 
| 244 | 247 |         self.relative = False | 
| 245 | 248 |         self.owner = None | 
| 246 | 249 |         self.group = None | 
| 247 | 250 |         self.universal: bool = False | 
| 248 |  | -        self.compression: str | int = "deflated" | 
|  | 251 | +        self.compression: int = ZIP_DEFLATED | 
| 249 | 252 |         self.python_tag: str = python_tag() | 
| 250 | 253 |         self.build_number: str | None = None | 
| 251 | 254 |         self.py_limited_api: str | Literal[False] = False | 
| 252 | 255 |         self.plat_name_supplied = False | 
| 253 | 256 | 
 | 
| 254 |  | -    def finalize_options(self): | 
| 255 |  | -        if self.bdist_dir is None: | 
|  | 257 | +    def finalize_options(self) -> None: | 
|  | 258 | +        if not self.bdist_dir: | 
| 256 | 259 |             bdist_base = self.get_finalized_command("bdist").bdist_base | 
| 257 | 260 |             self.bdist_dir = os.path.join(bdist_base, "wheel") | 
| 258 | 261 | 
 | 
| 259 |  | -        egg_info = self.distribution.get_command_obj("egg_info") | 
|  | 262 | +        egg_info = cast(egg_info_cls, self.distribution.get_command_obj("egg_info")) | 
| 260 | 263 |         egg_info.ensure_finalized()  # needed for correct `wheel_dist_name` | 
| 261 | 264 | 
 | 
| 262 | 265 |         self.data_dir = self.wheel_dist_name + ".data" | 
| 263 |  | -        self.plat_name_supplied = self.plat_name is not None | 
|  | 266 | +        self.plat_name_supplied = bool(self.plat_name) | 
| 264 | 267 | 
 | 
| 265 |  | -        try: | 
| 266 |  | -            self.compression = self.supported_compressions[self.compression] | 
| 267 |  | -        except KeyError: | 
| 268 |  | -            raise ValueError(f"Unsupported compression: {self.compression}") from None | 
|  | 268 | +        # Handle compression not being an int or a supported value | 
|  | 269 | +        if not ( | 
|  | 270 | +            isinstance(self.compression, int) | 
|  | 271 | +            and self.compression in self.supported_compressions.values() | 
|  | 272 | +        ): | 
|  | 273 | +            try: | 
|  | 274 | +                self.compression = self.supported_compressions[str(self.compression)] | 
|  | 275 | +            except KeyError: | 
|  | 276 | +                raise ValueError( | 
|  | 277 | +                    f"Unsupported compression: {self.compression}" | 
|  | 278 | +                ) from None | 
| 269 | 279 | 
 | 
| 270 | 280 |         need_options = ("dist_dir", "plat_name", "skip_build") | 
| 271 | 281 | 
 | 
| @@ -295,21 +305,21 @@ def finalize_options(self): | 
| 295 | 305 |             raise ValueError("Build tag (build-number) must start with a digit.") | 
| 296 | 306 | 
 | 
| 297 | 307 |     @property | 
| 298 |  | -    def wheel_dist_name(self): | 
|  | 308 | +    def wheel_dist_name(self) -> str: | 
| 299 | 309 |         """Return distribution full name with - replaced with _""" | 
| 300 |  | -        components = ( | 
|  | 310 | +        components = [ | 
| 301 | 311 |             safer_name(self.distribution.get_name()), | 
| 302 | 312 |             safer_version(self.distribution.get_version()), | 
| 303 |  | -        ) | 
|  | 313 | +        ] | 
| 304 | 314 |         if self.build_number: | 
| 305 |  | -            components += (self.build_number,) | 
|  | 315 | +            components.append(self.build_number) | 
| 306 | 316 |         return "-".join(components) | 
| 307 | 317 | 
 | 
| 308 | 318 |     def get_tag(self) -> tuple[str, str, str]: | 
| 309 | 319 |         # bdist sets self.plat_name if unset, we should only use it for purepy | 
| 310 | 320 |         # wheels if the user supplied it. | 
| 311 |  | -        if self.plat_name_supplied: | 
| 312 |  | -            plat_name = cast(str, self.plat_name) | 
|  | 321 | +        if self.plat_name_supplied and self.plat_name: | 
|  | 322 | +            plat_name = self.plat_name | 
| 313 | 323 |         elif self.root_is_pure: | 
| 314 | 324 |             plat_name = "any" | 
| 315 | 325 |         else: | 
| @@ -453,7 +463,7 @@ def run(self): | 
| 453 | 463 | 
 | 
| 454 | 464 |     def write_wheelfile( | 
| 455 | 465 |         self, wheelfile_base: str, generator: str = f"setuptools ({__version__})" | 
| 456 |  | -    ): | 
|  | 466 | +    ) -> None: | 
| 457 | 467 |         from email.message import Message | 
| 458 | 468 | 
 | 
| 459 | 469 |         msg = Message() | 
| @@ -527,7 +537,7 @@ def license_paths(self) -> Iterable[str]: | 
| 527 | 537 | 
 | 
| 528 | 538 |         return files | 
| 529 | 539 | 
 | 
| 530 |  | -    def egg2dist(self, egginfo_path: str, distinfo_path: str): | 
|  | 540 | +    def egg2dist(self, egginfo_path: str, distinfo_path: str) -> None: | 
| 531 | 541 |         """Convert an .egg-info directory into a .dist-info directory""" | 
| 532 | 542 | 
 | 
| 533 | 543 |         def adios(p: str) -> None: | 
|  | 
0 commit comments