summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-10-24 16:31:31 +0300
committerGiampaolo Rodola <g.rodola@gmail.com>2020-10-24 16:31:31 +0300
commitb5867a85362f9cb8c02ecf1668aa2dd2ffee6d0e (patch)
tree88b07f8123a7d57135682360bc5eef7a659ae421
parent6d42d4949faa2acd0a8e4f55f6472f641ee90199 (diff)
downloadpsutil-b5867a85362f9cb8c02ecf1668aa2dd2ffee6d0e.tar.gz
script to convert README for PYPI
-rw-r--r--.flake81
-rw-r--r--MANIFEST.in1
-rw-r--r--Makefile2
-rwxr-xr-xscripts/internal/convert_readme.py50
-rwxr-xr-xsetup.py13
5 files changed, 64 insertions, 3 deletions
diff --git a/.flake8 b/.flake8
index 15efab52..89225a6a 100644
--- a/.flake8
+++ b/.flake8
@@ -9,5 +9,6 @@ ignore =
per-file-ignores =
setup.py:T001
scripts/*:T001
+ scripts/internal/convert_readme.py:E501,T001
psutil/tests/runner.py:T001
psutil/tests/test_memleaks.py:T001
diff --git a/MANIFEST.in b/MANIFEST.in
index b8c2064e..f5ceeb7c 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -117,6 +117,7 @@ include scripts/internal/bench_oneshot.py
include scripts/internal/bench_oneshot_2.py
include scripts/internal/check_broken_links.py
include scripts/internal/clinter.py
+include scripts/internal/convert_readme.py
include scripts/internal/download_wheels_appveyor.py
include scripts/internal/download_wheels_github.py
include scripts/internal/fix_flake8.py
diff --git a/Makefile b/Makefile
index c603da8a..d9d344f7 100644
--- a/Makefile
+++ b/Makefile
@@ -238,6 +238,7 @@ git-tag-release: ## Git-tag a new release.
sdist: ## Create tar.gz source distribution.
${MAKE} generate-manifest
$(PYTHON) setup.py sdist
+ $(PYTHON) -m twine check dist/*.tar.gz
upload-src: ## Upload source tarball on https://pypi.org/project/psutil/
${MAKE} sdist
@@ -266,6 +267,7 @@ pre-release: ## Check if we're ready to produce a new release.
git diff MANIFEST.in > /dev/null # ...otherwise 'git diff-index HEAD' will complain
${MAKE} download-wheels
${MAKE} sdist
+ $(PYTHON) -m twine check dist/*
$(PYTHON) -c \
"from psutil import __version__ as ver; \
doc = open('docs/index.rst').read(); \
diff --git a/scripts/internal/convert_readme.py b/scripts/internal/convert_readme.py
new file mode 100755
index 00000000..d6cae918
--- /dev/null
+++ b/scripts/internal/convert_readme.py
@@ -0,0 +1,50 @@
+#!/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.
+
+"""
+Convert README.rst format to make it compatible with PyPI (no raw html).
+"""
+
+import re
+import sys
+
+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"""
+
+
+def main():
+ with open(sys.argv[1]) 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)
+ print(data)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.py b/setup.py
index 615f6d7b..3a8dab59 100755
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@ import platform
import re
import shutil
import struct
+import subprocess
import sys
import tempfile
import warnings
@@ -98,9 +99,15 @@ macros.append(('PSUTIL_VERSION', int(VERSION.replace('.', ''))))
def get_description():
- README = os.path.join(HERE, 'README.rst')
- with open(README, 'r') as f:
- return f.read()
+ script = os.path.join(HERE, "scripts", "internal", "convert_readme.py")
+ readme = os.path.join(HERE, 'README.rst')
+ p = subprocess.Popen([sys.executable, script, readme],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ if p.returncode != 0:
+ raise RuntimeError(stderr)
+ assert not stderr, stderr
+ return stdout.decode('utf8')
@contextlib.contextmanager