0

What is the best practice in 2020 to make SConstruct Python 3 compatible?

For example, running old SConstruct gives errors like this.

✗ python ~/scons/scripts/scons.py scons: Reading SConscript files ... File "/home/techtonik/Folding@home/fah-control/SConstruct", line 17 except Exception, e: ^ SyntaxError: invalid syntax 
3
  • amend that line into except Exception as e instead Commented Sep 5, 2020 at 9:29
  • 1
    also this repo. seems to be in python3 Commented Sep 5, 2020 at 9:38
  • @Tibebes.M I am using the repo. The problem is that github.com/FoldingAtHome/fah-control repo is not Python 3 compatible, and I don't want to rewrite scripts manually. Commented Sep 5, 2020 at 14:32

1 Answer 1

2

2to3 or modernize ought to help. it's just Python syntax that's at issue.

2to3 is shipped with Python, and can also be executed as a Python module:

python -m lib2to3 -w SConstruct 

Here's the patch 2to3 suggested, looks pretty minor:

RefactoringTool: Refactored SConstruct --- SConstruct (original) +++ SConstruct (refactored) @@ -3,8 +3,8 @@ env = Environment(ENV = os.environ) try: env.Tool('config', toolpath = [os.environ.get('CBANG_HOME')]) -except Exception, e: - raise Exception, 'CBANG_HOME not set?\n' + str(e) +except Exception as e: + raise Exception('CBANG_HOME not set?\n' + str(e)) env.CBLoadTools('packager run_distutils osx fah-client-version') env.CBAddVariables( @@ -14,7 +14,7 @@ # Version try: version = env.FAHClientVersion() -except Exception, e: +except Exception as e: print(e) version = '0.0.0' env.Replace(PACKAGE_VERSION = version) RefactoringTool: Files that need to be modified: RefactoringTool: SConstruct 
Sign up to request clarification or add additional context in comments.

2 Comments

How did you get that diff?
It's the output of running 2to3 (with a few lines about running other checkers snipped)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.