Przeglądaj źródła

Add github2pypi

Kentaro Wada 6 lat temu
rodzic
commit
01809e731f
3 zmienionych plików z 11 dodań i 45 usunięć
  1. 3 0
      .gitmodules
  2. 1 0
      github2pypi
  3. 7 45
      setup.py

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "github2pypi"]
+	path = github2pypi
+	url = https://github.com/wkentaro/github2pypi.git

+ 1 - 0
github2pypi

@@ -0,0 +1 @@
+Subproject commit 9fddf5b4d6001315d31ae968fbb78a7da24a6389

+ 7 - 45
setup.py

@@ -9,6 +9,8 @@ import shlex
 import subprocess
 import sys
 
+import github2pypi
+
 
 PY3 = sys.version_info[0] == 3
 PY2 = sys.version_info[0] == 2
@@ -94,50 +96,10 @@ if sys.argv[1] == 'release':
     sys.exit(0)
 
 
-def get_long_description():
-    f = open('README.md')
-
-    lines = []
-    for line in f:
-
-        def repl(match):
-            if not match:
-                return
-
-            url = match.group(1)
-            if url.startswith('http'):
-                return match.group(0)
-
-            url_new = (
-                'https://github.com/wkentaro/labelme/blob/master/{}'
-                .format(url)
-            )
-            if re.match(r'.*[\.jpg|\.png]$', url_new):
-                url_new += '?raw=true'
-
-            start0, end0 = match.regs[0]
-            start, end = match.regs[1]
-            start -= start0
-            end -= start0
-
-            res = match.group(0)
-            res = res[:start] + url_new + res[end:]
-            return res
-
-        patterns = [
-            r'!\[.*?\]\((.*?)\)',
-            r'<img.*?src="(.*?)".*?/>',
-            r'\[.*?\]\((.*?)\)',
-            r'<a.*?href="(.*?)".*?>',
-        ]
-        for pattern in patterns:
-            line = re.sub(pattern, repl, line)
-
-        lines.append(line)
-
-    f.close()
-
-    return ''.join(lines)
+with open('README.md') as f:
+    long_description = github2pypi.replace_url(
+        slug='wkentaro/imgviz', content=f.read()
+    )
 
 
 setup(
@@ -145,7 +107,7 @@ setup(
     version=version,
     packages=find_packages(),
     description='Image Polygonal Annotation with Python',
-    long_description=get_long_description(),
+    long_description=long_description,
     long_description_content_type='text/markdown',
     author='Kentaro Wada',
     author_email='www.kentaro.wada@gmail.com',