Skip to content

Commit 5dd1d9c

Browse files
authored
Merge pull request #4512 from mwichmann/print-Variables
Allow printing a Variables object
2 parents 8c85b35 + 65dec46 commit 5dd1d9c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
3838
by adding SKIP_PDF=1. This should help with distro packaging of SCons,
3939
which now does not need "fop" and other tools to be set up in order to
4040
build pdf versions which are then ignored.
41+
- Add the ability to print a Variables object for debugging purposes
42+
(provides a __str__ method in the class).
4143

4244

4345
RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700

SCons/Variables/__init__.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,21 @@ def __init__(self, files=None, args=None, is_global: bool=True) -> None:
7676
if not Variables.instance:
7777
Variables.instance=self
7878

79+
def __str__(self) -> str:
80+
"""Provide a way to "print" a Variables object."""
81+
s = "Variables(\n options=[\n"
82+
for option in self.options:
83+
s += f" {str(option)},\n"
84+
s += " ],\n"
85+
s += f" args={self.args},\n files={self.files},\n unknown={self.unknown},\n)"
86+
return s
87+
7988
def _do_add(self, key, help: str="", default=None, validator=None, converter=None, **kwargs) -> None:
8089

8190
class Variable:
82-
pass
91+
def __str__(self) -> str:
92+
"""Provide a way to "print" a Variable object."""
93+
return f"({self.key!r}, {self.aliases}, {self.help!r}, {self.default!r}, {self.validator}, {self.converter})"
8394

8495
option = Variable()
8596

0 commit comments

Comments
 (0)