[Scons-users] Regression? GetOption('prefix') does not seem to work in SConscript files since Python 3.10

Robert-André Mauchin zebob.m at gmail.com
Tue Jun 21 11:41:00 EDT 2022


On 6/21/22 17:35, Mats Wichmann wrote:
> On 6/21/22 09:16, Robert-André Mauchin wrote:
> 
>> ```
>> if 'install' in COMMAND_LINE_TARGETS and GetOption('with_gui'):
>>      if not which('python3'):
>>          print('!! Unable to find python3 executable.')
>>          print('!! Will build no GUI.')
>>      else:
>>          py_install = env.Command(
>>              'always.install',
>>              ['setup.py'],
>>              'cd gui && python3 -m install . --prefix {}'.format(
>>                  GetOption('prefix')
>>              )
>>          )
>>          env.Alias('install', py_install)
>> ```
>>
>> to be able to pass an environment variable to the Python subprocess via
>> env.Command.
>>
>> Any idea how to do that?
> 
> a construction environment contains a variable ENV the holds a dict
> known as the execution environment - this is what is passed to the
> subprocess call.  And you've been (un) lucky, SCons is adamant about not
> passing through environment variables, so you do need to set them
> explicity if you need them.  It can be as simple as:
> 
> env['ENV']['RPM_BUILD_ROOT'] = "value"
> 
> 
> Not sure this is the ideal setup, by the way:
> 
> 'cd gui && python3 -m install . --prefix {}'.format(GetOption('prefix')
> 
> 
> In our own test suites, which do a lot of forking of of Python
> subprocesses, the python is typically pasted in (ususally from
> sys.interpreter, which may or may not be appropriate in the rpm case),
> rather than explicitly named something like. The reason is that the
> execution environment also contains the PATH variable, which also isn't
> transferred forward from your original environment.  In other words, if
> you've got Python in a nonstandard place, which an isolated rpm build
> clearly does, you either need to set env['ENV']['PATH'] to something
> appropriate, or supply a path-to-Python instead of just the bare name
> "python3" to have joy with this....
> 
> 
> 

Yes I did a

diff --git a/SConstruct b/SConstruct
index 7e12d413..4a4f1497 100755
--- a/SConstruct
+++ b/SConstruct
@@ -538,7 +538,7 @@ options = dict(
      PREFIX=GetOption('prefix'),
      ENV = dict([ (key, os.environ[key])
                   for key in os.environ
-                 if key in ['PATH', 'TERM', 'HOME', 'PKG_CONFIG_PATH']
+                 if key in ['PATH', 'TERM', 'HOME', 'PKG_CONFIG_PATH', 'RPM_BUILD_ROOT']
                ])
  )



And it worked.


More information about the Scons-users mailing list