From 48c123c3f4581eeadda73460f903ba5a4e2c043f Mon Sep 17 00:00:00 2001 From: Peng Sun Date: Tue, 8 Aug 2023 21:59:46 +0100 Subject: Replace relative links with absolute links to https://review.mlplatform.org in package description. Change-Id: Id890542b76c383d868a40f2748184a8ee051ab82 --- setup.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 6aadd48..7aaf5d1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import argparse import git import os -import pathlib +import re import setuptools import setuptools.command.build_ext import shutil @@ -164,11 +164,30 @@ class BazelBuildExtension(setuptools.command.build_ext.build_ext): ) +def get_long_description(nightly): + # Read the contents of README.md file + this_directory = os.path.abspath(os.path.dirname(__file__)) + with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f: + long_description = f.read() + + if not nightly: + # Replace relative links to existing files with absolute links to https://review.mlplatform.org + url = f"https://review.mlplatform.org/plugins/gitiles/tosa/tosa_checker/+/refs/tags/{TOSA_CHECKER_VERSION}/" + # Find all markdown links that match the format: [text](link) + for match, link in re.findall(r"(\[.+?\]\((.+?)\))", long_description): + # If the link is a file that exists, replace it with the web link to the file instead + if os.path.exists(os.path.join(this_directory, link)): + url_link = re.sub(r"\((.+?)\)", rf"({url}{link})", match) + long_description = long_description.replace(match, url_link) + + return long_description + + setuptools.setup( name="tosa-checker", version=get_package_version(args.nightly), description="Tool to check if a ML model is compatible with the TOSA specification", - long_description=(pathlib.Path(__file__).parent / "README.md").read_text(), + long_description=get_long_description(args.nightly), long_description_content_type="text/markdown", author="Arm Limited", url="https://git.mlplatform.org/tosa/tosa_checker.git/", -- cgit v1.2.1