Skip to content

Commit

Permalink
chore(wheelmaker): drop Python 2 support (#1545)
Browse files Browse the repository at this point in the history
Python2 has been EOL for a while so this is just a small cleanup.
  • Loading branch information
aignas authored Nov 8, 2023
1 parent 955da69 commit b347a29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Breaking changes:
`incompatible_normalize_version` to `True` by default to enforce `PEP440`
for wheel names built by `rules_python`.

* (tools/wheelmaker.py) drop support for Python 2 as only Python 3 is tested.

### Fixed

* Skip aliases for unloaded toolchains. Some Python versions that don't have full
Expand Down
24 changes: 8 additions & 16 deletions tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def arcname_from(name):

def add_string(self, filename, contents):
"""Add given 'contents' as filename to the distribution."""
if sys.version_info[0] > 2 and isinstance(contents, str):
if isinstance(contents, str):
contents = contents.encode("utf-8", "surrogateescape")
zinfo = self._zipinfo(filename)
self.writestr(zinfo, contents)
Expand Down Expand Up @@ -199,7 +199,7 @@ def add_recordfile(self):
entries = self._record + [(record_path, b"", b"")]
contents = b""
for filename, digest, size in entries:
if sys.version_info[0] > 2 and isinstance(filename, str):
if isinstance(filename, str):
filename = filename.lstrip("/").encode("utf-8", "surrogateescape")
contents += b"%s,%s,%s\n" % (filename, digest, size)

Expand Down Expand Up @@ -530,22 +530,14 @@ def main() -> None:

description = None
if arguments.description_file:
if sys.version_info[0] == 2:
with open(arguments.description_file, "rt") as description_file:
description = description_file.read()
else:
with open(
arguments.description_file, "rt", encoding="utf-8"
) as description_file:
description = description_file.read()
with open(
arguments.description_file, "rt", encoding="utf-8"
) as description_file:
description = description_file.read()

metadata = None
if sys.version_info[0] == 2:
with open(arguments.metadata_file, "rt") as metadata_file:
metadata = metadata_file.read()
else:
with open(arguments.metadata_file, "rt", encoding="utf-8") as metadata_file:
metadata = metadata_file.read()
with open(arguments.metadata_file, "rt", encoding="utf-8") as metadata_file:
metadata = metadata_file.read()

if arguments.noincompatible_normalize_version:
version_in_metadata = version
Expand Down

0 comments on commit b347a29

Please sign in to comment.