33from setuptools import setup , find_packages
44import os
55import re
6+ from pathlib import Path
7+ from urllib .parse import urljoin , urlsplit , urlunsplit
68
79# source path for the class' package. Amend if necessary
810PACKAGE_SOURCE_DIR = "path/to/class/directory"
911
1012# Amend this section with your custom data
11- PACKAGE_NAME = "package-name"
13+ PACKAGE_NAME = "package-name"
1214DESCRIPTION = "package-description"
1315AUTHOR = "author-name"
1416AUTHOR_EMAIL = "author@email.com"
2325 "Development Status :: 4 - Beta" ,
2426 "Framework :: Robot Framework" ,
2527]
26- INSTALL_REQUIRES = [
27- "package_1" ,
28- "package_2"
28+ INSTALL_REQUIRES = ["package_1" , "package_2" ]
29+ KEYWORDS = [
30+ "Notifications" ,
31+ "Notification Service" ,
32+ "Push Notifications" ,
33+ "Notifier" ,
34+ "Alerts" ,
35+ "Robot Framework" ,
2936]
30- KEYWORDS = [
31- "Notifications" ,
32- "Notification Service" ,
33- "Push Notifications" ,
34- "Notifier" ,
35- "Alerts" ,
36- "Robot Framework"
37- ]
38- LICENSE = "GNU General Public License v3 (GPLv3)"
37+ LICENSE = "GNU General Public License v3 (GPLv3)"
38+
3939
4040def running_in_a_github_action ():
4141 return os .getenv ("GITHUB_ACTIONS" ) == "true"
4242
43+
44+ # Absolute URL to base repo; change this setting!
45+ BASE_URL = "https://github.com/joergschultzelutter/MY_REPO_NAME/blob/master/"
46+
47+ # Markdown link recognition (will not work on image links)
48+ LINK_RE = re .compile (r"(?<!\!)\[(?P<text>[^\]]+)\]\((?P<href>[^)\s]+)\)" )
49+
50+
51+ def is_absolute_url (href : str ) -> bool :
52+ return href .startswith (("http://" , "https://" , "mailto:" ))
53+
54+
55+ def is_root_relative (href : str ) -> bool :
56+ return href .startswith ("/" )
57+
58+
59+ def looks_like_md (href : str ) -> bool :
60+ path = urlsplit (href ).path
61+ return path .lower ().endswith (".md" )
62+
63+
64+ def to_absolute_md (href : str ) -> str :
65+ parts = urlsplit (href ) # (scheme, netloc, path, query, fragment)
66+ abs_url = urljoin (BASE_URL , parts .path )
67+ return urlunsplit (
68+ urlsplit (abs_url )._replace (query = parts .query , fragment = parts .fragment )
69+ )
70+
71+
72+ def rewrite_md_links (md_text : str ) -> str :
73+ def repl (m : re .Match ) -> str :
74+ text = m .group ("text" )
75+ href = m .group ("href" )
76+
77+ if (
78+ not is_absolute_url (href )
79+ and not is_root_relative (href )
80+ and looks_like_md (href )
81+ ):
82+ href = to_absolute_md (href )
83+
84+ return f"[{ text } ]({ href } )"
85+
86+ return LINK_RE .sub (repl , md_text )
87+
88+
89+ def transform_file (filename : str ) -> str :
90+ in_path = Path (filename )
91+ if not in_path .exists ():
92+ raise FileNotFoundError (filename )
93+
94+ content = in_path .read_text (encoding = "utf-8" )
95+ transformed = rewrite_md_links (content )
96+ return transformed
97+
98+
4399if __name__ == "__main__" :
44- # get README and use it as long description
45- with open ("README.md" , "r" ) as fh :
46- LONG_DESCRIPTION = fh .read ()
100+
101+ LONG_DESCRIPTION = transform_file ("README.md" )
47102
48103 GITHUB_PROGRAM_VERSION = ""
49-
104+
50105 if running_in_a_github_action ():
51106 # Only run this branch if we are part of a Github action. Otherwise, just skip
52107 # it as we won't be able to get the version info from Github anyway
@@ -56,9 +111,11 @@ def running_in_a_github_action():
56111 if not GITHUB_PROGRAM_VERSION :
57112 raise ValueError ("Did not receive release label version info from GitHub" )
58113 else :
59- if len (GITHUB_PROGRAM_VERSION == 0 ):
60- raise ValueError ("Manual run requires a manually set GITHUB_PROGRAM_VERSION; change setup.py accordingly" )
61-
114+ if len (GITHUB_PROGRAM_VERSION ) == 0 :
115+ raise ValueError (
116+ "Manual run requires a manually set GITHUB_PROGRAM_VERSION; change setup.py accordingly"
117+ )
118+
62119 # Main setup branch
63120 setup (
64121 name = PACKAGE_NAME ,
@@ -76,4 +133,3 @@ def running_in_a_github_action():
76133 install_requires = INSTALL_REQUIRES ,
77134 keywords = KEYWORDS ,
78135 )
79-
0 commit comments