skrawcz commented on code in PR #1408:
URL: https://github.com/apache/hamilton/pull/1408#discussion_r2464566683
##########
scripts/apache_release_helper.py:
##########
@@ -139,10 +142,96 @@ def sign_artifacts(archive_name: str) ->
Optional[list[str]]:
return files
+def _modify_wheel_for_apache_release(original_wheel: str, new_wheel_path: str):
+ """Helper to modify the wheel for apache release.
+
+ # Flit somehow builds something incorrectly.
+ # 1. change PKG-INFO's first line to be `Metadata-Version: 2.4`
+ # 2. make sure the second line is `Name: apache-hamilton`
+ # 3. remove the `Import-Name: hamilton` line from PKG-INFO.
+
+ :param original_wheel: Path to the original wheel.
+ :param new_wheel_path: Path to the new wheel to create.
+ """
+ with tempfile.TemporaryDirectory() as tmpdir:
+ # Unzip the wheel
+ with zipfile.ZipFile(original_wheel, "r") as zip_ref:
+ zip_ref.extractall(tmpdir)
+
+ # Find the .dist-info directory
+ dist_info_dirs = glob.glob(os.path.join(tmpdir, "*.dist-info"))
+ if not dist_info_dirs:
+ raise ValueError(f"Could not find .dist-info directory in
{original_wheel}")
+ dist_info_dir = dist_info_dirs[0]
+ pkg_info = os.path.join(dist_info_dir, "PKG-INFO")
+
+ _modify_pkg_info_file(pkg_info)
+
+ # Create the new wheel
+ with zipfile.ZipFile(new_wheel_path, "w", zipfile.ZIP_DEFLATED) as
zip_ref:
+ for root, _, files in os.walk(tmpdir):
+ for file in files:
+ zip_ref.write(
+ os.path.join(root, file),
os.path.relpath(os.path.join(root, file), tmpdir)
+ )
+
+
+def _modify_pkg_info_file(pkg_info_path: str):
+ """
+ Flit somehow builds something incorrectly.
+ 1. change PKG-INFO's first line to be `Metadata-Version: 2.4`
+ 2. make sure the second line is `Name: apache-hamilton`
+ 3. remove the `Import-Name: hamilton` line from PKG-INFO.
+ """
+ with open(pkg_info_path, "r") as f:
+ lines = f.readlines()
+
+ new_lines = []
+ for i, line in enumerate(lines):
+ if i == 0:
+ new_lines.append("Metadata-Version: 2.4\n")
+ elif i == 1:
+ new_lines.append("Name: apache-hamilton\n")
+ elif line.strip() == "Import-Name: hamilton":
+ continue # Skip this line
+ else:
+ new_lines.append(line)
+
+ with open(pkg_info_path, "w") as f:
+ f.writelines(new_lines)
+
+
+def _modify_tarball_for_apache_release(original_tarball: str,
new_tarball_path: str):
+ """Helper to modify the tarball for apache release.
+
+ # Flit somehow builds something incorrectly.
+ # 1. change PKG-INFO's first line to be `Metadata-Version: 2.4`
+ # 2. make sure the second line is `Name: apache-hamilton`
+ # 3. remove the `Import-Name: hamilton` line from PKG-INFO.
+
+ :param original_tarball: Path to the original tarball.
+ :param new_tarball_path: Path to the new tarball to create.
+ """
+ with tempfile.TemporaryDirectory() as tmpdir:
+ # Extract the tarball
+ with tarfile.open(original_tarball, "r:gz") as tar:
+ tar.extractall(path=tmpdir)
+
+ # Modify the PKG-INFO file
+ # The extracted tarball has a single directory inside.
+ extracted_dir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
+ pkg_info_path = os.path.join(extracted_dir, "PKG-INFO")
+
+ _modify_pkg_info_file(pkg_info_path)
+
+ # Create the new tarball
+ with tarfile.open(new_tarball_path, "w:gz") as tar:
+ tar.add(extracted_dir, arcname=os.path.basename(extracted_dir))
+
+
def create_release_artifacts(version) -> list[str]:
"""Creates the source tarball, GPG signature, and checksums using `python
-m build`."""
- print("Creating release artifacts with 'python -m build'...")
- files_to_upload = []
+ print("Creating release artifacts with 'flit build'...")
Review Comment:
I think this is closer to the code -- so no difference?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]