[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#930565: dev-ref: should use distro-info instead of hardcoding version numbers



Hi Holger,

On 3/28/22 14:12, Holger Levsen wrote:
On Wed, Mar 02, 2022 at 02:21:20PM +0100, kaliko wrote:
On Sat, 15 Jun 2019 16:26:33 +0000 Holger Levsen <holger@layer-acht.org>
wrote:
[…]
and then for bullseye we should use distro-info(-data). (wondering how
to do this sensibly at run time and not at build time...)
What is "run time" for manual (pdf, html, etc…), do you mean when the manual
is actually shown in the browser for instance with html?

could also be a monthly (?) cron job or some such.

Alright then here is a patch using distro-info (forking currently fails at least with my account on salsa).

I was thinking about using python distro-info to set variables to format
rst_epilog with along with _version and _date. But I guess this is not what
you expect.

Ideally I'd like something that also works in a pdf viewer and for the txt
version.

This should works for any output format since distro-info is used to configure the rst source (through rst_epilog). I've tested the plain text and pdf outputs and it's fine indeed.

Cheers,
k


From f1a9aa93d449c1ef48b3a3cd9ab19bef7b846d77 Mon Sep 17 00:00:00 2001
From: Geoffroy Youri Berret <efrim@azylum.org>
Date: Tue, 29 Mar 2022 09:40:38 +0200
Subject: [PATCH] Use distro-info instead of hardcoding version numbers

Closes: #930565
---
 debian/control |  1 +
 source/conf.py | 49 +++++++++++++++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/debian/control b/debian/control
index e180c98..6e239d7 100644
--- a/debian/control
+++ b/debian/control
@@ -7,6 +7,7 @@ Uploaders: Hideki Yamane <henrich@debian.org>,
 Standards-Version: 4.6.0
 Rules-Requires-Root: no
 Build-Depends-Indep: latexmk,
+ python3-distro-info,
  python3-sphinx,
  python3-stemmer,
  tex-gyre,
diff --git a/source/conf.py b/source/conf.py
index a207e34..088d447 100644
--- a/source/conf.py
+++ b/source/conf.py
@@ -6,6 +6,19 @@
 # full list see the documentation:
 # http://www.sphinx-doc.org/en/master/config
 
+# -- distro-info
+import distro_info
+_deb = distro_info.DebianDistroInfo()
+_all_codenames = _deb.get_all()
+_testing_codename = _deb.testing()
+_testing_version = int(_deb.version(_deb.testing()))
+_stable_codename = _deb.stable()
+_stable_version = int(_deb.version(_deb.stable()))
+_old_codename = _deb.old()
+_old_version = int(_deb.version(_deb.old()))
+_oldold_codename = _all_codenames[_all_codenames.index(_old_codename)-1]
+_nexttesting_codename = _all_codenames[_all_codenames.index(_testing_codename)+1]
+
 # -- Environment variable setup ----------------------------------------------
 import os
 _package = os.getenv("PACKAGE", default="package-name")
@@ -63,28 +76,28 @@ source_suffix = '.rst'
 master_doc = 'index'
 
 # Substitution (only for text contents (not for URL refs)
-rst_epilog = """
-.. |version| replace:: ``{}``
-.. |pubdate| replace:: ``{}``
+rst_epilog = f"""
+.. |version| replace:: ``{_version}``
+.. |pubdate| replace:: ``{_date}``
 .. |number-of-pkgs| replace:: ``30000``
 .. |number-of-maintainers| replace:: 1000
 .. |number-of-arches| replace:: 10
 .. |codename-security| replace:: *codename*\ ``-security``
-.. |codename-oldoldstable| replace:: ``jessie``
-.. |codename-oldstable| replace:: ``stretch``
-.. |codename-stable| replace:: ``buster``
-.. |codename-stable-security| replace:: ``buster-security``
-.. |codename-testing| replace:: ``bullseye``
-.. |codename-nexttesting| replace:: ``bookworm``
-.. |version-oldoldstable| replace:: 8
-.. |version-oldstable| replace:: 9
-.. |version-stable| replace:: 10
-.. |version1-revision-deb-version-stable-u1| replace:: ``1:2.4.3-4+deb10u1``
-.. |version2-revision-deb-version-stable-u1| replace:: ``1.5-3+deb10u1``
-.. |version-testing| replace:: 11
-.. |version2-revision-deb-version-testing-u1| replace:: ``1.5-3+deb11u1``
-.. |version-nexttesting| replace:: 12
-""".format(_version, _date)
+.. |codename-oldoldstable| replace:: ``{_oldold_codename}``
+.. |codename-oldstable| replace:: ``{_old_codename}``
+.. |codename-stable| replace:: ``{_stable_codename}``
+.. |codename-stable-security| replace:: ``{_stable_codename}-security``
+.. |codename-testing| replace:: ``{_testing_codename}``
+.. |codename-nexttesting| replace:: ``{_nexttesting_codename}``
+.. |version-oldoldstable| replace:: {_old_version-1}
+.. |version-oldstable| replace:: {_old_version}
+.. |version-stable| replace:: {_stable_version}
+.. |version1-revision-deb-version-stable-u1| replace:: ``1:2.4.3-4+deb{_stable_version}u1``
+.. |version2-revision-deb-version-stable-u1| replace:: ``1.5-3+deb{_stable_version}u1``
+.. |version-testing| replace:: {_testing_version}
+.. |version2-revision-deb-version-testing-u1| replace:: ``1.5-3+deb{_testing_version}u1``
+.. |version-nexttesting| replace:: {_testing_version+1}
+"""
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 #
-- 
2.30.2

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


Reply to: