summaryrefslogtreecommitdiff
path: root/scripts/internal/convert_readme.py
blob: bd00cf2340645d8ccd40dbcd0201c85686e3c82c (plain)
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
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3

# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Remove raw HTML from README.rst to make it compatible with PyPI on
dist upload.
"""

import argparse
import re


summary = """\
Quick links
===========

- `Home page <https://github.com/giampaolo/psutil>`_
- `Install <https://github.com/giampaolo/psutil/blob/master/INSTALL.rst>`_
- `Documentation <http://psutil.readthedocs.io>`_
- `Download <https://pypi.org/project/psutil/#files>`_
- `Forum <http://groups.google.com/group/psutil/topics>`_
- `StackOverflow <https://stackoverflow.com/questions/tagged/psutil>`_
- `Blog <https://gmpy.dev/tags/psutil>`_
- `What's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst>`_
"""

funding = """\
Sponsors
========

.. image:: https://github.com/giampaolo/psutil/raw/master/docs/_static/tidelift-logo.png
  :width: 200
  :alt: Alternative text

`Add your logo <https://github.com/sponsors/giampaolo>`__.

Example usages"""  # noqa


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('file', type=str)
    args = parser.parse_args()
    with open(args.file) as f:
        data = f.read()
    data = re.sub(r".. raw:: html\n+\s+<div align[\s\S]*?/div>", summary, data)
    data = re.sub(r"Sponsors\n========[\s\S]*?Example usages", funding, data)
    if len(sys.argv) > 2:
        with open(sys.argv[2], "wb") as f:
            f.write(data.encode("utf8"))
    else:
        print(data)


if __name__ == '__main__':
    main()