comparison flatpak/build_manifest.py @ 157:150085e39072

flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
author Goffi <goffi@goffi.org>
date Tue, 23 Jul 2019 21:57:41 +0200
parents 0a92bb60db12
children 4fe61dcd856e
comparison
equal deleted inserted replaced
156:0a92bb60db12 157:150085e39072
230 def get_python_package(package_name, step_name=None, step_message=None, with_pre=False, 230 def get_python_package(package_name, step_name=None, step_message=None, with_pre=False,
231 version=None): 231 version=None):
232 """Generate module for a Python package 232 """Generate module for a Python package
233 233
234 @param package_name(str, list[str]): name of the Python package 234 @param package_name(str, list[str]): name of the Python package
235 use list of str to get several packages at once 235 use list of str to get several packages at once.
236 A (name, version) tuple (or any size 2 iterable) can be used to force version of a
237 package.
238 If package is a list with iterables, it will be modified in place to keep only the
239 name as string. This is because version is not needed anymore after that, but
240 name is still used to remove dependencies already installed with setup
241 requirements.
236 @param step_name(None, str): name of the step, None to use package_name 242 @param step_name(None, str): name of the step, None to use package_name
237 @param step_message(None, str): message of the step (None to use default one) 243 @param step_message(None, str): message of the step (None to use default one)
238 use empty string to disable it 244 use empty string to disable it
239 @param with_pre(bool): if True retrieve also pre-releases 245 @param with_pre(bool): if True retrieve also pre-releases
240 @param version(str, None): indicate the version of the package to download 246 @param version(str, None): indicate the version of the package to download
248 cache = get_cache(step_name) 254 cache = get_cache(step_name)
249 if cache is not None: 255 if cache is not None:
250 return cache 256 return cache
251 package_names = [package_name] if single else package_name 257 package_names = [package_name] if single else package_name
252 data = [] 258 data = []
253 for name in package_names: 259
260 for idx, name in enumerate(package_names):
261 if not isinstance(name, str):
262 if version is not None:
263 raise ValueError(
264 "forced version can't be used with packages versions (i.e. tuples)")
265 name, forced_version = name
266 package_names[idx] = name
267 else:
268 forced_version = version
254 r = requests.get(f"https://pypi.org/pypi/{name}/json") 269 r = requests.get(f"https://pypi.org/pypi/{name}/json")
255 r.raise_for_status() 270 r.raise_for_status()
256 271
257 releases_data = [] 272 releases_data = []
258 for version_raw, release_data in r.json()["releases"].items(): 273 for version_raw, release_data in r.json()["releases"].items():
259 if version is not None and version != version_raw: 274 if forced_version is not None and forced_version != version_raw:
260 continue 275 continue
261 release_version = parse_version(version_raw) 276 release_version = parse_version(version_raw)
262 if release_version.is_prerelease and not with_pre: 277 if release_version.is_prerelease and not with_pre:
263 continue 278 continue
264 releases_data.append((release_version, release_data)) 279 releases_data.append((release_version, release_data))