Skip to content

Commit fe9e4ad

Browse files
committed
Collect pandoc urls from github api
1 parent 7111c16 commit fe9e4ad

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

pypandoc/pandoc_download.py

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
import json
33
import logging
44
import os
55
import os.path
@@ -42,36 +42,29 @@ def _get_pandoc_urls(version="latest"):
4242
:return: str version: actual pandoc version. (e.g. "latest" will be resolved to the actual one)
4343
"""
4444
# url to pandoc download page
45-
url = "https://github.com/jgm/pandoc/releases/" + \
46-
("tag/" if version != "latest" else "") + version
45+
url = "https://api.github.com/repos/jgm/pandoc/releases/" + \
46+
("tags/" if version != "latest" else "") + version
4747
# try to open the url
4848
try:
4949
response = urlopen(url)
50-
version_url_frags = response.url.split("/")
51-
version = version_url_frags[-1]
5250
except urllib.error.HTTPError as e:
5351
raise RuntimeError("Invalid pandoc version {}.".format(version))
54-
return
55-
# read the HTML content
56-
response = urlopen(f"https://github.com/jgm/pandoc/releases/expanded_assets/{version}")
57-
content = response.read()
58-
# regex for the binaries
59-
uname = platform.uname()[4]
60-
processor_architecture = "arm" if uname.startswith("arm") or uname.startswith("aarch") else "amd"
61-
regex = re.compile(fr"/jgm/pandoc/releases/download/.*(?:{processor_architecture}|x86|mac).*\.(?:msi|deb|pkg)")
62-
# a list of urls to the binaries
63-
pandoc_urls_list = regex.findall(content.decode("utf-8"))
52+
# read the json response
53+
data = json.loads(response.read())
6454
# actual pandoc version
65-
version = pandoc_urls_list[0].split('/')[5]
55+
version = data["tag_name"]
6656
# dict that lookup the platform from binary extension
6757
ext2platform = {
6858
'msi': 'win32',
6959
'deb': 'linux',
7060
'pkg': 'darwin'
71-
}
72-
# parse pandoc_urls from list to dict
73-
# py26 don't like dict comprehension. Use this one instead when py26 support is dropped
74-
pandoc_urls = {ext2platform[url_frag[-3:]]: (f"https://github.com{url_frag}") for url_frag in pandoc_urls_list}
61+
}
62+
# collect pandoc urls from json content
63+
pandoc_urls = dict()
64+
for asset in data["assets"]:
65+
pf = ext2platform.get(asset["name"][-3:])
66+
if pf:
67+
pandoc_urls[pf] = asset["browser_download_url"]
7568
return pandoc_urls, version
7669

7770

0 commit comments

Comments
 (0)