gsetup: Rework version string handling
I split the function into two. Calling env_string() will return the string we generate with the versions of the various modules we depend on. Calling print_env() will print this string. I need env_string() so we can set the environment as a tooltip in the header. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a86ce6165d
commit
dd9d6268ff
|
@ -250,7 +250,7 @@ class Application(Adw.Application):
|
||||||
"""Handle any command line options."""
|
"""Handle any command line options."""
|
||||||
if opts.contains("version"):
|
if opts.contains("version"):
|
||||||
print(VERSION_STRING)
|
print(VERSION_STRING)
|
||||||
gsetup.print_versions()
|
gsetup.print_env()
|
||||||
return 0
|
return 0
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
|
@ -40,26 +40,31 @@ def add_style():
|
||||||
CSS_PROVIDER, CSS_PRIORITY)
|
CSS_PROVIDER, CSS_PRIORITY)
|
||||||
|
|
||||||
|
|
||||||
def __print_version(subsystem, major, minor, micro):
|
def __version_string(subsystem, major, minor, micro):
|
||||||
print(f" ⋅ {subsystem} {major}.{minor}.{micro}")
|
return f" ⋅ {subsystem} {major}.{minor}.{micro}"
|
||||||
|
|
||||||
|
|
||||||
def print_versions():
|
def env_string() -> str:
|
||||||
"""Print version information for libraries we use."""
|
"""Return a string with the version numbers of our dependencies."""
|
||||||
__print_version("Python", sys.version_info.major, sys.version_info.minor,
|
gst = gi.repository.Gst.version()
|
||||||
sys.version_info.micro)
|
strs = [__version_string("Python", sys.version_info.major,
|
||||||
__print_version("Gtk", gi.repository.Gtk.MAJOR_VERSION,
|
sys.version_info.minor, sys.version_info.micro),
|
||||||
gi.repository.Gtk.MINOR_VERSION,
|
__version_string("Gtk", gi.repository.Gtk.MAJOR_VERSION,
|
||||||
gi.repository.Gtk.MICRO_VERSION)
|
gi.repository.Gtk.MINOR_VERSION,
|
||||||
__print_version("Libadwaita", gi.repository.Adw.MAJOR_VERSION,
|
gi.repository.Gtk.MICRO_VERSION),
|
||||||
gi.repository.Adw.MINOR_VERSION,
|
__version_string("Libadwaita", gi.repository.Adw.MAJOR_VERSION,
|
||||||
gi.repository.Adw.MICRO_VERSION)
|
gi.repository.Adw.MINOR_VERSION,
|
||||||
__print_version("GStreamer", gi.repository.Gst.version().major,
|
gi.repository.Adw.MICRO_VERSION),
|
||||||
gi.repository.Gst.version().minor,
|
__version_string("GStreamer", gst.major, gst.minor, gst.micro),
|
||||||
gi.repository.Gst.version().micro)
|
__version_string("Pango", gi.repository.Pango.VERSION_MAJOR,
|
||||||
__print_version("Pango", gi.repository.Pango.VERSION_MAJOR,
|
gi.repository.Pango.VERSION_MINOR,
|
||||||
gi.repository.Pango.VERSION_MINOR,
|
gi.repository.Pango.VERSION_MICRO),
|
||||||
gi.repository.Pango.VERSION_MICRO)
|
__version_string("SQLite", sqlite3.sqlite_version_info[0],
|
||||||
__print_version("SQLite", sqlite3.sqlite_version_info[0],
|
sqlite3.sqlite_version_info[1],
|
||||||
sqlite3.sqlite_version_info[1],
|
sqlite3.sqlite_version_info[2])]
|
||||||
sqlite3.sqlite_version_info[2])
|
return "\n".join(strs)
|
||||||
|
|
||||||
|
|
||||||
|
def print_env() -> None:
|
||||||
|
"""Print the environment versions to stdout."""
|
||||||
|
print(env_string())
|
||||||
|
|
|
@ -4,6 +4,7 @@ import unittest
|
||||||
import pathlib
|
import pathlib
|
||||||
import emmental
|
import emmental
|
||||||
import gi
|
import gi
|
||||||
|
import io
|
||||||
import xdg.BaseDirectory
|
import xdg.BaseDirectory
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,3 +66,20 @@ class TestGSetup(unittest.TestCase):
|
||||||
"""Check that the DATA_DIR points to the right place."""
|
"""Check that the DATA_DIR points to the right place."""
|
||||||
data_path = xdg.BaseDirectory.save_data_path("emmental")
|
data_path = xdg.BaseDirectory.save_data_path("emmental")
|
||||||
self.assertEqual(emmental.gsetup.DATA_DIR, pathlib.Path(data_path))
|
self.assertEqual(emmental.gsetup.DATA_DIR, pathlib.Path(data_path))
|
||||||
|
|
||||||
|
def test_env_string(self):
|
||||||
|
"""Check that the env_string() function works as expected."""
|
||||||
|
self.assertRegex(emmental.gsetup.env_string(),
|
||||||
|
r" ⋅ Python \d+\.\d+\.\d+\n"
|
||||||
|
r" ⋅ Gtk \d+\.\d+\.\d+\n"
|
||||||
|
r" ⋅ Libadwaita \d+\.\d+\.\d+\n"
|
||||||
|
r" ⋅ GStreamer \d+\.\d+\.\d+\n"
|
||||||
|
r" ⋅ Pango \d+\.\d+\.\d+\n"
|
||||||
|
r" ⋅ SQLite \d+\.\d+\.\d+$")
|
||||||
|
|
||||||
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
||||||
|
def test_print_env(self, mock_stdout: io.StringIO):
|
||||||
|
"""Check that the print_env() function prints the env_string()."""
|
||||||
|
emmental.gsetup.print_env()
|
||||||
|
self.assertEqual(mock_stdout.getvalue(),
|
||||||
|
emmental.gsetup.env_string() + "\n")
|
||||||
|
|
Loading…
Reference in New Issue