chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
Finds and copies the latest shaded JAR from the Java build to the Python package source.
|
||||
|
||||
This script is intended to be run from the monorepo root, typically as part of a
|
||||
CI/CD pipeline, before the Python package is built.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
# Requires 'packaging' library (pip install packaging)
|
||||
from packaging.version import parse as parse_version
|
||||
|
||||
def find_latest_jar_by_semver(target_dir: Path) -> Optional[Path]:
|
||||
"""Finds the shaded JAR with the highest semantic version in its filename."""
|
||||
|
||||
# Example filename: opendataloader-pdf-runtime-0.1.0.jar
|
||||
jar_pattern = "opendataloader-pdf-runtime-*.jar"
|
||||
version_regex = re.compile(r"opendataloader-pdf-runtime-(.+?)\.jar")
|
||||
|
||||
latest_version = parse_version("0.0.0")
|
||||
latest_jar_path = None
|
||||
|
||||
# Exclude Maven's 'original' JARs to ensure we get the shaded (fat) JAR.
|
||||
potential_jars = [p for p in target_dir.glob(jar_pattern) if 'original' not in p.name]
|
||||
|
||||
if not potential_jars:
|
||||
return None
|
||||
|
||||
# Iterate through potential JARs to find the one with the highest version number.
|
||||
for jar_path in potential_jars:
|
||||
match = version_regex.search(jar_path.name)
|
||||
if match:
|
||||
try:
|
||||
current_version = parse_version(match.group(1))
|
||||
if current_version > latest_version:
|
||||
latest_version = current_version
|
||||
latest_jar_path = jar_path
|
||||
except Exception:
|
||||
# Ignore files with non-parseable version strings.
|
||||
continue
|
||||
|
||||
return latest_jar_path
|
||||
|
||||
def main():
|
||||
"""Parse command-line arguments and orchestrate the copy process."""
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s', stream=sys.stdout)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Copies the latest shaded JAR to the Python source tree.")
|
||||
parser.add_argument("java_target_dir", type=Path, help="Path to the Java module's 'target' directory.")
|
||||
parser.add_argument("python_jars_dir", type=Path, help="Path to the Python package's destination directory for JARs.")
|
||||
args = parser.parse_args()
|
||||
|
||||
java_target_path: Path = args.java_target_dir.resolve()
|
||||
python_jars_path: Path = args.python_jars_dir.resolve()
|
||||
|
||||
if not java_target_path.is_dir():
|
||||
parser.error(f"Java target directory not found: {java_target_path}")
|
||||
|
||||
# Ensure the destination directory exists.
|
||||
python_jars_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
source_jar_path = find_latest_jar_by_semver(java_target_path)
|
||||
if not source_jar_path:
|
||||
parser.error(f"No versioned shaded JAR found in: {java_target_path}")
|
||||
|
||||
# Standardize the destination name for consistent access within the Python package.
|
||||
destination_jar_path = python_jars_path / 'runtime.jar'
|
||||
|
||||
shutil.copy2(source_jar_path, destination_jar_path)
|
||||
logging.info(f"Copied '{source_jar_path.name}' to '{destination_jar_path}'")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,45 @@
|
||||
# build-scripts/set_version.py
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
def set_version(version_file, pom_file, pyproject_toml_file):
|
||||
with open(version_file, 'r') as f:
|
||||
version = f.read().strip()
|
||||
|
||||
# Update Maven POM
|
||||
with open(pom_file, 'r') as f:
|
||||
pom_content = f.read()
|
||||
pom_content = re.sub(r'<version>.*</version>', f'<version>{version}</version>', pom_content, count=1)
|
||||
with open(pom_file, 'w') as f:
|
||||
f.write(pom_content)
|
||||
print(f"Updated Maven POM version to {version}")
|
||||
|
||||
# Update Python pyproject.toml
|
||||
with open(pyproject_toml_file, 'r') as f:
|
||||
pyproject_content = f.read()
|
||||
pyproject_content = re.sub(r'version = ".*"', f'version = "{version}"', pyproject_content, count=1)
|
||||
with open(pyproject_toml_file, 'w') as f:
|
||||
f.write(pyproject_content)
|
||||
print(f"Updated Python pyproject.toml version to {version}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Paths are relative to the monorepo root
|
||||
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
version_path = os.path.join(root_dir, 'VERSION')
|
||||
java_pom_path = os.path.join(root_dir, 'java', 'pom.xml')
|
||||
python_pyproject_path = os.path.join(root_dir, 'python', 'packages', 'opendataloader_pdf', 'pyproject.toml')
|
||||
|
||||
if not os.path.exists(version_path):
|
||||
print(f"Error: VERSION file not found at {version_path}")
|
||||
sys.exit(1)
|
||||
if not os.path.exists(java_pom_path):
|
||||
print(f"Error: Java pom.xml not found at {java_pom_path}")
|
||||
sys.exit(1)
|
||||
if not os.path.exists(python_pyproject_path):
|
||||
print(f"Error: Python pyproject.toml not found at {python_pyproject_path}")
|
||||
sys.exit(1)
|
||||
|
||||
set_version(version_path, java_pom_path, python_pyproject_path)
|
||||
Reference in New Issue
Block a user