File: vendor_schemas.py

package info (click to toggle)
matplotlib 3.10.1%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,340 kB
  • sloc: python: 147,118; cpp: 62,988; objc: 1,679; ansic: 1,426; javascript: 786; makefile: 92; sh: 53
file content (50 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""
Download YAML Schemas for linting and validation.

Since pre-commit CI doesn't have Internet access, we need to bundle these files
in the repo.
"""

import os
import pathlib
import urllib.request


HERE = pathlib.Path(__file__).parent
SCHEMAS = [
    'https://json.schemastore.org/appveyor.json',
    'https://json.schemastore.org/circleciconfig.json',
    'https://json.schemastore.org/github-funding.json',
    'https://json.schemastore.org/github-issue-config.json',
    'https://json.schemastore.org/github-issue-forms.json',
    'https://json.schemastore.org/codecov.json',
    'https://json.schemastore.org/pull-request-labeler-5.json',
    'https://github.com/microsoft/vscode-python/raw/'
        'main/schemas/conda-environment.json',
]


def print_progress(block_count, block_size, total_size):
    size = block_count * block_size
    if total_size != -1:
        size = min(size, total_size)
        width = 50
        percent = size / total_size * 100
        filled = int(percent // (100 // width))
        percent_str = '\N{Full Block}' * filled + '\N{Light Shade}' * (width - filled)
    print(f'{percent_str} {size:6d} / {total_size:6d}', end='\r')


# First clean up existing files.
for json in HERE.glob('*.json'):
    os.remove(json)

for schema in SCHEMAS:
    path = HERE / schema.rsplit('/', 1)[-1]
    print(f'Downloading {schema} to {path}')
    urllib.request.urlretrieve(schema, filename=path, reporthook=print_progress)
    print()
    # This seems weird, but it normalizes line endings to the current platform,
    # so that Git doesn't complain about it.
    path.write_text(path.read_text())