Yicong-Huang commented on code in PR #5417:
URL: https://github.com/apache/texera/pull/5417#discussion_r3368488808


##########
.github/workflows/build.yml:
##########
@@ -246,6 +246,21 @@ jobs:
             /tmp/dists/amber-*/lib || check_exit=$?
           ./bin/licensing/audit_jar_licenses.py /tmp/dists/amber-*/lib || true
           exit "$check_exit"
+      - name: Verify amber NOTICE-binary matches generator output
+        # amber/NOTICE-binary is generated from the bundled jars' 
META-INF/NOTICE
+        # content via bin/licensing/generate_notice_binary.py, plus
+        # amber/NOTICE-binary-python for the python-only (non-jar) 
attributions.
+        # Regenerate against the amber dist lib dir unzipped by the step above
+        # and diff against the committed file. Drift means a dep was added,
+        # removed, or bumped without rerunning the generator — fix by running:
+        #   ./bin/licensing/generate_notice_binary.py amber/NOTICE-binary 
/tmp/dists/amber-*/lib --extras amber/NOTICE-binary-python

Review Comment:
   can these two steps be merged?



##########
.github/workflows/build.yml:
##########
@@ -603,6 +618,20 @@ jobs:
             /tmp/dists/${{ matrix.service }}-*/lib || check_exit=$?
           ./bin/licensing/audit_jar_licenses.py /tmp/dists/${{ matrix.service 
}}-*/lib || true
           exit "$check_exit"
+      - name: Verify ${{ matrix.service }} NOTICE-binary matches generator 
output
+        # Each service's NOTICE-binary is generated from its bundled jars'
+        # META-INF/NOTICE content via bin/licensing/generate_notice_binary.py.
+        # Regenerate against the dist lib dir unzipped by the step above and
+        # diff against the committed file. Drift means a dep was added, 
removed,
+        # or bumped without rerunning the generator — fix by running:
+        #   ./bin/licensing/generate_notice_binary.py ${{ matrix.service 
}}/NOTICE-binary /tmp/dists/${{ matrix.service }}-*/lib
+        run: |
+          set -euo pipefail
+          ./bin/licensing/generate_notice_binary.py /tmp/notice-${{ 
matrix.service }}.txt /tmp/dists/${{ matrix.service }}-*/lib

Review Comment:
   ditto



##########
bin/licensing/generate_notice_binary.py:
##########
@@ -0,0 +1,215 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Generate a NOTICE-binary for a service from its bundled jars' 
META-INF/NOTICE
+files.
+
+The output starts with the project's own NOTICE (Texera ASF header), then
+emits one block per unique META-INF/NOTICE content (deduped by SHA-1 hash
+across the jars in the given lib dirs). Each block is headed by a synthesized
+project name derived from the longest common prefix of its members' Maven
+coordinates, plus the list of contributing jars.
+
+Blocks are sorted by jar count (largest cluster first), with hash as a stable
+tiebreaker.
+
+Optional `--extras <file>` appends a verbatim text file at the end. Use this
+for non-jar attributions (Apache-2.0 Python wheels like aiohttp, Matplotlib)
+that don't ship a NOTICE inside any jar.
+
+Usage:
+  generate_notice_binary.py <output> <lib-dir-1> [<lib-dir-2> ...] [--extras 
<file>] [--project-notice <NOTICE>]
+"""
+from __future__ import annotations
+
+import argparse
+import hashlib
+import os
+import re
+import sys
+import zipfile
+from collections import defaultdict
+from pathlib import Path
+
+
+SEP = "-" * 80
+TEXERA_OWN_JAR_PREFIX = "org.apache.texera."
+
+NOTICE_NAMES_TOPLEVEL = {"notice", "notice.txt", "notice.md"}
+
+
+def is_notice_entry(parts: list[str]) -> bool:
+    """Return True if the zip entry path is a NOTICE-style file we want to
+    pick up. Mirrors audit_jar_licenses.py's classifier (notice side)."""
+    if len(parts) == 1:
+        return parts[0].lower() in NOTICE_NAMES_TOPLEVEL
+    if parts[0].upper() != "META-INF":
+        return False
+    return "notice" in parts[-1].lower()
+
+
+def extract_notice_blob(jar_path: Path) -> str | None:
+    """Concatenate every NOTICE-style file in a jar (root level or
+    META-INF/...) into one blob. Return None for bad-zip jars or jars
+    whose NOTICE blobs are all empty."""
+    pieces: list[str] = []
+    try:
+        with zipfile.ZipFile(jar_path) as zf:
+            for name in zf.namelist():
+                if is_notice_entry(name.split("/")):
+                    try:
+                        raw = zf.read(name).decode("utf-8", errors="replace")
+                    except Exception:
+                        continue
+                    # Normalize line endings: jars from Windows-built upstreams
+                    # ship CRLF, which git auto-converts on commit and would
+                    # cause spurious drift between committed and regenerated.
+                    blob = raw.replace("\r\n", "\n").replace("\r", 
"\n").strip()
+                    if blob:
+                        pieces.append(blob)

Review Comment:
   are we going to manually execute this script? 
   
   better to use Path methods instead of string manipulation. otherwise this 
may not work for windows. 



##########
bin/licensing/generate_notice_binary.py:
##########
@@ -0,0 +1,215 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Generate a NOTICE-binary for a service from its bundled jars' 
META-INF/NOTICE
+files.
+
+The output starts with the project's own NOTICE (Texera ASF header), then
+emits one block per unique META-INF/NOTICE content (deduped by SHA-1 hash
+across the jars in the given lib dirs). Each block is headed by a synthesized
+project name derived from the longest common prefix of its members' Maven
+coordinates, plus the list of contributing jars.
+
+Blocks are sorted by jar count (largest cluster first), with hash as a stable
+tiebreaker.
+
+Optional `--extras <file>` appends a verbatim text file at the end. Use this
+for non-jar attributions (Apache-2.0 Python wheels like aiohttp, Matplotlib)
+that don't ship a NOTICE inside any jar.
+
+Usage:
+  generate_notice_binary.py <output> <lib-dir-1> [<lib-dir-2> ...] [--extras 
<file>] [--project-notice <NOTICE>]
+"""
+from __future__ import annotations

Review Comment:
   it will be good to write test for this script as well. similar to the script 
to detect LICENSE drift. 



-- 
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]

Reply via email to