Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

gen-catalog-json.py 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import json
  2. from typing import NamedTuple, Tuple, List, Sequence, Union, Optional, Mapping
  3. import sys
  4. import textwrap
  5. class Git(NamedTuple):
  6. url: str
  7. ref: str
  8. auto_lib: Optional[str] = None
  9. def to_dict(self) -> dict:
  10. return {
  11. 'url': self.url,
  12. 'ref': self.ref,
  13. 'auto-lib': self.auto_lib,
  14. }
  15. RemoteInfo = Union[Git]
  16. class Version(NamedTuple):
  17. version: str
  18. remote: RemoteInfo
  19. depends: Mapping[str, str] = {}
  20. description: str = '(No description provided)'
  21. def to_dict(self) -> dict:
  22. ret: dict = {
  23. 'description': self.description,
  24. }
  25. ret['depends'] = self.depends
  26. if isinstance(self.remote, Git):
  27. ret['git'] = self.remote.to_dict()
  28. return ret
  29. class Package(NamedTuple):
  30. name: str
  31. versions: List[Version]
  32. def many_versions(name: str,
  33. versions: Sequence[str],
  34. *,
  35. tag_fmt: str = '{}',
  36. git_url: str,
  37. auto_lib: str = None,
  38. description='(No description was provided)') -> Package:
  39. return Package(name, [
  40. Version(
  41. ver,
  42. description='\n'.join(textwrap.wrap(description)),
  43. remote=Git(
  44. url=git_url, ref=tag_fmt.format(ver), auto_lib=auto_lib))
  45. for ver in versions
  46. ])
  47. packages = [
  48. many_versions(
  49. 'range-v3',
  50. (
  51. '0.5.0',
  52. '0.9.0',
  53. '0.9.1',
  54. '0.10.0',
  55. ),
  56. git_url='https://github.com/ericniebler/range-v3.git',
  57. auto_lib='range-v3/range-v3',
  58. description=
  59. 'Range library for C++14/17/20, basis for C++20\'s std::ranges',
  60. ),
  61. many_versions(
  62. 'nlohmann-json',
  63. (
  64. '3.0.0',
  65. '3.0.1',
  66. '3.1.0',
  67. '3.1.1',
  68. '3.1.2',
  69. '3.2.0',
  70. '3.3.0',
  71. '3.4.0',
  72. '3.5.0',
  73. '3.6.0',
  74. '3.6.1',
  75. '3.7.0',
  76. '3.7.1',
  77. '3.7.2',
  78. '3.7.3',
  79. ),
  80. git_url='https://github.com/vector-of-bool/json.git',
  81. tag_fmt='dds/{}',
  82. description='JSON for Modern C++',
  83. ),
  84. Package('ms-wil', [
  85. Version(
  86. '2020.03.16',
  87. description='The Windows Implementation Library',
  88. remote=Git('https://github.com/vector-of-bool/wil.git',
  89. 'dds/2020.03.16'))
  90. ]),
  91. many_versions(
  92. 'neo-sqlite3',
  93. (
  94. '0.1.0',
  95. '0.2.0',
  96. '0.2.1',
  97. '0.2.2',
  98. '0.2.3',
  99. ),
  100. description='A modern and low-level C++ SQLite API',
  101. git_url='https://github.com/vector-of-bool/neo-sqlite3.git',
  102. ),
  103. many_versions(
  104. 'neo-fun',
  105. (
  106. '0.1.0',
  107. '0.1.1',
  108. '0.2.0',
  109. '0.2.1',
  110. '0.3.0',
  111. '0.3.1',
  112. '0.3.2',
  113. ),
  114. description='Some library fundamentals that you might find useful',
  115. git_url='https://github.com/vector-of-bool/neo-fun.git',
  116. ),
  117. many_versions(
  118. 'neo-concepts',
  119. (
  120. '0.1.0',
  121. '0.2.0',
  122. '0.2.1',
  123. '0.2.2',
  124. ),
  125. description=
  126. 'Minimal C++ concepts library. Contains many definitions from C++20.',
  127. git_url='https://github.com/vector-of-bool/neo-concepts.git',
  128. ),
  129. Package('semver', [
  130. Version(
  131. '0.2.1',
  132. description=
  133. 'A C++ library that implements Semantic Versioning parsing, emitting, '
  134. 'types, ordering, and operations. See https://semver.org/',
  135. remote=Git('https://github.com/vector-of-bool/semver.git',
  136. '0.2.1')),
  137. Version(
  138. '0.2.2',
  139. description=
  140. 'A C++ library that implements Semantic Versioning parsing, emitting, '
  141. 'types, ordering, and operations. See https://semver.org/',
  142. remote=Git('https://github.com/vector-of-bool/semver.git',
  143. '0.2.2')),
  144. ]),
  145. many_versions(
  146. 'pubgrub',
  147. (
  148. '0.1.2',
  149. '0.2.0',
  150. '0.2.1',
  151. ),
  152. description=
  153. 'A C++ implementation of the Pubgrub version solving algorithm',
  154. git_url='https://github.com/vector-of-bool/pubgrub.git',
  155. ),
  156. many_versions(
  157. 'vob-json5',
  158. ('0.1.5', ),
  159. description='A C++ implementation of a JSON5 parser',
  160. git_url='https://github.com/vector-of-bool/json5.git',
  161. ),
  162. Package('vob-semester', [
  163. Version(
  164. '0.1.0',
  165. description='A C++ library to process recursive dynamic data',
  166. remote=Git('https://github.com/vector-of-bool/semester.git',
  167. '0.1.0'),
  168. depends={
  169. 'neo-fun': '^0.1.0',
  170. 'neo-concepts': '^0.2.1',
  171. }),
  172. Version(
  173. '0.1.1',
  174. description='A C++ library to process recursive dynamic data',
  175. remote=Git('https://github.com/vector-of-bool/semester.git',
  176. '0.1.1'),
  177. depends={
  178. 'neo-fun': '^0.1.1',
  179. 'neo-concepts': '^0.2.2',
  180. }),
  181. ]),
  182. Package('ctre', [
  183. Version(
  184. '2.7.0',
  185. description=
  186. 'A compile-time PCRE (almost) compatible regular expression matcher',
  187. remote=Git(
  188. 'https://github.com/hanickadot/compile-time-regular-expressions.git',
  189. 'v2.7',
  190. auto_lib='hanickadot/ctre',
  191. ))
  192. ]),
  193. many_versions(
  194. 'spdlog',
  195. (
  196. '0.9.0',
  197. '0.10.0',
  198. '0.11.0',
  199. '0.12.0',
  200. '0.13.0',
  201. '0.14.0',
  202. '0.16.0',
  203. '0.16.1',
  204. '0.16.2',
  205. '0.17.0',
  206. '1.0.0',
  207. '1.1.0',
  208. '1.2.0',
  209. '1.2.1',
  210. '1.3.0',
  211. '1.3.1',
  212. '1.4.0',
  213. '1.4.1',
  214. '1.4.2',
  215. ),
  216. git_url='https://github.com/gabime/spdlog.git',
  217. tag_fmt='v{}',
  218. auto_lib='spdlog/spdlog',
  219. description='Fast C++ logging library',
  220. ),
  221. many_versions(
  222. 'fmt',
  223. (
  224. '0.8.0',
  225. '0.9.0',
  226. '0.10.0',
  227. '0.12.0',
  228. '1.0.0',
  229. '1.1.0',
  230. '2.0.0',
  231. '2.0.1',
  232. '2.1.0',
  233. '2.1.1',
  234. '3.0.0',
  235. '3.0.1',
  236. '3.0.2',
  237. '4.0.0',
  238. '4.1.0',
  239. '5.0.0',
  240. '5.1.0',
  241. '5.2.0',
  242. '5.2.1',
  243. '5.3.0',
  244. '6.0.0',
  245. '6.1.0',
  246. '6.1.1',
  247. '6.1.2',
  248. ),
  249. git_url='https://github.com/fmtlib/fmt.git',
  250. auto_lib='fmt/fmt',
  251. description='A modern formatting library : https://fmt.dev/',
  252. ),
  253. ]
  254. data = {
  255. 'version': 1,
  256. 'packages': {
  257. pkg.name: {ver.version: ver.to_dict()
  258. for ver in pkg.versions}
  259. for pkg in packages
  260. }
  261. }
  262. print(json.dumps(data, indent=2, sort_keys=True))