[Scons-users] Custom environment tools evaluated before Configure contexts?

Ben Farmer ben.farmer at gmail.com
Mon Nov 6 00:42:19 EST 2023


Hi scons mailing list,

I am currently trying to understand the intended usage of the Configure
context vs Environment 'tools'. Here's my scenario: the codebase I am
working on has a bunch of custom 'tools' defined, which create various
"actions" to run, one of which is running some unit tests via pytest. These
are passed to the construction Environment in it's constructor in the
project SConstruct file:

    env = Environment(tools=our_custom_tools, ...)

However, I would now like to change the behaviour of these tools depending
on the build environment. It's a simple change, I just want to pass `-n
<N>` to pytest to set it to run in parallel if pytest-xdist is installed.
So I figured I would check this somewhere, then in the custom tool build
the pytest Builder action with or without this -n flag depending on the
result. Checking if stuff is installed seemed like a job for the Configure
context, so I made some custom checks for that following
https://scons.org/doc/production/HTML/scons-man.html#configure_contexts,
and do this:

    conf = Configure(env, custom_tests={"CheckPytest": check_pytest,
                                        "CheckPytestXdist":
check_pytest_xdist})
    env["PYTEST_INSTALLED"] = 'true' if conf.CheckPytest() else 'false'
    env["PYTEST_XDIST_INSTALLED"] = 'true' if conf.CheckPytestXdist() else
'false'
    conf.Finish()

This works totally fine, it checks if `pytest-xdist` is available and adds
some construction variables to communicate this. Unfortunately it seems
like it does this too late. The tools have already been "built" when
Environment was called, so I can't use them to build the "action"
differently depending on the environment

So I guess Configure is no good for this? Or am I just thinking about this
wrong? It feels like this is where SCons wants me to do these kind of
environment checks, but then how am I supposed to use that information in
the build actions if they've already been prepared before Configure does
its thing?

Regards,

Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20231106/f7c399d6/attachment.htm>


More information about the Scons-users mailing list