Mercurial > sat_docs
annotate 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 |
rev | line source |
---|---|
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 import tempfile |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 import subprocess |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from pathlib import Path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from typing import List |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from dataclasses import dataclass |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 import hashlib |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from ftplib import FTP |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 from urllib.parse import urlparse |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
11 from textwrap import dedent |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 import sys |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 import os |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 import json |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 import time |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 import argparse |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 import shutil |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 from packaging.version import parse as parse_version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import requests |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
20 from lxml import etree |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 CACHE_LIMIT = 3600 * 24 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 PYTHON_DEP_OVERRIDE = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 "lxml": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 "build-commands": [ |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
27 # --optimize=1 make the build fail, to be tried again once moved to Python3 |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
28 # "python2 ./setup.py install --prefix=${FLATPAK_DEST} --optimize=1" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
29 "python2 ./setup.py install --prefix=${FLATPAK_DEST}" |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 "build-options": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 "env": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 "XSLT_CONFIG": "pkg-config libxslt" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "dbus-python": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 "python2 setup.py build", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "python2 setup.py install --prefix=${FLATPAK_DEST}", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 "kivy": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 "post-install": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 # this file is not copied normally when installing with |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 # `python2 setup.py install`. |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 # TODO: report upstream |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 "cp kivy/setupconfig.py /app/lib/python2.7/site-packages/Kivy-*.egg/kivy/" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 }, |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
51 "pillow": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
52 "build-options": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
53 "arch": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
54 "x86_64": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
55 "ldflags": "-L/usr/lib/x86_64-linux-gnu" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
56 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
57 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
58 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
59 }, |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 PYTHON_DEP_REQUIREMENTS_UPDATE = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 # service-identity is not seen as a twisted requirement, so it's sometimes misplaced |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 'twisted': ['service-identity'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 PYTHON_SETUP_REQUIREMENTS = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 'setuptools', # to have an up-to-date version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 'setuptools_scm', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 'docutils', # needed my m2r |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 'mistune', # needed my m2r |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 'm2r', # needed by automat |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 DEFAULT_MANIFEST = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 "runtime": "org.freedesktop.Platform", |
151
6f8c849daf2a
flatpak (build_manifest): updated org.freedesktop.Platform runtime version:
Goffi <goffi@goffi.org>
parents:
150
diff
changeset
|
74 "runtime-version": "18.08", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 "sdk": "org.freedesktop.Sdk", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 "command": "sat_wrapper", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 "finish-args": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 "--socket=session-bus", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 "--share=network", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 "--filesystem=home" |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
81 ], |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
82 "modules": [ |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
83 { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
84 "name": "python", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
85 # we use the same options as the ones of Python 2 from SDK |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
86 "config-opts": [ |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
87 "--enable-deterministic-archives", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
88 "--disable-static", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
89 "--enable-shared", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
90 "--with-ensurepip=yes", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
91 "--with-system-expat", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
92 "--with-system-ffi", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
93 "--enable-loadable-sqlite-extensions", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
94 "--with-dbmliborder=gdbm", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
95 "--enable-unicode=ucs4", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
96 ], |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
97 "post-install": [ |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
98 # stipping won't work without this |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
99 "chmod 644 /app/lib/libpython2.7.so.1.0" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
100 ], |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
101 "sources": [ |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
102 { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
103 "type": "archive", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
104 "url": "https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tar.xz", |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
105 "sha256": "f222ef602647eecb6853681156d32de4450a2c39f4de93bd5b20235f2e660ed7" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
106 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
107 ] |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
108 } |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 SHOW_REQUIRES_HEADER = 'Requires: ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 SETTINGS_KEY = '_build_settings' |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
113 APPDATA_RELEASE_DEV_TEXT = dedent("""\ |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
114 This is a development version, used as a preview. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
115 Please note that it is incomplete and it probably contains bugs. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
116 """) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
117 OVERWRITE_WARNING = "{} already exists, do you want to overwrite it (y/N)? " |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 @dataclass |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 class Package: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 name: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 version: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 hash_: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 url: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 requirements: List[str] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 def __hash__(self): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 return hash(self.name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 def print_step(step): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 print() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 print("┌" + "─" * (len(step) + 2) + "┐") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 print("│ {} │".format(step)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 print("└" + "─" * (len(step) + 2) + "┘") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 print() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 def parse_args(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 parser = argparse.ArgumentParser( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 description='Flatpak manifest builder for Salut à Toi') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 build_group = parser.add_argument_group('building', 'options used to generate the manifest') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 export_group = parser.add_argument_group('export', 'otions used to building files') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 # build group |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 build_group.add_argument('-f', '--force', action="store_true", |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
149 help="force overwritting of existing manifest and appdata file") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 build_group.add_argument('--ignore-cache', action='append', default=[], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 help='ignore the cache of this step ("all" to ignore all caches)') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 build_group.add_argument( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 '--deps-dir', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 help="use this directory to build_group python dependencies (it won't be deleted at " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 "the end, useful when you want to re-use it and avoir re-downloading)") |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
156 # build_group.add_argument('--no-binary', help="don't use binary packages") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 # export group |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 export_group.add_argument('-s', '--symlink', choices=['no', 'all', 'cache'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 default='no', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 help='"no" to copy all files, "all" to symlink all files, "cache" to copy files ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 'and symlink only cache (default: "no")') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 export_group.add_argument('-F', '--force-export', action='store_true', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 help='force overwritting of existing files/symlinks when exporting (DEFAULT: ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 'existing files are skipped)') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 export_group.add_argument('-e', '--export', type=Path, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 help="export build files to this directory (DEFAULT: don't export files)") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 # common |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 parser.add_argument('name', type=str, help="name of the package to build_group") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 parser.add_argument('version', type=str, help="version of the package to build_group") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 args = parser.parse_args() |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
174 # FIXME: no_binary is currently not managed because version parser doesn't handle |
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
175 # wheels |
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
176 args.no_binary = True |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 if 'all' in args.ignore_cache and len(args.ignore_cache) != 1: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 parser.error('"all" cannot be used with step names in --ignore-cache, ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 'use it alone') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 if args.export is not None and not args.export.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 parser.error(f"{args.export} is not a directory!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 return args |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 ## useful methods ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 def get_cache(name): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 """Retrieve cache for a step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 cache will be ignored if too old, or explicitly ignored by user |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 @param name(str): name of the step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 @return (object): cached data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 # name of the cache without prefix, mainly used for python_deps |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 shortname = name.split('__', 1)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 if shortname in args.ignore_cache or 'all' in args.ignore_cache: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 print(f"ignoring cache for {shortname}") |
154
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
202 if shortname in args.ignore_cache: |
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
203 args.ignore_cache.remove(shortname) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 cache_name = cache[name] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 cache_updated = cache_name['updated'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 except KeyError: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 if time.time() - cache_updated > CACHE_LIMIT: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 print(f"cache for {name} is too old, we won't use it") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 print(f"cache found for {shortname}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 return cache_name['data'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 def set_cache(name, data): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 """Update cache for a step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 @param name(str): name of the step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 @param data(object): data to cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 cache_name = cache.setdefault(name, {}) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 cache_name['updated'] = time.time() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 cache_name['data'] = data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 with cache_path.open('w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 json.dump(cache, f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 def get_python_package(package_name, step_name=None, step_message=None, with_pre=False, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 version=None): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 """Generate module for a Python package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 @param package_name(str, list[str]): name of the Python package |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
235 use list of str to get several packages at once. |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
236 A (name, version) tuple (or any size 2 iterable) can be used to force version of a |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
237 package. |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
238 If package is a list with iterables, it will be modified in place to keep only the |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
239 name as string. This is because version is not needed anymore after that, but |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
240 name is still used to remove dependencies already installed with setup |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
241 requirements. |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 @param step_name(None, str): name of the step, None to use package_name |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 @param step_message(None, str): message of the step (None to use default one) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 use empty string to disable it |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 @param with_pre(bool): if True retrieve also pre-releases |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 @param version(str, None): indicate the version of the package to download |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 if None, the most recent version compativle with `with_pre` will be used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 single = isinstance(package_name, str) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 if step_name is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 step_name = package_name if single else ' - '.join(package_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 if step_message != "": |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 print_step(step_message or f"retrieving latest version of {package_name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 package_names = [package_name] if single else package_name |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 data = [] |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
259 |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
260 for idx, name in enumerate(package_names): |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
261 if not isinstance(name, str): |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
262 if version is not None: |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
263 raise ValueError( |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
264 "forced version can't be used with packages versions (i.e. tuples)") |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
265 name, forced_version = name |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
266 package_names[idx] = name |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
267 else: |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
268 forced_version = version |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 r = requests.get(f"https://pypi.org/pypi/{name}/json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 releases_data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 for version_raw, release_data in r.json()["releases"].items(): |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
274 if forced_version is not None and forced_version != version_raw: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 release_version = parse_version(version_raw) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 if release_version.is_prerelease and not with_pre: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 releases_data.append((release_version, release_data)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 # we sort releases by version to be sure to have latests one |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 releases_data.sort(key=lambda d: d[0]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 release_version, release_data = releases_data[-1] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 package = next(r for r in release_data if r["packagetype"] == "sdist") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 except (IndexError, StopIteration): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 raise RuntimeError(f"Can't find a matching package for {name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 print(f"{name} {release_version} will be used") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 "name": name, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 "url": package["url"], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 "sha256": package["digests"]["sha256"], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 data.append(dep_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 def file_upload(filename, dest="/app/bin", src=None, replace=None, use_install=False): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 """Generate manifest modules to upload a local file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 @param filename(str): name of the local file to upload |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 Note that it will be overwritted if replace is used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 @param dest(str, Path): path where the file must be installed in the container |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 @param src(str, None): when replace is used, name of the source file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 @param replace(dict, None): mapping of text to replace |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 Use when file must be dynamicly adapted to the container, note that src must be |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 set to the name of the template file if this is used. |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 e.g. {'##COMMAND##', 'cagou'} will replace all '##COMMAND##' in filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 by 'cagou' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 @param use_install(bool): if True, install file with `install src dest` |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 else, use `mv src dest` |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 @return (list(dict)): modules to add to the manifest |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 assert isinstance(filename, str) and '/' not in filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 print_step(f"generating {filename} module") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 # no cache for this one, to be sure to have always latest version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 filename = Path(filename) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 if src is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 file_to_test = filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 src = Path(src) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 file_to_test = src |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 if not file_to_test.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 raise RuntimeError( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 f"{file_to_test} is missing, it is needed to build the manifest!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 if replace: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 if src is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 raise ValueError( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 '"src" must be set to name of template file if replace is used') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 print(f'doing replacement in template "{src}" to dest "{filename}"') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 # there are strings to replace, we read file, do the changes and dump the |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 # result in <filename> |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 with open(src) as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 buff = f.read() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 for old, new in replace.items(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 buff = buff.replace(old, new) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 with open(filename, 'w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 f.write(buff) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 if src is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 raise ValueError('"src" must not be used if replace is not used') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 with filename.open('rb') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 hash_ = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 dest = Path(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 "name": str(filename), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 "type": "file", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 "path": str(filename), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 "sha256": hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 build_commands = dep_data['build-commands'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 if use_install: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 build_commands.append(f"install -Dv {filename} {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 if dest.as_posix() not in ('/app', '/app/bin'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 # just in case the destination directory doesn't exist |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 build_commands.append(f"mkdir -p {dest.parent}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 build_commands.append(f"mv -v {filename} {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 return [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 def file_from_url(url, dest=None, step_name=None, step_message=None): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 """Generate manifest modules for a file either on a http(s) url or local |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 @param url(str): url of the file to use, or local path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 if it starts with http, url will be used, else file_upload(url) will be used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 @param dest(str, None): path were the file should be copied |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 parsed = urlparse(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 if not parsed.scheme: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 return file_upload(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 if not parsed.scheme.startswith('http'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 raise NotImplementedError ( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 f'we can\'t use the URL "{url}", the scheme "{parsed.scheme}" is not managed') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 filepath = Path(parsed.path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 stem = filepath.stem |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 if step_name is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 # we use this name to easily ignore cache (with stem) while avoiding |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 # conflict if we have 2 URLs with the same stem |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 step_name = f"{stem}__{url}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 if step_message is None: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
417 step_message = f"generating module for {stem}" |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 print_step(step_message) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 r = requests.get(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 file_hash = hashlib.sha256(r.content).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 dep_data = {"name": stem} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 if dest is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 dest = Path(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 dep_data.update({ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 'buildsystem': 'simple', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 'build-commands':[ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 f'mkdir -p {dest.parent}', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 f'mv "{filepath.name}" "{dest}"', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 }) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 dep_data['sources'] = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
442 "type": "file", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 "url": url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 "sha256": file_hash, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 data = [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 def get_requirements(pip, package_name): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 """Retrieve requirements for an installed python package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 @param pip(Path): path to pip executable to use |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 package must be installed in the environment of this pip |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 @param package_name(str): name of the package to retrieve |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 @return(list[str]): found requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 show_cplted = subprocess.run([pip, "show", package_name], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 capture_output=True, text=True) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 show_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 lines = show_cplted.stdout.split('\n') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 requirement_raw = next(l for l in lines if l.startswith(SHOW_REQUIRES_HEADER)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 requirement_raw = requirement_raw[len(SHOW_REQUIRES_HEADER):] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 requirements = [canonical(p) for p in requirement_raw.split(',') if p.strip()] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 requirements_update = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 canonical(r) for r in PYTHON_DEP_REQUIREMENTS_UPDATE.get(package_name, [])] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 new_requirements = set(requirements_update).difference(requirements) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 if new_requirements: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 print("adding extra requirements to {}: {}".format( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 package_name, ', '.join(new_requirements))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 requirements.extend(new_requirements) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 return requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 def resolve_requirements(package, deps_map, deps, indent=0): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 """Recursively resolve requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 @param package(Package): retrieve dependencies of this package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 @param deps_map(dict): map from dependency name to Package instance |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 @param deps(list[package]): ordered dependencies |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 this list is updated in place |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 @param indent(int): use internally to print dependencies tree |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 if package in deps: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 return |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 print(" " * indent + package.name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 reqs_data = [deps_map[r] for r in package.requirements] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 for data in reqs_data: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 resolve_requirements(data, deps_map, deps, indent+1) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 deps.append(package) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
499 def get_hg_id_date(path): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
500 """Get short identifier and date of current commit from given Mercurial repository |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
501 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
502 version is retrieve with `hg id`, a "+" is appended after shortrev if it has |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
503 been modified. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
504 @param path(str, Path): path to the repository |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
505 @return(tuple(str, date)): found revision + iso date |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
506 """ |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
507 hg_cplted = subprocess.run( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
508 ["hg", "id", "--template", "{id|short}{dirty}\n{date|isodate}", path], |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
509 capture_output=True, text=True) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
510 hg_cplted.check_returncode() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
511 return hg_cplted.stdout.split('\n') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
512 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
513 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 def get_cache_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 """Return path to directory to use for cache""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 return Path(f"cache_{app_id}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 def canonical(name): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 """Get canonical name of a package""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 return name.lower().replace('_', '-').strip() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 modules = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 cache_path = Path.home() / Path('.cache/sat_flatpak_cache.json') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 if not cache_path.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 cache = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 with cache_path.open() as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 cache = json.load(f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
532 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 ## steps ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 def get_libxslt(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 """Generate manifest module to install libxslt (needed for lxml)""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 step_name = 'libxslt' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
538 print_step("retrieving latest version of libxslt") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
539 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
540 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
541 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 ftp = FTP("xmlsoft.org") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 ftp.login() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 ftp.cwd("libxml2") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 libxslt_archives = [l for l in ftp.nlst() if 'xslt' in l |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 and l.endswith('tar.gz') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 and 'git' not in l |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
549 and 'rc' not in l] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 latest_libxslt = libxslt_archives[-1] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 print(f"latest libxslt found: {latest_libxslt}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 with tempfile.TemporaryDirectory() as tmp_dirname: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 tmp_dir = Path(tmp_dirname) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
555 file_path = tmp_dir / latest_libxslt |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 with file_path.open('wb+') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 ftp.retrbinary('RETR ' + latest_libxslt, f.write) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 f.seek(0) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
559 libxslt_hash = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
560 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
561 ftp.quit() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 print(f"libxstl hash: {libxslt_hash}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 data = [{ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 "name": "libxslt", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 "url": f"ftp://xmlsoft.org/libxml2/{latest_libxslt}", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
571 "sha256": libxslt_hash, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
574 }] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
579 def get_python_deps(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
580 """Generate manifest modules for python dependencies of main package""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 step_name = f'python_deps__{app_id}' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 print_step("retrieving python dependencies") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
583 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
586 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 with tempfile.TemporaryDirectory() as tmp_dirname: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 if args.deps_dir is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 # we ignore the created temporary directory is we have an other one specified |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 tmp_dirname = args.deps_dir |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 tmp_dir = Path(tmp_dirname) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 env_dir = tmp_dir / 'env' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 pip = env_dir / 'bin' / 'pip' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
594 download_dir = tmp_dir / 'archives' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
595 if download_dir.exists() and env_dir.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 print("dependencies are already downloaded and packages are already " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 "installed") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 download_dir.mkdir() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 print(f"working in temporary directory {tmp_dirname}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
601 venv_cplted = subprocess.run(["/usr/bin/env", "virtualenv2", env_dir]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 venv_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 print("\ndownloading packages") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
604 command_args = [pip, "download", "-d", download_dir, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
605 "--progress-bar", "emoji"] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
606 if args.no_binary: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
607 command_args.extend(["--no-binary", ":all:"]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
608 command_args.append(main_package_source) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
609 down_cplted = subprocess.run(command_args) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
610 down_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
611 print("\ninstalling package\n") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 # we install package to have a good map of requirements, pypi metadata |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 # are incomplete. Packages should be retrieved from pip cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 inst_cplted = subprocess.run([pip, "install", main_package_source]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 inst_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
617 print_step("analyzing python dependencies") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 deps_map = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
619 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
620 for archive_path in download_dir.iterdir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 name, right_part = archive_path.name.rsplit('-', 1) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
622 name_canonical = canonical(name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
623 if right_part.endswith('.tar.gz'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 version = right_part[:-7] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 elif right_part.endswith('.tar.bz2'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 version = right_part[:-8] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 elif right_part.endswith('.zip'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 version = right_part[:-4] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
629 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 raise ValueError( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
631 f"Archive are supposed to be .tar.gz, .tar.bz2 or .zip archives, but " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 f"file found is {archive_path.name}, did something change on Pypy?") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
633 with open(archive_path, "rb") as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 dep_hash = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 r = requests.get(f"https://pypi.org/pypi/{name}/{version}/json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 dep_json = r.json() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 release_json = dep_json["releases"][version] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 version_json = next(v for v in release_json |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 if v['digests']['sha256'] == dep_hash) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 except IndexError: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 raise ValueError(f"Can't find the version we downloaded for {name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
644 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 requirements = get_requirements(pip, name_canonical) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 dep = Package(name=name_canonical, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 version=version, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 hash_=dep_hash, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
650 url=version_json['url'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 requirements=requirements, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 ) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
653 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 deps_map[name_canonical] = dep |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 print(f"found dependency: {dep.name} {dep.version}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 |
155
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
657 print_step("ordering dependencies") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 |
155
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
659 requirements = get_requirements(pip, main_package) |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
660 main_pack = Package(name=main_package, |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
661 version=args.version, |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
662 hash_="", |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
663 url="", |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
664 requirements=requirements, |
5af7c3d4fab2
flatpak (build_manifest): fixed ordering when a one-short temporary directory is used
Goffi <goffi@goffi.org>
parents:
154
diff
changeset
|
665 ) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 deps = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 print("resolving requirements\n") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 resolve_requirements(main_pack, deps_map, deps) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 missing_deps = set(deps_map.values()).difference(deps) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 if missing_deps: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 print("\n/!\\ some dependencies are missing this should not happen! " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 "Adding them\n") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 print("additional requirements") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 for pack in missing_deps: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 resolve_requirements(pack, deps_map, deps) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 # we remove deps already installed with PYTHON_SETUP_REQUIREMENTS |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 for name in PYTHON_SETUP_REQUIREMENTS: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 package_data = deps_map.get(name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 if package_data is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 deps.remove(package_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 print(f"removed {name} which is already a setup requirement") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 # main package is installed at the end |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 deps.remove(main_pack) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 print("\npackages are now ordered: {}".format(", ".join(d.name for d in deps))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 print("\nwe now generate modules for python dependencies") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 version_force = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 canonical(n): v |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
694 for n,v in build_settings.get('python_deps_version_force', {}).items() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
695 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
697 for dep in deps: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 version_forced = version_force.get(dep.name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
699 if version_forced == 'pre-release': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
700 print(f"using pre-release version for {dep.name} as requested in build " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
701 "settings") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
702 dep_data = get_python_package(dep.name, step_message='', with_pre=True)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
703 elif version_forced is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 print(f"using version {version_forced} for {dep.name} as requested in " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 "build settings") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 dep_data = get_python_package(dep.name, step_message='', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 version=version_forced)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
708 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
709 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
710 "name": dep.name, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
711 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
712 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
713 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
714 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
717 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
718 "url": dep.url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
719 "sha256": dep.hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
720 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
721 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
723 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
724 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
726 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
727 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 if dep.name in PYTHON_DEP_OVERRIDE: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
729 print(f"applying override for {dep.name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
730 override = PYTHON_DEP_OVERRIDE[dep.name] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
731 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
732 # key suffixed with "_extend" won't replace the data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
733 for key in list(override.keys()): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 if key.endswith('_extend'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
735 real_key = key[:-7] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
736 extend_data = override.pop(key) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
737 if real_key == 'sources': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
738 for item_data in extend_data: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 # we look for missing hashes and add them |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
740 if (item_data.get('type') in ('file', 'patch') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 and 'sha256' not in item_data): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
742 with open(item_data['path'], 'rb') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 hash_ = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
744 item_data['sha256'] = hash_ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
745 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
746 dep_data.setdefault(real_key, []).extend(extend_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
747 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
748 dep_data.update(override) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
749 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
750 data.append(dep_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
751 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
754 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
755 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
756 def cache_from_repos(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
757 """Get and cache locally a repository and returns cache path""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 print_step("retrieving code from repository") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
759 dev_repos = build_settings['dev_repos'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
760 repos_type = dev_repos.get('type', 'hg') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
761 if repos_type != 'hg': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
762 raise NotImplementedError("only Mercurial is managed so far") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
763 url = dev_repos['url'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
764 dest_path = get_cache_dir() / main_package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
765 dest_path.mkdir(parents=True, exist_ok=True) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
766 if (dest_path / '.hg').is_dir(): |
156
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
767 print("code is already in cache, updating") |
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
768 hg_cplted = subprocess.run(["hg", "pull", "-u", "--cwd", dest_path]) |
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
769 hg_cplted.check_returncode() |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
770 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
771 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
772 print(f"retrieving code from repository {url} into {dest_path}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
773 hg_cplted = subprocess.run(["hg", "clone", url, dest_path]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
774 hg_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
775 except Exception as e: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
776 shutil.rmtree(dest_path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
777 raise e |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
778 return dest_path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
779 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
780 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
781 def get_repos_module(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
782 """Generate manifest module for the repository""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
783 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
784 "name": main_package, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
785 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
786 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
787 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
788 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
789 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
790 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
791 "type": "dir", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
792 "path": str(main_package_source) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
793 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
794 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
796 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
797 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
798 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
799 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
800 return [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
801 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
802 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
803 def get_sat_media(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
804 """Generate module for last version of sat_media available on the FTP""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
805 step_name = 'sat_media' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
806 print_step("retrieving latest version of sat_media") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
807 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
808 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
809 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
810 url = "https://ftp.goffi.org/sat_media/sat_media.tar.bz2" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
811 r = requests.get(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
812 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
813 hash_ = hashlib.sha256(r.content).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
814 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
815 "name": "sat-media", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
816 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
817 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
818 "cp -vr . ${FLATPAK_DEST}/share/sat-media" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
819 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
820 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
821 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
822 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
823 "url": url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
824 "sha256": hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
825 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
826 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
827 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
828 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
829 data = [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
830 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
831 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
832 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
833 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
834 def get_icon(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
835 icon = build_settings.get('icon') |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
836 if icon is None: |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
837 return [] |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
838 else: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
839 if isinstance(icon, str): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
840 icon = {'url': icon} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
841 icon_path = Path(urlparse(icon['url']).path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
842 suffix = icon_path.suffix[1:] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
843 if suffix not in ('svg', 'png'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
844 raise ValueError("invalid icon, you must use a SVG or PNG image!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
845 if 'size' not in icon: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
846 if suffix == 'svg': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
847 icon['size'] = 'scalable' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
848 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
849 raise ValueError('icon size is not specified, please add a "size" key') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
850 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
851 dest_path = f"/app/share/icons/hicolor/{icon['size']}/apps/{app_id}.{suffix}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
852 |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
853 data = file_from_url( |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
854 url = icon['url'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
855 dest = dest_path, |
150
10adfa3f9552
flatpak (build_manifest): icon names depends of app_id, so set cache to be dependant of app_id
Goffi <goffi@goffi.org>
parents:
146
diff
changeset
|
856 step_name = f"icon__{app_id}", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
857 step_message = "retrieving application icon", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
858 ) |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
859 data[0]['name'] = 'icon' |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
860 return data |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
861 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
862 |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
863 def generate_appdata_from_template(template_file): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
864 appdata_file = Path(f"{app_id}.appdata.xml") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
865 if appdata_file.exists() and not args.force: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
866 confirm = input(OVERWRITE_WARNING.format(appdata_file)) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
867 if confirm != 'y': |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
868 print("manifest building cancelled") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
869 sys.exit(0) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
870 parser = etree.XMLParser(remove_blank_text=True) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
871 tree = etree.parse(template_file, parser) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
872 root = tree.getroot() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
873 if args.version == 'dev': |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
874 print(f"addind release data for dev version ({dev_version_rev})") |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
875 releases_elt = root.find('releases') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
876 if releases_elt is None: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
877 raise ValueError( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
878 "<releases/> element is missing in appdata template, please add it") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
879 release_elt = etree.SubElement( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
880 releases_elt, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
881 "release", |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
882 {'type': 'development', |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
883 'version': dev_version_rev, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
884 'date': dev_version_date}, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
885 ) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
886 description_elt = etree.SubElement(release_elt, 'description') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
887 text_lines = APPDATA_RELEASE_DEV_TEXT.strip().split('\n') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
888 for text in text_lines: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
889 etree.SubElement(description_elt, 'p').text = text |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
890 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
891 with open(appdata_file, "wb") as f: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
892 f.write(etree.tostring(root, encoding="utf-8", xml_declaration=True, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
893 pretty_print=True)) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
894 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
895 return appdata_file.as_posix() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
896 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
897 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
898 def get_app_metadata(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
899 desktop_file = build_settings.get('desktop_file') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
900 appdata_file = build_settings.get('appdata_file') |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
901 if desktop_file is None and appdata_file is None: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
902 return |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
903 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
904 print_step("retrieving application metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
905 # we don't use cache here to be sure to have always up-to-date files |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
906 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
907 data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
908 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
909 if desktop_file is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
910 print("generating module for desktop metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
911 data.extend(file_upload( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
912 filename = desktop_file, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
913 dest=f"/app/share/applications/{app_id}.desktop", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
914 )) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
915 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
916 if appdata_file is not None: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
917 if appdata_file.startswith('_tpl_'): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
918 print("found appdata template, we now use it to generate the file") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
919 appdata_file = generate_appdata_from_template(appdata_file) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
920 print("generating module for appdata metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
921 data.extend(file_upload( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
922 filename = appdata_file, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
923 dest=f"/app/share/metainfo/{app_id}.appdata.xml", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
924 )) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
925 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
926 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
927 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
928 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
929 ## main_script ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
930 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
931 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
932 if __name__ == '__main__': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
933 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
934 args = parse_args() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
935 title = args.name.title() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
936 app_id = f"org.salutatoi.{title}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
937 package_file = Path(f"{app_id}.json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
938 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
939 print(f"generating manifest for {app_id} ({args.version})") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
940 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
941 if package_file.exists() and not args.force: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
942 confirm = input(OVERWRITE_WARNING.format(package_file)) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
943 if confirm != 'y': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
944 print("manifest building cancelled") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
945 sys.exit(0) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
946 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
947 tpl_file = Path(f"_tpl_{package_file}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
948 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
949 if not tpl_file.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
950 raise RuntimeError(f"Can't find template {tpl_file}, it is mandatory to build" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
951 "the manifest!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
952 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
953 with tpl_file.open() as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
954 template = json.load(f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
955 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
956 build_settings = template.pop(SETTINGS_KEY, {}) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
957 if "setup_requirements" in build_settings: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
958 PYTHON_SETUP_REQUIREMENTS.extend(build_settings["setup_requirements"]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
959 main_package = canonical(build_settings.get('package', args.name)) |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
960 if args.version == 'dev': |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
961 if 'dev_repos' not in build_settings: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
962 raise NotImplementedError( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
963 "dev version can currently only be handled with a dev repostiory " |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
964 "(dev_repos)") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
965 dev_repos = build_settings['dev_repos'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
966 main_package_source = cache_from_repos() |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
967 dev_version_rev, dev_version_date = get_hg_id_date(main_package_source) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
968 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
969 main_package_source = main_package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
970 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
971 manifest = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
972 manifest['app-id'] = app_id |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
973 manifest['default-branch'] = args.version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
974 # we update DEFAULT_MANIFEST only now to have "app-id" and "default-branch" on the top |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
975 # of the manifest, also we don't want modules to be set now |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
976 default_modules = DEFAULT_MANIFEST.pop('modules', []) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
977 manifest.update(DEFAULT_MANIFEST) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
978 manifest.update(template) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
979 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
980 modules.extend(get_libxslt()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
981 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
982 # setup requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
983 modules.extend(get_python_package( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
984 PYTHON_SETUP_REQUIREMENTS, |
146
64c02902b86a
flatpak (build_manifest): fixed setup_requirements step cache by making dependent of app_id
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
985 step_name=f"setup_requirements__{app_id}", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
986 step_message="generating modules for setup requirements") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
987 ) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
988 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
989 # python dependencies |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
990 modules.extend(get_python_deps()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
991 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
992 # at this point we add things specified in the template |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
993 modules.extend(manifest.get('modules', [])) |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
994 modules = default_modules + modules |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
995 manifest['modules'] = modules |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
996 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
997 # sat common things |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
998 existing_modules = {d['name'] for d in modules} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
999 if "sat_templates" not in existing_modules: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1000 modules.extend(get_python_package("sat_templates", with_pre=True)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1001 modules.extend(get_sat_media()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1002 modules.extend(file_upload('sat.conf', '/app')) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1003 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1004 # wrapper to launch the backend if needed |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1005 wrapped_command = build_settings.get('wrapped_command') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1006 if wrapped_command: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1007 modules.extend(file_upload('sat_wrapper', src='sat_wrapper.py', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1008 replace={'##COMMAND##': wrapped_command}, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1009 use_install=True)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1010 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1011 # icon |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1012 modules.extend(get_icon()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1013 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1014 # desktop file and appdata file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1015 modules.extend(get_app_metadata()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1016 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1017 # now the app itself |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
1018 if args.version == 'dev': |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1019 # mercurial is needed for dev version to install but also to |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1020 # retrieve revision used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1021 modules.extend(get_python_package("mercurial")) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1022 modules.extend(get_repos_module()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1023 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1024 modules.extend(get_python_package(main_package, version=args.version)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1025 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1026 print_step("writing manifest") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1027 with package_file.open('w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1028 json.dump(manifest, f, indent=4) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1029 |
154
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
1030 if args.ignore_cache and args.ignore_cache != ['all']: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1031 print("/!\\ those --ignore-cache arguments don't correspond to any step: {}". |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1032 format(', '.join(args.ignore_cache))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1033 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1034 print(f"manifest generated successfully at {package_file}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1035 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1036 if args.export is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1037 print_step("exporting building files") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1038 print(f"exporting to {args.export}\n") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1039 to_export = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1040 ("package file", package_file), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1041 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1042 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1043 for m in modules: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1044 for s in m.get('sources', []): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1045 s_type = s.get('type') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1046 if s_type in ('path', 'file'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1047 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1048 path = s['path'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1049 except KeyError: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1050 if 'url' in s: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1051 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1052 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1053 raise ValueError(f"path missing for module source:\n{s}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1054 to_export.append((s_type, Path(path))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1055 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1056 for label, path in to_export: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1057 print(f"exporting {label}: {path}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1058 dest = args.export / path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1059 if dest.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1060 if args.force_export: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1061 print(f" replacing existing {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1062 if path.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1063 shutil.rmtree(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1064 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1065 dest.unlink() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1066 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1067 print(" it already exists, skipping") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1068 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1069 if args.symlink == 'all': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1070 os.symlink(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1071 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1072 if path.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1073 shutil.copytree(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1074 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1075 shutil.copyfile(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1076 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1077 if args.version == 'dev': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1078 print("exporting cache") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1079 dest = args.export / get_cache_dir() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1080 if args.force_export and os.path.lexists(dest): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1081 print(f" replacing existing {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1082 if dest.is_symlink(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1083 dest.unlink() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1084 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1085 shutil.rmtree(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1086 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1087 if dest.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1088 print(" it already exists, skipping") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1089 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1090 if args.symlink in ('all', 'cache'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1091 os.symlink(get_cache_dir().resolve(), dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1092 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1093 shutil.copytree(get_cache_dir(), dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1094 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1095 print("\nexport completed") |