Category: Python

How to debug a SConstruct/SConscript file with Eclipse/PyDev

1) Create a Pydev project
File -> New -> Pydev Project

Project name: scons_pydev
Uncheck “Use default” and Browse for “C:\Python26\Scripts” (on windows)
Uncheck “Create default ‘src’ folder …”

2) Copy “C:\Python26\Scripts\scons” as “C:\Python26\Scripts\scons.py”

3) Create a Debug configuration:
Run -> Debug Configurations…

4) Edit the main tab with “scons_pydev” as project e “scons.py” as Main module

5) Edit the “Arguments” tab, set the working directory to the root of your project (see Working Directory)

6) Set the breakpoint either on SConstruct or SConcript and run in debug mode

Trick: Debugging could be easier executing the following steps:
– modify the Main.py module in “C:\Python26\Lib\site-packages\scons-1.2.0\SCons\Script” as following:
# filelist = [‘SConstruct’, ‘Sconstruct’, ‘sconstruct’]
filelist = [‘SConstruct’, ‘Sconstruct’, ‘sconstruct’, ‘SConstruct.py’, ‘Sconstruct.py’, ‘sconstruct.py’]
– copy SConstruct as SConstruct.py

Advertisements

Python switch statement

Python doesn’t have a switch statement such as other programming languages but you can do the same thing with a dictionary:

import platform

def set_windows() :
   return
def set_linux() :
   return
def set_sunos() :
   return

platform_settings = {
           'Windows' : set_windows, 
           'Linux'   : set_linux, 
           'SunOS'   : set_sunos,
}

platform_settings[platform.system()]()