From ec92dec9ab911230f343213c732fd09d78adb70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Fri, 31 Dec 2021 18:05:43 +0100 Subject: [PATCH] Build and include man pages in distributions I do not fully understand how the building process works, and have some doubts on what a "source distribution" should be. The sdist might be polluted if a "man" directory exists at the project root when building the distribution. The inclusion of man pages in the wheel requires it to be built from the sdist, so it's best to build both at the same time using "python -m build". Closes #215 --- docs/conf.py | 15 ++++++++++++--- pyproject.toml | 2 +- setup.cfg | 3 +++ setup.py | 20 ++++++++++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1446adb..2b0e4aa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,13 @@ -import supysonic +import os.path + +# Simulate import of the "supysonic" package +supy_module_path = os.path.join( + os.path.dirname(__file__), "..", "supysonic", "__init__.py" +) +with open(supy_module_path, "rt", encoding="utf-8") as f: + supysonic = type("", (), {})() + exec(f.read(), supysonic.__dict__) + # -- Project information ----------------------------------------------------- @@ -99,6 +108,6 @@ man_pages = [ "supysonic-server", "Python implementation of the Subsonic server API", [author], - 1 - ) + 1, + ), ] diff --git a/pyproject.toml b/pyproject.toml index 3607e0f..396b209 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=51.0.0", "wheel"] +requires = ["setuptools>=51.0.0", "wheel", "sphinx"] build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index 430be0d..254b218 100644 --- a/setup.cfg +++ b/setup.cfg @@ -71,3 +71,6 @@ console_scripts = supysonic-cli = supysonic.cli:main supysonic-daemon = supysonic.daemon:main supysonic-server = supysonic.server:main + +[options.data_files] +share/man/man1 = man/*.1 diff --git a/setup.py b/setup.py index e51e2d7..190e0ba 100644 --- a/setup.py +++ b/setup.py @@ -2,11 +2,27 @@ # Supysonic is a Python implementation of the Subsonic server API. # # Copyright (C) 2013-2021 Alban 'spl0k' Féron -# 2017 Óscar García Amor # # Distributed under terms of the GNU AGPLv3 license. +import os.path + +from distutils import dir_util from setuptools import setup +from setuptools.command.sdist import sdist as _sdist + + +class sdist(_sdist): + def make_release_tree(self, base_dir, files): + super().make_release_tree(base_dir, files) + + man_dir = os.path.join(base_dir, "man") + doctrees_dir = os.path.join(man_dir, ".doctrees") + self.spawn(["sphinx-build", "-q", "-b", "man", "docs", man_dir]) + dir_util.remove_tree(doctrees_dir) + if __name__ == "__main__": - setup() + setup( + cmdclass={"sdist": sdist}, + )