diff options
author | Michael McGeagh <michael.mcgeagh@arm.com> | 2020-12-03 13:08:32 +0000 |
---|---|---|
committer | patrik.gustavsson <patrik.gustavsson@arm.com> | 2020-12-07 14:53:36 +0000 |
commit | 1e05afa473cf2ca08d2a3464dae6bd2809913c83 (patch) | |
tree | d2e289cf93931f627e5538dd0b36eae37695db85 /setup.py | |
parent | 1e17018d1aabff6b2a4cc5e8e3758678347b84c5 (diff) | |
download | ethos-u-vela-1e05afa473cf2ca08d2a3464dae6bd2809913c83.tar.gz |
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 <michael.mcgeagh@arm.com>
Change-Id: Ia95530f38d5d78433c2d0e7c42bfff9532114285
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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", |