bobbai00 commented on code in PR #5417: URL: https://github.com/apache/texera/pull/5417#discussion_r3369703244
########## 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: changed -- 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]
