Skip to content

Commit f351d24

Browse files
committed
remove badges and strip links when generating PyPI package description
This is to avoid broken links in the PyPI project description (that occur because we avoid hardcoding the Github repository URLs in the README).
1 parent 0028196 commit f351d24

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

setup.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
from pathlib import Path
2-
from setuptools import setup
1+
import re
32
import sdist_upip
3+
from setuptools import setup
44

5+
VERSION = "1.0.0"
56

6-
HERE = Path(__file__).parent
7-
README = (HERE / 'README.rst').read_text()
87

9-
VERSION = "1.0.0"
8+
def long_desc_from_readme():
9+
with open('README.rst', 'r') as fd:
10+
long_description = fd.read()
11+
12+
# remove badges
13+
long_description = re.compile(r'^\.\. start-badges.*^\.\. end-badges', re.M | re.S).sub('', long_description)
14+
15+
# strip links. keep link name and use literal text formatting
16+
long_description = re.sub(r'`([^<`]+) </[^>]+>`_', '``\\1``', long_description)
17+
18+
return long_description
19+
1020

1121
setup(
1222
name="micropython-py-esp32-ulp",
1323
version=VERSION,
1424
description="Assembler toolchain for the ESP32 ULP co-processor, written in MicroPython",
15-
long_description=README,
25+
long_description=long_desc_from_readme(),
1626
long_description_content_type='text/x-rst',
1727
url="https://github.com/ThomasWaldmann/py-esp32-ulp",
1828
license="MIT",

0 commit comments

Comments
 (0)