|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
| 3 | +from collections import defaultdict |
3 | 4 | from pathlib import Path
|
4 | 5 | import pprint
|
5 | 6 |
|
6 | 7 | from jinja2 import Template
|
7 | 8 | from yaml import safe_load
|
8 |
| -from markdown import markdown |
9 | 9 | import requests
|
10 | 10 |
|
11 |
| -# concatenate yml files... |
12 | 11 |
|
13 | 12 | here = Path(__file__).parent.resolve()
|
14 | 13 |
|
15 |
| -all_path = here.parent / 'packages/all.yml' |
16 |
| -all_path.unlink(missing_ok=True) |
17 |
| -packages = (here.parent / 'packages').glob('*') |
18 |
| - |
19 |
| - |
20 | 14 | print("Opening section names file")
|
21 | 15 | with (here.parent / 'section_names.yml').open() as f:
|
22 | 16 | section_names = safe_load(f)
|
23 | 17 |
|
24 | 18 | section_names = section_names['section_names']
|
25 | 19 |
|
26 | 20 | print("section_names", section_names)
|
27 |
| -packs = dict() |
28 |
| -# divide the yml files into sections based on teh section tag... |
29 |
| -for package in packages: |
30 |
| - with package.open('r') as fin: |
31 |
| - pack = safe_load(fin) |
32 |
| - if 'section' not in pack: |
33 |
| - pack['section'] = 'miscellaneous' |
34 |
| - if pack['section'] in packs: |
35 |
| - packs[pack['section']] += [pack] |
36 |
| - else: |
37 |
| - packs[pack['section']] = [pack] |
38 |
| - |
39 |
| -pprint.pprint(packs) |
| 21 | +config = defaultdict(list) |
| 22 | +for path in (here.parent / 'packages').glob('*'): |
| 23 | + with path.open('r') as fin: |
| 24 | + package = safe_load(fin) |
| 25 | + |
| 26 | + # Divide the yml files into sections based on the section tag... |
| 27 | + if 'section' not in package: |
| 28 | + package['section'] = 'miscellaneous' |
| 29 | + package['section'] = section_names[package['section'].lower()] |
40 | 30 |
|
41 |
| -with all_path.open('w') as out: |
42 |
| - for secname in sorted(packs.keys()): |
43 |
| - packs_sec = sorted(packs[secname], key=lambda i: i['repo'].split('/')[1].lower()) |
44 |
| - |
45 |
| - out.write(f' - name: {section_names[secname]}\n') |
46 |
| - out.write(f' packages:\n\n') |
47 |
| - for pack in packs_sec: |
48 |
| - out.write(f' - repo: {pack["repo"]}\n') |
49 |
| - for k, v in pack.items(): |
50 |
| - if k != 'repo': |
51 |
| - out.write(f' {k}: {v}\n') |
52 |
| - out.write('\n') |
53 |
| - |
54 |
| - |
55 |
| - |
56 |
| -print("Opening config file") |
57 |
| -with all_path.open() as f: |
58 |
| - config = safe_load(f) |
59 |
| -pprint.pprint(config) |
60 |
| -print() |
61 |
| - |
62 |
| -for section in config: |
63 |
| - print(section.get('name', '')) |
64 |
| - if section.get('intro'): |
65 |
| - section['intro'] = markdown(section['intro']) |
66 |
| - for package in section['packages']: |
67 |
| - print(f" {package['repo']}") |
| 31 | + print(f" {package['repo']} -> {package['section']}") |
68 | 32 | try:
|
69 | 33 | package['user'], package['repo_name'] = package['repo'].split('/')
|
70 | 34 | except:
|
|
73 | 37 | package['conda_package'] = package.get('conda_package', package['repo_name'])
|
74 | 38 | package['pypi_name'] = package.get('pypi_name', package['repo_name'])
|
75 | 39 |
|
76 |
| - package['section'] = section_names[package['section'].lower()] |
77 | 40 | if package.get('badges'):
|
78 | 41 | package['badges'] = [x.strip() for x in package['badges'].split(',')]
|
79 | 42 | else:
|
|
125 | 88 | else:
|
126 | 89 | package['site'] = package['site'].rstrip('/')
|
127 | 90 |
|
128 |
| -template = Template((here / 'template.rst').read_text(), |
129 |
| - lstrip_blocks=True, trim_blocks=True) |
| 91 | + config[package['section']].append(package) |
130 | 92 |
|
131 |
| -config = sorted(config, key = lambda i: i['name']) |
| 93 | +# Turn defaultdict into plain dict. |
| 94 | +config = {**config} |
| 95 | +pprint.pprint(config) |
132 | 96 |
|
| 97 | +template = Template((here / 'template.rst').read_text(), |
| 98 | + lstrip_blocks=True, trim_blocks=True) |
133 | 99 |
|
134 | 100 | (here.parent / 'docs/source/packages.rst').write_text(f"""\
|
135 | 101 | Third-party and user-contributed packages
|
|
0 commit comments