-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
372db50
commit e4d389d
Showing
2 changed files
with
2 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,4 @@ | ||
"""The setup and installation script.""" | ||
|
||
import io | ||
import re | ||
|
||
from setuptools import setup | ||
|
||
# We want to use our README.md as project description. | ||
# However, we must fix all the references inside. | ||
with io.open("README.md", | ||
"rt", encoding='utf-8-sig') as reader: | ||
old_lines = reader.readlines() | ||
|
||
# It seems that the markdown parser does not auto-generate anchors. This means | ||
# that we need to fix all references following the pattern `[xxx](#12-hello)` | ||
# to `[xxx]({docu_url#hello)`, where `docu_url` is the url of our | ||
# documentation. We do this with a regular expression `regex_search`. | ||
new_lines = [] | ||
in_code: bool = False # we only process non-code lines | ||
# detects strings of the form [xyz](#123-bla) and gives \1=xyz and \2=bla | ||
regex_search = re.compile("(\\[.+?])\\(#\\d+-(.+?)\\)") | ||
regex_repl: str = \ | ||
"\\1(https://thomasweise.github.io/latexgit_py/index.html#\\2)" | ||
license_old: str = \ | ||
"https://github.com/thomasWeise/latexgit_py/blob/main/LICENSE" | ||
license_new: str = \ | ||
"https://thomasweise.github.io/latexgit_py/LICENSE.html" | ||
|
||
for line in old_lines: | ||
line = line.rstrip() | ||
if in_code: | ||
if line.startswith("```"): | ||
in_code = False # toggle to non-code | ||
else: | ||
if line.startswith("```"): | ||
in_code = True # toggle to code | ||
else: # fix all internal urls | ||
# replace links of the form "#12-bla" to "#bla" | ||
line = re.sub(regex_search, regex_repl, line) | ||
line = line.replace(license_old, license_new) | ||
new_lines.append(line) | ||
|
||
# Now we can use the code in the setup. | ||
setup(long_description="\n".join(new_lines), | ||
long_description_content_type="text/markdown") | ||
setup() |