Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

gen-catalog-json.py 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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'] = {}
  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='Niebler/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. '2019.11.10',
  87. description='The Windows Implementation Library',
  88. remote=Git('https://github.com/vector-of-bool/wil.git',
  89. 'dds/2019.11.10'))
  90. ]),
  91. many_versions(
  92. 'neo-sqlite3',
  93. (
  94. '0.1.0',
  95. '0.2.0',
  96. '0.2.1',
  97. ),
  98. description='A modern and low-level C++ SQLite API',
  99. git_url='https://github.com/vector-of-bool/neo-sqlite3.git',
  100. ),
  101. Package('neo-fun', [
  102. Version(
  103. '0.1.0',
  104. description='Some library fundamentals that you might find useful',
  105. remote=Git('https://github.com/vector-of-bool/neo-fun.git',
  106. '0.1.0'))
  107. ]),
  108. Package('semver', [
  109. Version(
  110. '0.2.1',
  111. description=
  112. 'A C++ library that implements Semantic Versioning parsing, emitting, '
  113. 'types, ordering, and operations. See https://semver.org/',
  114. remote=Git('https://github.com/vector-of-bool/semver.git',
  115. '0.2.1'))
  116. ]),
  117. many_versions(
  118. 'pubgrub',
  119. (
  120. '0.1.2',
  121. '0.2.0',
  122. ),
  123. description=
  124. 'A C++ implementation of the Pubgrub version solving algorithm',
  125. git_url='https://github.com/vector-of-bool/pubgrub.git',
  126. ),
  127. many_versions(
  128. 'spdlog',
  129. (
  130. '0.9.0',
  131. '0.10.0',
  132. '0.11.0',
  133. '0.12.0',
  134. '0.13.0',
  135. '0.14.0',
  136. '0.16.0',
  137. '0.16.1',
  138. '0.16.2',
  139. '0.17.0',
  140. '1.0.0',
  141. '1.1.0',
  142. '1.2.0',
  143. '1.2.1',
  144. '1.3.0',
  145. '1.3.1',
  146. '1.4.0',
  147. '1.4.1',
  148. '1.4.1',
  149. ),
  150. git_url='https://github.com/gabime/spdlog.git',
  151. tag_fmt='v{}',
  152. auto_lib='spdlog/spdlog',
  153. description='Fast C++ logging library',
  154. ),
  155. many_versions(
  156. 'fmt',
  157. (
  158. '0.8.0',
  159. '0.9.0',
  160. '0.10.0',
  161. '0.12.0',
  162. '1.0.0',
  163. '1.1.0',
  164. '2.0.0',
  165. '2.0.1',
  166. '2.1.0',
  167. '2.1.1',
  168. '3.0.0',
  169. '3.0.1',
  170. '3.0.2',
  171. '4.0.0',
  172. '4.1.0',
  173. '5.0.0',
  174. '5.1.0',
  175. '5.2.0',
  176. '5.2.1',
  177. '5.3.0',
  178. '6.0.0',
  179. '6.1.0',
  180. '6.1.1',
  181. '6.1.2',
  182. ),
  183. git_url='https://github.com/fmtlib/fmt.git',
  184. auto_lib='fmt/fmt',
  185. description='A modern formatting library : https://fmt.dev/',
  186. ),
  187. ]
  188. data = {
  189. 'version': 1,
  190. 'packages': {
  191. pkg.name: {ver.version: ver.to_dict()
  192. for ver in pkg.versions}
  193. for pkg in packages
  194. }
  195. }
  196. print(json.dumps(data, indent=2, sort_keys=True))