From 1e05afa473cf2ca08d2a3464dae6bd2809913c83 Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Thu, 3 Dec 2020 13:08:32 +0000 Subject: vela: Further improve readme regex in setup.py Replace exact instances, not just any occurance Add ability to dump modified contents to a file "PYPI.md" to verify changes are as expected. To enable that mode, an environment variable is required to exist when running pip or setup.py. e.g: ETHOSU_VELA_DEBUG=1 pip install -e . Signed-off-by: Michael McGeagh Change-Id: Ia95530f38d5d78433c2d0e7c42bfff9532114285 --- setup.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index ee4e40e8..57cc2aee 100644 --- a/setup.py +++ b/setup.py @@ -15,23 +15,29 @@ # limitations under the License. # Description: # Packaging for the Vela compiler +import os import re -from os import path from setuptools import Extension from setuptools import find_namespace_packages from setuptools import setup # Read the contents of README.md file -this_directory = path.abspath(path.dirname(__file__)) -with open(path.join(this_directory, "README.md"), encoding="utf-8") as f: +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() - # Replace local file links with URLs tag = "2.0.1" url = f"https://review.mlplatform.org/plugins/gitiles/ml/ethos-u/ethos-u-vela/+/refs/tags/{tag}/" - for link in set(re.findall(r"\[.+\]\((.+?)\)", long_description)): - if path.exists(path.join(this_directory, link)): - long_description = long_description.replace(link, url + link) + # 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 = match.replace(link, url + link) + long_description = long_description.replace(match, url_link) + if os.getenv("ETHOSU_VELA_DEBUG"): + # Verify the contents of the modifications made in a markdown renderer + with open(os.path.join(this_directory, "PYPI.md"), "wt", encoding="utf-8") as fout: + fout.write(long_description) mlw_module = Extension( "ethosu.mlw_codec", -- cgit v1.2.1