Skip to content

Commit d7d12d5

Browse files
author
gon
committed
libsodium-recipe-update to url
1 parent 518216c commit d7d12d5

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

pythonforandroid/recipes/libsodium/__init__.py

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,27 @@
11
from pythonforandroid.recipe import Recipe
22
from pythonforandroid.util import current_directory
3-
from pythonforandroid.logger import shprint, error
3+
from pythonforandroid.logger import shprint
44
from multiprocessing import cpu_count
5-
from urllib.request import urlopen
6-
from os import environ
7-
import json
85
import sh
9-
10-
11-
def get_libsodium_urls():
12-
"""
13-
Retrieves the download url formats for libsodium versions
14-
15-
Returns dict with version to url format mappings
16-
"""
17-
releases_url = 'https://api.github.com/repos/jedisct1/libsodium/releases'
18-
with urlopen(releases_url) as response:
19-
response = response.read().decode()
20-
releases = json.loads(response)
21-
urls = {}
22-
for release in releases:
23-
version = release['name']
24-
file_name = 'libsodium-{}.tar.gz'.format(version)
25-
for asset in release['assets']:
26-
if asset['name'] == file_name:
27-
download_url = asset['browser_download_url']
28-
urls[version] = download_url.replace(version, '{version}')
29-
break
30-
return urls
31-
32-
try:
33-
URLS = get_libsodium_urls()
34-
except:
35-
message = 'failed to get libsodium url formats'
36-
error(message)
37-
raise Exception(message)
6+
from packaging import version as packaging_version
387

398

409
class LibsodiumRecipe(Recipe):
41-
env_version = environ.get('VERSION_libsodium')
42-
if not env_version:
43-
version = '1.0.16'
44-
else:
45-
version = env_version
46-
try:
47-
url = URLS[version]
48-
except KeyError:
49-
message = "libsodium version '{}' not found".format(version)
50-
error(message)
51-
raise Exception(message)
10+
version = '1.0.16'
11+
url = 'https://github.com/jedisct1/libsodium/releases/download/{}/libsodium-{}.tar.gz'
5212
depends = []
5313
patches = ['size_max_fix.patch']
5414
built_libraries = {'libsodium.so': 'src/libsodium/.libs'}
5515

16+
@property
17+
def versioned_url(self):
18+
asked_version = packaging_version.parse(self.version)
19+
recipe_version = packaging_version.parse(self._version)
20+
if asked_version > recipe_version:
21+
return self._url.format(self.version + '-RELEASE', self.version)
22+
else:
23+
return self._url.format(self.version, self.version)
24+
5625
def build_arch(self, arch):
5726
env = self.get_recipe_env(arch)
5827
with current_directory(self.get_build_dir(arch.arch)):

0 commit comments

Comments
 (0)